Related tutorial: http://codepen.io/alexandredees/pen/ojaFr
Last active
August 29, 2015 13:56
-
-
Save hofmannsven/9170328 to your computer and use it in GitHub Desktop.
How to center floating elements with no specified 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
<section id="container"> | |
<div class="center"> | |
<ul class="child"> | |
<li>Lorem Ipsum</li> | |
<li>Lorem Ipsum</li> | |
</ul> | |
</div> | |
<div class="clear"></div> | |
</section> |
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 { | |
float: right; | |
position: relative; | |
left: -50%; /* or right 50% */ | |
text-align: left; | |
} | |
.center > .child { | |
position: relative; | |
left: 50%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment