CSS: Is it correct that text content of a div overflows into the padding?

前端 未结 7 1310
傲寒
傲寒 2021-01-30 10:55

I expected that the padding inside a div would remain clear of any text. But given the following html/css, the content-text spills out into the padding;

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 11:25

    It is by design as overflow: hidden uses the border as its clip so contents will flow into the padding.

    You can use a box-shadow here that is the same color as your background to generate some fake padding that the text won't flow into.

    box-shadow: 0px 0px 0px 5px black;
    

    You'll have to adjust margins and padding to account for this but its the most painless solution I've found so far.

提交回复
热议问题