HTML/CSS/Box Model/display
Содержание
- 1 display: inline-block
- 2 display:list-item to render as list item
- 3 Div toggler with Javascript
- 4 Rendered as a table with rows and cells
- 5 use display:block to render an element as a block
- 6 use display:inline-block to render an inline element as a block nested in a line.
- 7 use display:inline to render an element inline.
- 8 use display:none to prevent an element from being rendered.
display: inline-block
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
* .inline-box {
display: inline-block;
overflow: visible;
visibility: visible;
width: 275px;
height: 52px;
margin: 10px 100px;
padding: 10px 10px;
}
</style>
</head>
<body>
<h1></h1>
<div>
<span>BEFORE</span>
<span class="inline-box">Inline element displayed as an inline block.</span>
<span>AFTER</span>
</div>
</body>
</html>
display:list-item to render as list item
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
dfn {
display: list-item;
list-style-type: square;
}
</style>
</head>
<body>
<div class="ul"><dfn>dfn <code>display:list-item</code></dfn><dfn>dfn</dfn></div>
</body>
</html>
Div toggler with Javascript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Div toggler</title>
<script type="text/javascript">
function swap(targetId){
if (document.getElementById){
target = document.getElementById(targetId);
if (target.style.display == "none"){
target.style.display = "";
} else {
target.style.display = "none";
}
}
}
</script>
<style type="text/css" media="Screen">
body {
font: 12px Verdana;
}
#hiddenDiv {
background-color: #aaaaaa;
width: 200px;
}
</style>
</head>
<body>
<div>
<a href="#" title="Toggle section" onclick="swap("hiddenDiv");return false;">Toggle div!</a>
</div>
<div id="hiddenDiv" style="display: none;">
<p>Hello!</p>
</div>
</body>
</html>
Rendered as a table with rows and cells
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css" media="Screen">
div,span {
border: 1px solid black;
padding: 5px;
}
* .tabled {
display: table;
border-collapse: collapse;
}
* .rowed {
display: table-row;
}
* .celled {
display: table-cell;
}
</style>
</head>
<body>
<div class="tabled">
<div class="rowed">
<div class="celled">division</div>
<div class="celled">division</div>
</div>
<span class="rowed">
<span class="celled">span</span>
<span class="celled">span</span></span>
</div>
</body>
</html>
use display:block to render an element as a block
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
em {
display: block;
}
</style>
</head>
<body>
<em>em <code>display:block</code></em> <em>em</em> <br />
</body>
</html>
use display:inline-block to render an inline element as a block nested in a line.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
strong {
display: inline-block;
width: 250px;
}
</style>
</head>
<body>
<strong>strong <br /><code>display:inline-block</code></strong> <br /><br />
</body>
</html>
use display:inline to render an element inline.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
p,ol,li,table {
display: inline;
}
</style>
</head>
<body>
<code>display:inline</code>
<p>p</p> <p>p</p> <p>p</p>
<ol><li>li</li><li>li</li><li>li</li></ol>
<table>
<tr>
<td>td</td>
<td>td</td>
</tr>
<tr>
<td>td</td>
<td>td</td>
</tr>
</table>
</body>
</html>
use display:none to prevent an element from being rendered.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
img {
display: none;
}
</style>
</head>
<body>
<br/><img src="http://www.wbex.ru/style/logo.png" alt="star" /> <code>display:none</code>
</body>
</html>