How can I set margin top/bottom to a li?

前端 未结 4 1313
轮回少年
轮回少年 2020-12-20 06:16

Here is my code:



        
4条回答
  •  盖世英雄少女心
    2020-12-20 06:46

    Answer

    The result is very easy to achieve. Simply add

        background-clip: content-box;
    

    to your CSS.

    li {
      padding: 5px 4px 6px 7px;
      list-style: none;
      
        background-clip: content-box;
    }
    li + li {
      border-top: 1px solid #eff0f1;
    }
    li:hover {
      background-color: #f7f8f8;
    }
    • padding
    • padding else
    • padding else again

    full exmample of background-clip:

    div {
      background-color:#faa;
      border:3px dotted black;
      margin:20px;
      padding:20px;
    }
    
    .normal {
        background-clip: border-box;
    }
    
    .padding-box {
        background-clip: padding-box;
    }
    
    .content-box {
      /* note this does not color the background of the border */
        background-clip: content-box;
    }
    Normal
    content box
    padding box

提交回复
热议问题