CSS: Adding a border changes the background-color (?!)

前端 未结 4 886
渐次进展
渐次进展 2020-12-19 20:50

HTML:

CSS:

div { background-color:green; border-top:1px solid white; }
p {          


        
4条回答
  •  佛祖请我去吃肉
    2020-12-19 21:30

    It's because the

    is right against the bottom of the enclosing

    . Since there's nothing constraining the height of the
    , the rendering gives just enough space to fit down to the bottom of the

    . Any explicit height > 50px will show the bottom.

    Yup, on the update, exactly. The box expands vertically, but not horizonally. Also, padding puts space on the inside of the box, so the p can't push right up against the bounds.

    Read up on the CSS box model, for example here: http://www.w3schools.com/css/css_boxmodel.asp and here: http://www.w3.org/TR/CSS21/box.html

提交回复
热议问题