How to style the UL list to a single line

前端 未结 5 904
时光取名叫无心
时光取名叫无心 2020-12-02 08:40

I want to render this list in a single line.

  • List item1
  • List item2

Should be shown as

*List item2 *List item2

What CSS

相关标签:
5条回答
  • 2020-12-02 09:31

    HTML code:

    <ul class="list">
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
    </ul>
    

    CSS code:

    ul.list li{
      width: auto;
      float: left;
    }
    
    0 讨论(0)
  • 2020-12-02 09:36

    In modern browsers you can do the following (CSS3 compliant)

    ul
    {
      display:flex;  
      list-style:none;
    }
    <ul>
      <li><a href="">Item1</a></li>
      <li><a href="">Item2</a></li>
      <li><a href="">Item3</a></li>
    </ul>

    0 讨论(0)
  • 2020-12-02 09:40

    in bootstrap use .list-inline css class

    <ul class="list-inline">
        <li>Coffee</li>
        <li>Tea</li>
        <li>Milk</li>
    </ul>
    

    Ref: https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_txt_list-inline&stacked=h

    0 讨论(0)
  • 2020-12-02 09:41

    Try experimenting with something like this also:

    HTML

     <ul class="inlineList">
       <li>She</li>
       <li>Needs</li>
       <li>More Padding, Captain!</li>
     </ul>
    

    CSS

     .inlineList {
       display: flex;
       flex-direction: row;
       /* Below sets up your display method: flex-start|flex-end|space-between|space-around */
       justify-content: flex-start; 
       /* Below removes bullets and cleans white-space */
       list-style: none;
       padding: 0;
       /* Bonus: forces no word-wrap */
       white-space: nowrap;
     }
     /* Here, I got you started.
     li {
       padding-top: 50px;
       padding-bottom: 50px;
       padding-left: 50px;
       padding-right: 50px;
     }
     */
    

    I made a codepen to illustrate: http://codepen.io/agm1984/pen/mOxaEM

    0 讨论(0)
  • 2020-12-02 09:44
    ul li{
      display: inline;
    }
    

    For more see the basic list options and a basic horizontal list at listamatic. (thanks to Daniel Straight below for the links).

    Also, as pointed out in the comments, you probably want styling on the ul and whatever elements go inside the li's and the li's themselves to get things to look nice.

    0 讨论(0)
提交回复
热议问题