How to avoid double borders on list of divs

后端 未结 5 1575
夕颜
夕颜 2021-01-23 04:01

I have a list of divs which are used as a FAQ. Sometimes the divs are listed below each other, sometimes there is text between them. When they are listed below one other, I have

相关标签:
5条回答
  • 2021-01-23 04:47

    You sure can use jQuery to do this:

    $('.faq').each(function(){
        if($(this).next('.faq').length > 0){
            $(this).css({borderBottom:0});   
        }
    });
    

    JSFiddle

    For each .faq, if there is another .faq following, remove this bottom border.

    0 讨论(0)
  • 2021-01-23 04:48

    Can you not simply use a negative margin ?

    .faq {width:200px;border: 1px solid #ffffd;margin-top:-1px;}
    

    http://jsfiddle.net/bYPR6/7/

    0 讨论(0)
  • 2021-01-23 04:56

    add this rule to your CSS

    .faq + .faq
    {
        border-top: none;
    }
    

    Explanation: .faq that comes directly after another .faq dont get a top border.

    1. this is a pure CSS solution (without Script)
    2. it doesnt assume anithing about the layout (the div's dont have to be last childs of a container, or at some specific index)
    3. its fixes the double border issue even if their are multiple .faq one after each other.
    4. its a cross browser solution.

    See this Working Fiddle

    0 讨论(0)
  • 2021-01-23 05:01

    Maybe just add margin-top:5px; (or less) in .faq :

    .faq {width:200px;border: 1px solid #ffffd;margin-top:5px;}
    

    http://jsfiddle.net/Wm7q7/

    0 讨论(0)
  • 2021-01-23 05:03
    .faq:nth-child(3) {
        border-bottom:none;
    }
    

    More info here

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