How to add vertical spacing between block elements, but not top and bottom

前端 未结 5 736
余生分开走
余生分开走 2021-02-02 13:51

Say I have a bunch of P, LI, or DIV elements, with nothing between them. I want to control the vertical spacing between them, so they don\'t fit so tightly. But I don\'t want

5条回答
  •  长发绾君心
    2021-02-02 14:13

    Use adjacent selectors

    p + p { margin-top: 10px; }
    

    Basically the concept is that, if a p comes after another p give 10px margin in between.

    You usage is something similar to

    p + p, li + li, div + div { 
        margin-top: 10px;
    }
    

提交回复
热议问题