为什么浏览器缩放会在我的web css html元素中产生线条伪像

ecr0jaav  于 2023-02-01  发布在  其他
关注(0)|答案(1)|浏览(149)

在我制作的一个网页的css/html元素中,如果用户在浏览器上放大或缩小,就会出现显示问题的. Here is a code pen线的伪像。在浏览器上放大或缩小,可以看到顶部出现的红线,如下所示:

我读到过这些问题的出现,因为浏览器可以将缩放设置为1.5倍,从而产生像素的舍入问题。请参阅slack post here。但我不确定应该采取什么适当的解决方案。在我的例子中,我希望通过css样式创建的矩形元素的每一端都有三角形。除了通过svg重新创建图形外,还有什么好的技巧吗?
下面是codepen中的html/css:

#root {
  display: block;
  width: 100%;
  height: 100%;
  background-color: lightgrey;
  padding: 24px;
  max-width: 400px;
  float: center;
  position: relative;
}

#gridRoot {
  display: flex;
  flex-flow: column wrap;
  top: 50%;
  left: 50%;
  align-content: center;
}

#LegendContainer {
  box-sizing: border-box;
  display: flex;
  flex-flow: row nowrap;
  width: 100%;
  align-items: center;
  justify-content: space-between;
}

#container {
  background-color: grey;
  postion: relative;
  height: 120px;
  justify-content: center;
  left: calc(50% - 60px);
  text-align: center;
  top: calc(50% - 60px);
}

#circle {
  transform: rotate(7.39deg);
}

#jss {
  display: flex;
  position: absolute;
  background: red;
  top: 40px;
  width: 110px;
  opacity: 80%;
  height: 20px;
}

#jss::before {
  left: 0;
  width: 0;
  bottom: 0;
  height: 0;
  content: '';
  position: absolute;
  transform: rotate(180deg);
  border-top: 10px solid white;
  border-left: 10px solid #00007f;
  border-bottom: 10px solid white;
}

#jss::after {
  right: 0;
  width: 0;
  bottom: 0;
  height: 0;
  content: '';
  position: absolute;
  border-top: 10px solid white;
  border-left: 10px solid #7f0000;
  border-bottom: 10px solid white;
}
<div id="root">
  <div id="gridRoot">
    <div id="LegendContainer">
      <div id="container">
        <div id="circle">
        </div>
        <div id="jss">
        </div>
      </div>
    </div>
  </div>
</div>
unftdfkk

unftdfkk1#

::before和::after元素似乎是导致此问题的原因。

body {
  margin: 0;
}

#container {
  background-color: grey;
  position: relative;
  display: flex;
  height: 120px;
  justify-content: center;
  text-align: center;
}

#jss {
  display: flex;
  position: absolute;
  top: 40px;
  width: 110px;
  opacity: 80%;
  height: 20px;
}

#jss-internal {
  background: red;
  width: 100%;
}

#jss-before {
  content: '';
  transform: rotate(180deg);
  border-top: 10px solid white;
  border-left: 10px solid #00007f;
  border-bottom: 10px solid white;
}

#jss-after {
  border-top: 10px solid white;
  border-left: 10px solid #7f0000;
  border-bottom: 10px solid white;
}
<div id="root">
  <div id="LegendContainer">
    <div id="container">
      <div id="circle">
      </div>
      <div id="jss">
        <div id="jss-before">
        
        </div>
        <div id="jss-internal">
          
        </div>
        <div id="jss-after">
        
        </div>
      </div>
    </div>
  </div>
</div>

相关问题