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

前端 未结 7 1439
傲寒
傲寒 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:27

    It is because you have constrained the width of the div to 50px causing the text to spill into the padding. Remove that width statement and the div will expand and contract with the size of the txt within it.

    helloworld
    .foo { float: left; overflow: hidden; background: red; padding-right: 10px; border: 1px solid green; }

    Hope that helps you.

提交回复
热议问题