简体   繁体   English

Chrome中的CSS错误:如何删除项目之间的空间

[英]CSS bug in Chrome: how to remove space between items

I have found an issue in a plugin I am developing. 我在开发的插件中发现了一个问题。 There is a space between the boxes when the percentages add up exactly. 百分比精确地相加时,框之间有一个空格。 This issue also only arises at certain widths - adjusting the width of the .wrapper div will in fact display the items correctly. 仅在某些宽度下也会出现此问题-调整.wrapper div的宽度实际上将正确显示项目。

  1. Why does this happen? 为什么会这样? And why is it seemingly only at certain sizes? 为什么看起来只有某些尺寸?
  2. How do I fix it? 我如何解决它? I can not simply adjust the width of the .wrapper 我不能简单地调整.wrapper的宽度

 .wrapper { width: 454px; height: 200px; position: relative; border: 1px solid #ddd; } .inner { width: auto; height: 100%; position: relative; } .item-holder { width: 100%; height: 100%; position: relative; } #item1 { position: absolute; width: 49.8%; height: 49.8%; top: 16.6%; left: 41.5%; background: red; } #item2 { position: absolute; width: 8.7%; height: 33.2%; top: 33.2%; left: 91.3%; background: green; } 
 <div class="wrapper"> <div class="inner"> <div id="item1"> </div> <div id="item2"> </div> </div> </div> 

Link to fiddle: https://jsfiddle.net/4pve7ws4/ 链接到小提琴: https : //jsfiddle.net/4pve7ws4/

The width and other numbers get rounded to an integer number of pixels, sometimes this can lead to unexpected results. 宽度和其他数字会四舍五入为整数像素,有时这可能会导致意外结果。

You should round the numbers yourself, or try to go further in details like 49.8957515 which sometimes works. 您应该自己对数字进行四舍五入,或者尝试进一步使用一些细节,例如49.8957515,这有时会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM