The And here is another option, which may This technique uses an
CSS just sizes the
by setting the
an inline-block with
vertical-align:
. Then it sets the line-height back to normal for the
middle
, so its contents will flow naturally inside the
block.
/>Simulating table
display
not work on older browsers that don't support display: table
and
display: table-cell
(basically just Internet Explorer
7). Using CSS we simulate table behavior (since tables support vertical alignment), and
the HTML is the same as the second example:
class="snippet" data-lang="js" data-hide="false" data-console="true"
data-babel="false">
class="snippet-code-css lang-css prettyprint-override">div {
display: table;
height: 100px;
width: 100%;
text-align: center;
border: 2px dashed #f69c55;
}
span
{
display: table-cell;
vertical-align:
middle;
}
Hello
World!
/>Using absolute
positioning
absolutely positioned element setting top, bottom, left and right to 0. It is described
in more detail in an article in Smashing Magazine, href="http://coding.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/"
rel="nofollow noreferrer">Absolute Horizontal And Vertical Centering In
CSS.
data-lang="js" data-hide="false" data-console="true"
data-babel="false">
class="snippet-code-css lang-css prettyprint-override">div {
display: flex;
justify-content: center;
align-items:
center;
height: 100px;
width: 100%;
border:
2px dashed #f69c55;
}
class="snippet-code-html lang-html
prettyprint-override">
Hello
World!
, vertically center aligns the
's line-height equal to its height, and makes the
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment