I have a problem with automatically setting the UL width, which the LI can float directly.
If I change css, set UL with a width like '1000px' and not 'auto' ; that what I want can be done.
However, are there other CSS-only settings also to achieve the same result ?, because I want to automatically change the UL width as the number of LIs increases.
Now is like div ul-------------------------------div ul | /////// //////// | | /////// li /////// li | --------------------------------- /////// //////// ////// li /////// li I want to be like this div div ul-------------------------------------------------------------ul | /////// //////// | /////// //////// | | /////// li /////// li | /////// li /////// li | -------------------------------------------------------------
http://jsfiddle.net/KgyHZ/21/
HTML
<div class='test'> <ul> <li></li> <li></li> <li></li> <li></li> </ul> </div>
CSS
.test{ width: 500px; height: 100px; overflow: hidden; } .test > ul{ list-style:none; width: auto; height: 100%; background-color:#999; display: block; padding: 0px; margin: 0px; } .test > ul > li{ float: left; display: block; height: 100%; width: 180px; background-color:#99c; margin-right:10px; }
Thanks so much for your advice.
source share