How to avoid double borders on list of divs

后端 未结 5 1630
夕颜
夕颜 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: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

提交回复
热议问题