How can I disable inherited css styles?

前端 未结 7 1498
借酒劲吻你
借酒劲吻你 2021-02-02 08:27

So I am creating a container with rounded corners using the following method:

div.rounded {
    background: #CFFEB6 url(\'tr.gif\') no-repeat top right;
}
div.ro         


        
7条回答
  •  灰色年华
    2021-02-02 09:06

    The simple answer is to change

    div.rounded div div div {
        padding: 10px;
    }
    

    to

    div.rounded div div div {
        background-image: none;
        padding: 10px;
    }
    

    The reason is because when you make a rule for div.rounded div div it means every div element nested inside a div inside a div with a class of rounded, regardless of nesting.

    If you want to only target a div that's the direct descendent, you can use the syntax div.rounded div > div (though this is only supported by more recent browsers).

    Incidentally, you can usually simplify this method to use only two divs (one each for either top and bottom or left and right), by using a technique called Sliding Doors.

提交回复
热议问题