开发者

how to create a multi column list with css?

I want to create a fixed layout that displays some images. for example, a "table" of 3 images in a row and 3 images in a column. Also i need that every li conatins some fixed width and height and the image centered and alignet to top.

So i've thinked in something开发者_如何转开发 like this:

<ul>
<li><img /></li>
<li><img /></li>
<li><img /></li>
</ul>
<ul>
<li><img /></li>
<li><img /></li>
<li><img /></li>
</ul>
<ul>
<li><img /></li>
<li><img /></li>
<li><img /></li>
</ul>

But i don't know css, still i've created some like this but still doesn't work...

ul {display: block; text-align: center; border:#666666 solid 1px; height: 150px; padding:0; margin:0;}
li { list-style:none; float:left; width: 150px; height: 150px; margin-bottom: 32px;}

Fixed version:

ul{ height: 180px; text-align:center;padding:0;}
li{list-style:none;padding:0;width: 25%;height: 180px;float: left; display:inline-block;}

Note: Only works for only one <ul> with many <li>, the columns are setted changing the width of the <li>. 25% means 4 columns, 33% = 3 columns, etc. Formula: 100/(desired columns).


I've made 3x3 box with list tag and uploaded here, hope it help you Sein.

CSS:

<style type="text/css">
    ul { list-style-type:none; margin:0px; padding:0px; overflow:hidden; }
    li { float:left; width:150px; height:150px; margin:2px; padding:3px; background:#CCCCCC; text-align:center; }
    li img { max-width:144px; }
</style>

HTML:

<ul>
    <li><img src="" /></li>
    <li><img src="" /></li>
    <li><img src="" /></li>
</ul>
<ul>
    <li><img src="" /></li>
    <li><img src="" /></li>
    <li><img src="" /></li>
</ul>
<ul>
    <li><img src="" /></li>
    <li><img src="" /></li>
    <li><img src="" /></li>
</ul>


You're almost there Sein. All I did to make it work was removed the float: left; and replaced it with display: inline-block; on the <li> tag. That lined everything up perfectly for me. If you have any issues with the vertical alignment, try setting the following on the <img> tags: vertical-align: top;

There is a phenomenal article on the Mozilla WebDev blog for addressing this: Cross-Browser Inline-Block

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜