html - CSS div 宽度视觉上不准确

标签 html css

我有几个 div,每个 2px 宽,它们看起来不一样(取决于它们的位置)。虽然它们被放置在全像素上,但它们的宽度看起来不同。这是所有浏览器的问题。这是可以解决的问题吗?

.a{
  position:relative;
  width:300px;
  height:10px;
  background:#ccc;
}
.b1{
  position:absolute;
  left:50px;
  width:2px;
  height:100%;
  background:blue;
}
.b2{
  position:absolute;
  left:100px;
  width:2px;
  height:100%;
  background:blue;
}
.b3{
  position:absolute;
  left:150px;
  width:2px;
  height:100%;
  background:blue;
}
<div class="a">
<div class="b1"></div>
<div class="b2"></div>
<div class="b3"></div>
</div>

最佳答案

如果你的意思是第一个“条”从开始是 50px 然后条之间的距离减小一点,那是因为你没有在第二个和第三个“的偏移量中包括条的宽度”栏”:

.a{
  position:relative;
  width:300px;
  height:10px;
  background:#ccc;
}
.b1{
  position:absolute;
  left:50px;
  width:2px;
  height:100%;
  background:blue;
}
.b2{
  position:absolute;
  left:102px;
  width:2px;
  height:100%;
  background:blue;
}
.b3{
  position:absolute;
  left:154px;
  width:2px;
  height:100%;
  background:blue;
}
[class^="b"]:after {
  content: '50px';
  width: 50px; height: 2px;
  position: absolute; bottom: -2px; left: -50px;
  text-align: center;
  font-size: 11px; font-family: sans-serif;
  background: lightcoral;
}
<div class="a">
<div class="b1"></div>
<div class="b2"></div>
<div class="b3"></div>
</div>

关于html - CSS div 宽度视觉上不准确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57334298/

相关文章:

javascript - 静态网站中的表格分页问题

css - 将图像宽度调整为容器大小的 100% - 图像下方的持久空间

CSS 包含一篇带有图像的文章作为页面调整大小

html - 如何使用纯 HTML/CSS 使 "pretty"表溢出

jquery - 使用 CSS 构建复杂的形状

javascript - 带有元素符号列表等选项的文本输入

html - 图像上的链接扩展了图像标签

css - Javafx禁用Node继承DropShadow的颜色

css - p :after content tag 内的上标

html - 如何将事件的 css 类添加到菜单项?