The list does not appear as a grid with long texts

I have a problem with this, basically it will be a list with icons and text below. The icon size remains the same, but the text does not, as shown in the figure.

alt text.

The problem is that when it <li>contains a lot of text, the rest pops up to the right of it. How can I figure this out.

My code is below:

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>
+3
source share
4 answers

You need to use display: inline-block;instead of float to make them push the line below them for modern browsers. For IE6 and IE7 use display: inline.

Replace yours ul.iconifier liwith this code:

        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;
    }

Then add this code to make IE6 and IE7 work:

   /* 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

+6

, css, , LI ( : )

+1

, , , .

CSS:

ul.iconifier li 
{
    margin-bottom: -5000px;
    padding-bottom: 5000px;
}

CSS .

,

0
source
0
source

Source: https://habr.com/ru/post/1719599/


All Articles