html - CSS 转换中的奇怪错误 - 1 像素加上一些透明度
问题描述
问题是我正在尝试制作一条线来标记列表中的项目,并且以某种方式出现了一个两像素的条纹而不是一个像素,并且看起来它有一些 alpha。
我尝试使用比例使线条更细。
https://codepen.io/vendramini/pen/XWrywXV
索引.html
<div class="list-wrapper">
<ul>
<li>Do shopping</li>
<li class="marked">Wash the dishes</li>
<li class="marked-without-transform">Take a shower</li>
<li>Sleep</li>
</ul>
</div>
样式.scss
.marked{
position: relative;
&:before{
content: ' ';
display: block;
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
height: 1px;
width: 100%;
background-color: red;
}
}
.marked-without-transform{
position: relative;
&:before{
content: ' ';
display: block;
position: absolute;
top: 50%;
left: 0;
// transform: translateY(-50%);
height: 1px;
width: 100%;
background-color: red;
}
}
.list-wrapper{
max-width: 150px;
}
我想知道为什么会这样,听起来像一个错误。代码显示的不仅仅是文字。我希望有一条比 2 像素多 1 像素的直线。
解决方案
它与试图处理百分比而不是固定像素测量的变换混叠。如果你想保持相同的策略,一个快速的解决方法就像;
.marked, .marked-without-transform {
position: relative;
}
.marked:before, .marked-without-transform:before {
content: ' ';
display: block;
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
height: 1px;
width: 100%;
}
/* Workaround */
.marked:before {
border-top: red 1px solid;
}
/* Aliasing issue */
.marked-without-transform:before {
background-color: red;
}
.list-wrapper {
max-width: 150px;
}
<div class="list-wrapper">
<ul>
<li>Do shopping</li>
<li class="marked">Wash the dishes</li>
<li class="marked-without-transform">Take a shower</li>
<li>Sleep</li>
</ul>
</div>
推荐阅读
- r - 如何使用列表中的 tibbles 和 tibbles 展平列表以使所有 tibbles 处于同一级别?
- solr - Websphere Commerce 8 SOLR 中的类别名称搜索
- html2canvas - 将html2canvas图像发送到ajax的问题
- r - 经纬度县平均值
- webhooks - Reddit 是否有任何 Webhook 可以捕获消息?
- c++ - 使用 Address Sanitizer 编译主机应用程序时可使用 OpenCL
- tkinter - 在 Else 中删除标签
- postgresql - 如何使用 Kafka Connect JDBC 来获取具有多个包含同名表的模式的 PostgreSQL?
- php - 如何在 php 上使用代码登录将页面设为私有?
- google-app-engine - 如何在本地 appengine env 中修复 Flask,出现 404/500 错误