How to force a list to be vertical using html css

后端 未结 4 354
广开言路
广开言路 2020-12-24 12:57

I have a list i want to add to a

. Each listitem contains a
which in turn contain an image and a text string. The list must
相关标签:
4条回答
  • 2020-12-24 13:10

    Try putting display: block in the <li> tags instead of the <ul>

    0 讨论(0)
  • 2020-12-24 13:13

    CSS

    li {
       display: inline-block;
    }
    

    Works for me also.

    0 讨论(0)
  • 2020-12-24 13:19

    Hope this is your structure:

       <ul> 
         <li>
            <div ><img.. /><p>text</p></div>
        </li>
         <li>
            <div ><img.. /><p>text</p></div>
        </li>
         <li>
            <div ><img.. /><p>text</p></div>
        </li>
       </ul> 
    

    By default, it will be add one after another row:

    -----
    -----
    -----
    

    if you want to make it vertical, just add float left to li, give width and height, make sure that content will not break the width:

    |  |  |
    |  |  |
    
    li
    {
       display:block;
       float:left;
       width:300px; /* adjust */
       height:150px; /* adjust */
       padding: 5px; /*adjust*/
    }
    
    0 讨论(0)
  • 2020-12-24 13:22

    I would add this to the LI's CSS

    .list-item
    {
        float: left;
        clear: left;
    }
    
    0 讨论(0)
提交回复
热议问题