-
-
Save asbarron/3093263 to your computer and use it in GitHub Desktop.
Floating divs to auto shrink to text size
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
a:link { color:white } | |
img { | |
height:600px; | |
width:300px; | |
position: relative; | |
} | |
ul { | |
list-style-type: none; | |
padding:0; | |
} | |
#container { | |
top:30px; | |
padding:5px 0px 5px 0px; | |
position: absolute; | |
width:300px; | |
} | |
.item { | |
float:left; | |
background: rgba(0, 0, 0, 0.5); | |
height:25px; | |
margin: 5px; | |
padding:10px; | |
clear:both; | |
} |
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
<img src="http://subtlepatterns.com/patterns/tileable_wood_texture.png" > | |
<div id="container"> | |
<ul> | |
<li><a href="#"><div class="item">My</div><a></li> | |
<li><a href="#"><div class="item">supar long link hax</div><a></li> | |
<li><a href="#"><div class="item">brings all the</div><a></li> | |
<li><a href="#"><div class="item">divs inside the container.</div><a></li> | |
</ul> | |
</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
http://jsfiddle.net/mztriz/xbvmf/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A code snippit to show that divs can be auto resized by text length.
Works by floating the div to the left and then clearing it after.