Add a pipe separator after items in an unordered list unless that item is the last on a line

前端 未结 10 987
逝去的感伤
逝去的感伤 2020-11-29 18:54

Is it possible to style this html ...

  • Dogs
  • Cats
  • Lions
  • Tig
相关标签:
10条回答
  • 2020-11-29 19:12

    You can use the following CSS to solve.

    ul li { float: left; }
    ul li:before { content: "|"; padding: 0 .5em; }
    ul li:first-child:before { content: ""; padding: 0; }
    

    Should work on IE8+ as well.

    0 讨论(0)
  • 2020-11-29 19:13

    I came across a solution today that does not appear to be here already and which seems to work quite well so far. The accepted answer does not work as-is on IE10 but this one does. http://codepen.io/vithun/pen/yDsjf/ credit to the author of course!

    .pipe-separated-list-container {
      overflow-x: hidden;
    }
    .pipe-separated-list-container ul {
      list-style-type: none;
      position: relative;
      left: -1px;
      padding: 0;
    }
    .pipe-separated-list-container ul li {
      display: inline-block;
      line-height: 1;
      padding: 0 1em;
      margin-bottom: 1em;
      border-left: 1px solid;
    }
    <div class="pipe-separated-list-container">
      <ul>
        <li>One</li>
        <li>Two</li>
        <li>Three</li>
        <li>Four</li>
        <li>Five</li>
        <li>Six</li>
        <li>Seven</li>
        <li>Eight</li>
        <li>Nine</li>
        <li>Ten</li>
        <li>Eleven</li>
        <li>Twelve</li>
        <li>Thirteen</li>
        <li>Fourteen</li>
        <li>Fifteen</li>
        <li>Sixteen</li>
        <li>Seventeen</li>
        <li>Eighteen</li>
        <li>Nineteen</li>
        <li>Twenty</li>
        <li>Twenty One</li>
        <li>Twenty Two</li>
        <li>Twenty Three</li>
        <li>Twenty Four</li>
        <li>Twenty Five</li>
        <li>Twenty Six</li>
        <li>Twenty Seven</li>
        <li>Twenty Eight</li>
        <li>Twenty Nine</li>
        <li>Thirty</li>
      </ul>
    </div>

    0 讨论(0)
  • 2020-11-29 19:13

    Slightly modified SCSS version which gives you control of the pipe | size and will eliminate padding from first and last list items while respects borders.

    
    $pipe-list-height: 20px;
    $pipe-list-padding: 15px;
    
    .pipe-list {
        position: relative;
        overflow: hidden;
        height: $pipe-list-height;
    
        > ul {
            display: flex;
            flex-direction: row;
    
            > li {
                position: relative;
                padding: 0 $pipe-list-padding;
    
                &:after {
                    content: " ";
                    position: absolute;
                    border-right: 1px solid gray;
                    top: 10%;
                    right: 0;
                    height: 75%;
                    margin-top: auto;
                    margin-bottom: auto;
                }
    
                &:first-child {
                    padding-left: 0;
                }
    
                &:last-child {
                    padding-right: 0;
    
                    &:after {
                        border-right: none;
                    }
                }
            }
        }
    }
    
    <div class="pipe-list">
      <ul>
        <li>Link</li>
        <li>Link</li>
        <li>Link</li>
      </ul>
    </div>
    
    0 讨论(0)
  • 2020-11-29 19:20

    Yes, you'll need to use pseudo elements AND pseudo selectors: http://jsfiddle.net/cYky9/

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