Equivalent to valign = center for <p> with css
Here is a solution that avoids the use of tags <table>.
Internet Explorer 8 9, Chrome, Firefox Safari ( IE7, , 2% ).
-, - .
...
<div class="container">
<p>The text that you'd wish to have vertically aligned in the middle of the
container...which might be like an article column, or whatever</p>
</div>
CSS
.container{
border: 1px solid red; /*to see the example*/
display: table-cell;
height: /* insert whatever height you want*/;
vertical-align: middle;
}
.
, , , .
, , , :
:
<div class="containerTwo">
<p>here some text and stuffs, make this whatever the heck
you want it to be</p>
<p>these can be any height and, really any element, the magic
is in the display property of the elements so this still
looks pretty semantic</p>
<p>more stuff and this could be like an image or something</p>
</div>
CSS:
.containerTwo{
border: 1px solid green; /* for sake of the example */
display: table-cell;
height: /* what you want it to be */;
vertical-align: middle;
}
.containerTwo p{
border: 1px solid blue; /* for sake of example */
display: inline-block;
width: 30%; /* all of the child elems shouldn't go over 100% */
vertical-align: middle;
}
, . COOLER, display: table-cell, , , , , : (oh IE7)
:
<div class="containerThree">
<p>this is more text that you might want to have
vertically aligned in the middle with the others</p>
<p>so here a sibling paragraph you might want to
have aligned next to the other.</p>
<div title="a really big element!"></div>
<p>like the last one, the width can't add up to more
than 100% of the parent element, otherwise they just
wrap. But atleast no table-cell!</p>
</div>
CSS:
.containerThree{
border: 1px solid purple; /* for the example */
/* and that it!!! */
}
.containerThree p, .containerThree div{
border: 1px solid blue;
width: 20%; /* can't add beyond total width of parent */
display: inline-block;
*display: inline; /* ie7 hack */
zoom: 1; /* ie7 hack */
vertical-align: middle;
}
.containerThree div{ /* to simulate a big element */
height: 400px;
}
.
js ya, :
<!doctype html>
<html lang="en">
<head>
<style type="text/css">
#blockbox { height: 500px; border: 1px solid black;}
#container, #placeholder { height: 100%; }
#content, #placeholder { display:inline-block; vertical-align: middle; }
</style>
</head>
<body>
<div id="blockbox">
<p id="container">
<span id="content">
Content
</span>
<span id="placeholder"></span>
</p>
</div>
</body>
</html>
, display:inline-block display:table-cell display:table parent .
: