gpt4 book ai didi

html - 收缩时 Div 不会 100% 填满容器

转载 作者:太空宇宙 更新时间:2023-11-04 04:10:35 25 4
gpt4 key购买 nike

假设您有 5 个 div。一个是容器,另外四个是 child 。您已将每个设置为容器的 25%,并为每个设置了与容器背景分开的背景。

当您调整浏览器大小时,您的 4 个 div 在某个时间点并没有完全跨越,它们可能会偏离几个像素。有没有办法阻止这种形式的发生?我假设它正在发生,因为它“捕捉到每个像素”,因此在调整浏览器大小时会留下一个小间隙。

25% width not going all the way across

#container { 
width: 100%;
background: #000;
}
.children {
width: 25%;
float: left;
background: #fff;
}

JSFiddle:http://jsfiddle.net/AEvUL/

Safari 中 JSFiddle 页面的屏幕截图:http://cl.ly/image/1o1O2O401E0f

最佳答案

John Resig 有一篇关于这个问题的帖子,使用这个确切的案例作为例子。

http://ejohn.org/blog/sub-pixel-problems-in-css/

Take the following page for example. You have 4 floated divs, each with a width of 25%, contained within a parent div of width 50px. Here’s the question: How wide are each of the divs?

The problem lies in the fact that each div should be, approximately, 12.5px wide and since technology isn’t at a level where we can start rendering at the sub-pixel level we tend to have to round off the number. The problem then becomes: Which way do you round the number? Up, down, or a mixture of the two? I think the results will surprise you, as they did me.

关于这个主题还有几个 Stack Overflow 问题:

关于html - 收缩时 Div 不会 100% 填满容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20748907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com