Chrome上边框下方的空白区域

问题描述 投票:1回答:1

让我们来看看这个非常简单的HTML / CSS代码:

<html>
    <head>
        <style>
            body{
                margin:0
            }
            /* top div which height is set to 1px/5px/9px/13px...*/
            .first{
                height:5px
            }
            /* problematic atribute */
            .second.parent{
                border-top:1px solid red
            }
            /* background and height is set only to highlight my problem */
            .child{
                height:15px;
                background:black
            }
        </style>
    </head>
<body>
    <div class="first"></div>
    <div class="second parent">
        <div class="child"></div>
    </div>
</body>
</html>

Firefox上的一切看起来都很好:no problem on Firefox

不幸的是,在Chrome 65上存在一个问题 - 第二个div子项顶部的空白区域:

problem on Chrome

Chrome上的缩放屏幕截图(查看红色边框和黑色背景之间的白色):

problem on Chrome (x2 zoom)

你知道我的问题是什么原因吗?

html css google-chrome border
1个回答
1
投票

它的浏览器问题,但如果你使用Em或百分比,它可以帮助

<html>
    <head>
        <style>
            body{
                margin:0
            }
            /* top div which height is set to 1px/5px/9px/13px...*/
            .first{
                height:0.3125em
            }
            /* problematic atribute */
            .second.parent{
                border-top:0.0625em solid red
            }
            /* background and height is set only to highlight my problem */
            .child{
                height:0.9375em;
                background:black
            }
        </style>
    </head>
<body>
    <div class="first"></div>
    <div class="second parent">
        <div class="child"></div>
    </div>
</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.