Ignore parent padding

后端 未结 12 873
梦如初夏
梦如初夏 2021-01-30 19:23

I\'m trying to get my horizontal rule to ignore the parent padding.

Here\'s a simple example of what I have:

#par         


        
12条回答
  •  日久生厌
    2021-01-30 19:31

    Your parent is 120px wide - that is 100 width + 20 padding on each side so you need to make your line 120px wide. Here's the code. Next time note that padding adds up to element width.

    #parent
    {
        width: 100px;
        padding: 10px;
        background-color: Red;
    }
    
    hr
    {
        width: 120px;
        margin:0 -10px;
        position:relative;
    }
    

提交回复
热议问题