How to display a list inline using Twitter's Bootstrap

前端 未结 9 1441
陌清茗
陌清茗 2021-01-29 21:46

I want to display a list inline using Bootstrap. Is there a class I can add from Bootstrap to achieve this?

相关标签:
9条回答
  • 2021-01-29 22:01

    This solution works using Bootstrap v2, however in TBS3 the class INLINE. I haven't figured out what is the equivalent class (if there is one) in TBS3.

    This gentleman had a pretty good article of the differences between v2 and v3.

    http://mattduchek.com/differences-between-bootstrap-v2-3-and-v3-0/

    EDIT - use CSS to target the li elements to solve your problem as below

        { display: inline-block; }
    

    In my situation I was targeting the UL, instead of the LI

        nav ul li { display: inline-block; }
    
    0 讨论(0)
  • 2021-01-29 22:06

    Bootstrap 2.3.2

    <ul class="inline">
      <li>...</li>
    </ul>
    

    Bootstrap 3

    <ul class="list-inline">
      <li>...</li>
    </ul>
    

    Bootstrap 4

    <ul class="list-inline">
      <li class="list-inline-item">Lorem ipsum</li>
      <li class="list-inline-item">Phasellus iaculis</li>
      <li class="list-inline-item">Nulla volutpat</li>
    </ul>
    

    source: http://v4-alpha.getbootstrap.com/content/typography/#inline

    Updated link https://getbootstrap.com/docs/4.4/content/typography/#inline

    0 讨论(0)
  • 2021-01-29 22:08

    Inline is not actually the inline we maybe require - i.e. display:inline

    Bootstrap inline as far as I observer is more of a horizontal orientation

    To display the list inline with other elements then we do need

    display: inline; added to the UL
    
    <ul class="unstyled inline" style="display:inline">
    

    NB// Add to stylesheet

    0 讨论(0)
  • 2021-01-29 22:12

    While TheBrent's answer is true in general, it does not answer the question of how to do it in the official bootstrap way. The markup for bootstrap is simple:

    <ul class="inline">
      <li>1</li>
      <li>2</li>
      <li>3</li>
    </ul>
    

    Source

    http://jsfiddle.net/MgcDU/4602/

    0 讨论(0)
  • 2021-01-29 22:16

    According to Bootstrap documentation of 2.3.2 and 3, the class should be defined like this:

    Bootstrap 2.3.2

    <ul class="inline">
      <li>...</li>
    </ul>
    

    Bootstrap 3

    <ul class="list-inline">
      <li>...</li>
    </ul>
    
    0 讨论(0)
  • 2021-01-29 22:18

    According to the Bootstrap documentation, you need to add the class 'inline' to your list; like this:

    <ul class="inline">
        <li>Item one</li>
        <li>Item two</li>
        <li>Item three</li>
    </ul>
    

    However, this does not work as there seems to be some CSS missing in the Bootstrap CSS file referring to the class 'inline'. So additionally, add the following lines to your CSS file to make it work:

    ul.inline > li, ol.inline > li {
        display: inline-block;
        padding-right: 5px;
        padding-left: 5px;
    }
    
    0 讨论(0)
提交回复
热议问题