hide line beginning and end text separators

后端 未结 3 1070
南旧
南旧 2020-12-30 05:33

two solutions below: one with pure css, the second with jQuery, allowing any kind of symbol/image to be a separator

pre: Fairly hard to formulate an

相关标签:
3条回答
  • 2020-12-30 05:49

    Try this:

    jQuery:

    $('document').ready(function() {
        $('div').find('a').not(':last-child').after(' | ');
    });
    

    HTML:

    <div><a href="#">tag 1</a><a href="#">tag 2</a><a href="#">tag 3</a></div>
    <div><a href="#">tag 1</a><a href="#">tag 2</a><a href="#">tag 3</a></div>
    <div><a href="#">tag 1</a><a href="#">tag 2</a><a href="#">tag 3</a></div>
    

    This way, your content separator can be any HTML content.

    0 讨论(0)
  • 2020-12-30 06:05

    Yes you can do this but you need to put the | in a tag. Look at this example

    HTML:

    <div id="tags">
        <a href="#">C++</a>
        <span>|</span>
        <a href="#">PHP</a>
        <span>|</span>
        <a href="#">ASP</a>
        <span>|</span>
        <a href="#">JavaScript</a>
        <span>|</span>
        <a href="#">jQuery</a>
        <span>|</span>
        <a href="#">HTML 5</a>
        <span>|</span>
        <a href="#">StackOverflow</a>
    </div>
    

    CSS:

    #tags {
        width: 170px;
    }
    #tags a {
        white-space: nowrap;
    }
    

    JavaScript (jQuery):

    var iTop;
    $("#tags a").each(function() {
        if (iTop < $(this).offset().top) {
            $(this).prev("span").remove();
        }
        iTop = $(this).offset().top;
    });
    
    0 讨论(0)
  • 2020-12-30 06:11

    Here's an idea: http://jsfiddle.net/WyeSz/
    (note that the jsfiddle demo uses a CSS reset, you may need a little more CSS than this to reset list styles, etc.)

    Basically, you set border-left on the list items, then position the entire list -1px to the left within a container that has overflow:hidden, which cuts off the left borders.

    <div>
        <ul>
            <li>C++</li>
            <li>PHP</li>
            <li>CSS</li>
            <li>ASP</li>
            <li>JavaScript</li>
            <li>jQuery</li>
            <li>HTML 5</li>
            <li>StackOverflow</li>
        </ul>
    </div>
    
    ul {
        width:200px;  
        margin-left:-1px;/* hide the left borders */
    }
    li {
        float:left;   
        padding:2px 10px;
        border-left:1px solid #000;
    }
    div {
       overflow:hidden;/* hide the left borders */  
    }
    
    0 讨论(0)
提交回复
热议问题