Last active
December 17, 2015 06:09
-
-
Save giacomopaita/5563712 to your computer and use it in GitHub Desktop.
Css to center a <div> with dynamic width.
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="example"> | |
<div class="outer"> | |
<div id="centeredContent" class="inner"> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit. | |
</div> | |
</div> | |
</div> |
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
.example { | |
width: 960px; | |
float: left; | |
clear: both; | |
margin: 0 0 50px 0; | |
} | |
.outer { | |
float: left; | |
clear: both; | |
position: relative; | |
left: 50%; | |
} | |
.inner { | |
position: relative; | |
left: -50%; | |
} | |
#centeredContent { | |
background: #F4F0E4; | |
border: 1px solid #C2BEB2; | |
padding: 20px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Css center a <div / > or another Html tag in its parent container, irrespective of its width.