我在解决这个问题时遇到了问题,基本上它将是一个带有图标和文字的列表.图标大小保持不变,但文本不相同,如图 alt text http://i34.tinypic.com/33op84m.jpg( http://i34.tinypic.com/33op84m.jpg)所示.问题
Mycodes如下:
ul.iconifier { width: 100%; list-style: none; margin: 0 auto; padding: 0; } ul.iconifier li { float: left; margin: 10px; padding: 0; text-align: center; border: 1px solid #ccc; width:8em; height:200px; -moz-border-radius: 3px; /*--CSS3 Rounded Corners--*/ -khtml-border-radius: 3px; /*--CSS3 Rounded Corners--*/ -webkit-border-radius: 3px; /*--CSS3 Rounded Corners--*/ display: block; /*--IE6 Fix--*/ height:101%; } ul.iconifier li a.thumb{ width: 128px; height: 128px; overflow: hidden; display: block; cursor: pointer; } ul.iconifier li a.thumb:hover { } ul.iconifier li p { font: normal 0.75em Verdana, Arial, Helvetica, sans-serif; margin: 0; padding: 10px 5px; background: #f0f0f0; border-top: 1px solid #fff; /*--Subtle bevel effect--*/ text-align:center; width:118px; } ul.iconifier li a {text-decoration: none; color: #777; display: block;}
HTML:
<ul class="iconifier"> <li> <a href="#" class="thumb" Title=""><img src="img/sprite.png" alt="Contacts" /></a> <p><a href="#">English Depatment</a></p> </li> <li> <a href="#" class="thumb" title="art"><img src="img/sprite.png" alt="Art" /></a> <p><a href="#">Art Deptartment</a></p> </li> <li> <a href="#" class="thumb" title="Travel and Tourism"><img src="img/sprite.png" alt="Travel and Tourism" /></a> <p><a href="#">Mathematics</a></p> </li> <li> <a href="#" class="thumb" Title=""><img src="img/sprite.png" alt="Contacts" /></a> <p><a href="#">Business Studies</a></p> </li> <li> <a href="#" class="thumb" Title=""><img src="img/sprite.png" alt="Contacts" /></a> <p><a href="#">English Depatment with a really long title that will hopefully fall</a></p> </li> <li> <a href="#" class="thumb" title="art"><img src="img/sprite.png" alt="Art" /></a> <p><a href="#">Art Deptartment</a></p> </li> <li> <a href="#" class="thumb" title="Travel and Tourism"><img src="img/sprite.png" alt="Travel and Tourism" /></a> <p><a href="#">Mathematics</a></p> </li> <li> <a href="#" class="thumb" Title=""><img src="img/sprite.png" alt="Contacts" /></a> <p><a href="#">Business Studies</a></p> </li> <li> <a href="#" class="thumb" Title=""><img src="img/sprite.png" alt="Contacts" /></a> <p><a href="#">English Depatment</a></p> </li> <li> <a href="#" class="thumb" title="art"><img src="img/sprite.png" alt="Art" /></a> <p><a href="#">Art Deptartment</a></p> </li> </ul>你需要使用display:inline-block;而不是浮动让他们在现代浏览器下方向下推动他们的行.对于IE6& IE7使用display:inline.
用以下代码替换ul.iconifier li:
ul.iconifier li { margin: 10px; padding: 0; text-align: center; border: 1px solid #ccc; width: 8em; -moz-border-radius: 3px; /*--CSS3 Rounded Corners--*/ -khtml-border-radius: 3px; /*--CSS3 Rounded Corners--*/ -webkit-border-radius: 3px; /*--CSS3 Rounded Corners--*/ display: -moz-inline-box; /* mozilla only */ display: inline-block; /* for browsers that support display:inline-block*/ vertical-align: top; }
然后添加此代码以制作IE6& IE7的工作原理:
/* Show only to IE7 */ *:first-child + html ul.iconifier li { display: inline; } /* Show only to IE6 */ * html ul.iconifier li { display: inline; }
我从这些网站学到了这种方法:
http://gtwebdev.com/workshop/layout/inline-block-gallery.php
http://www.css-lab.com/demos/image-display/inline-block-caption.html