Created
November 25, 2013 01:04
-
-
Save carlos-sanchez/7634709 to your computer and use it in GitHub Desktop.
Absolute Center with Inline Block.
The content block’s width must be declared to be no wider than 100% of the container minus 0.25em if the content is wider than the container. like a block with long paragraph text. Otherwise, the content block will be pushed to the top, which is the reason for using :after. Using :before caused the content to b…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.Center-Container.is-Inline { | |
text-align: center; | |
overflow: auto; | |
} | |
.Center-Container.is-Inline:after, | |
.is-Inline .Center-Block { | |
display: inline-block; | |
vertical-align: middle; | |
} | |
.Center-Container.is-Inline:after { | |
content: ''; | |
height: 100%; | |
margin-left: -0.25em; /* To offset spacing. May vary by font */ | |
} | |
.is-Inline .Center-Block { | |
max-width: 99%; /* Prevents issues with long content causes the content block to be pushed to the top */ | |
/* max-width: calc(100% - 0.25em) /* Only for IE9+ */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="Center-Container is-Inline"> | |
<div class="Center-Block"> | |
<!-- CONTENT --> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment