我正尝试关注此Stripe博客文章:
https://stripe.com/blog/connect-front-end-experience
虽然我的最终产品通常看起来像教程中的样子,但我的浏览器似乎处于无意间的空白。我不愿意将它们称为“ gap”,因为“ gap”在CSS网格中具有特定的含义,而且我的错误似乎更多是随机的舍入错误。
这里有一些图片可供比较。 Safari比chrome更优雅地处理网格,但是仍然存在问题。请注意照片中的像素化白线。
剥离最终产品:
我在Safari上的尝试:
我在Chrome上的尝试
这是我正在使用的代码:
.stripes {
display: grid;
grid: repeat(5, 200px) / repeat(10, 1fr);
transform: skewY(-12deg);
transform-origin: 0;
}
.stripes :nth-child(1) {
grid-column: span 3;
}
.stripes :nth-child(2) {
grid-area: 3 / span 3 / auto / -1;
}
.stripes :nth-child(3) {
grid-row: 4;
grid-column: span 5;
}
.blue {
background: blue;
}
.red {
background: red;
}
.special1 {
background: linear-gradient(to bottom left, #1890ff, #42C6EB);
}
.special2{
background: linear-gradient(to left, #1890ff, #42C6EB);
}
.special3{
background: linear-gradient(to left, rgba(66,198,235, 0.9), rgba(66,198,235,0.2));
}
.topRow {
background: linear-gradient(to top, rgb(52, 173, 242), #1890ff);
}
.secondRow {
background: linear-gradient(to top, #42C6EB, rgb(52, 173, 242))
}
.thirdRow {
background: #42C6EB
}
.fourthRow {
background: linear-gradient(to top, rgba(66,198,235,0.8), #42C6EB)
}
.fifthRow {
background: linear-gradient(to top, rgba(66,198,235,0.2), rgba(66,198,235,0.8))
}
<div class="stripes">
<div class="special1"></div>
<div class="special2"></div>
<div class="special3"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="fourthRow"></div>
<div class="fourthRow"></div>
<div class="fourthRow"></div>
<div class="fourthRow"></div>
<div class="fourthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
</div>
经过一番尝试后,问题似乎出在使用linear-gradient
上。当我从渐变色切换为纯色时,竖线消失了,但沿着对角线条纹延伸的细混叠线却消失了。有什么想法吗?
答案 0 :(得分:4)
这是sub-pixel rendring issue。不幸的是,由于每个浏览器对小于 1px 的值进行计算时,对浏览器的处理方式不同,因此没有简单而通用的修补程序。
在您的情况下,可以为整个容器添加背景,以避免(或至少最小化)这种影响:
it
.stripes {
display: grid;
grid: repeat(5, 200px) / repeat(10, 1fr);
background:linear-gradient(to top,rgba(66, 198, 235, 0.2),#1890ff);
transform: skewY(-12deg);
transform-origin: 0;
}
.stripes :nth-child(1) {
grid-column: span 3;
}
.stripes :nth-child(2) {
grid-area: 3 / span 3 / auto / -1;
}
.stripes :nth-child(3) {
grid-row: 4;
grid-column: span 5;
}
.blue {
background: blue;
}
.red {
background: red;
}
.special1 {
background: linear-gradient(to bottom left, #1890ff, #42C6EB);
}
.special2{
background: linear-gradient(to left, #1890ff, #42C6EB);
}
.special3{
background: linear-gradient(to left, rgba(66,198,235, 0.9), rgba(66,198,235,0.2));
}
.topRow {
background: linear-gradient(to top, rgb(52, 173, 242), #1890ff);
}
.secondRow {
background: linear-gradient(to top, #42C6EB, rgb(52, 173, 242))
}
.thirdRow {
background: #42C6EB
}
.fourthRow {
background: linear-gradient(to top, rgba(66,198,235,0.8), #42C6EB)
}
.fifthRow {
background: linear-gradient(to top, rgba(66,198,235,0.2), rgba(66,198,235,0.8))
}
如果您只想获得视觉效果,可以考虑在一个容器中考虑多个背景,而不是考虑所有这些代码:
<div class="stripes">
<div class="special1"></div>
<div class="special2"></div>
<div class="special3"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="topRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="secondRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="thirdRow"></div>
<div class="fourthRow"></div>
<div class="fourthRow"></div>
<div class="fourthRow"></div>
<div class="fourthRow"></div>
<div class="fourthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
<div class="fifthRow"></div>
</div>
.container {
height:1000px;
transform: skewY(-12deg);
transform-origin:0;
background:
/*special 1*/
linear-gradient(to bottom left, #1890ff, #42C6EB) 0 0/calc(3*100%/10) calc(100%/5),
/*special 2*/
linear-gradient(to left, #1890ff, #42C6EB) 100% calc(100%/2)/calc(3*100%/10) calc(100%/5),
/*special 3*/
linear-gradient(to left, rgba(66,198,235, 0.9), rgba(66,198,235,0.2)) 0 calc(3*100%/4)/50% calc(100%/5),
/*Top row*/
linear-gradient(to top, rgb(52, 173, 242), #1890ff) 0 0/100% calc(100%/5),
/*second row*/
linear-gradient(to top, #42C6EB, rgb(52, 173, 242)) 0 calc(100%/4)/100% calc(100%/5),
/*third row*/
linear-gradient(#42C6EB, #42C6EB) 0 calc(100%/2)/100% calc(100%/5),
/*fourth row*/
linear-gradient(to top, rgba(66,198,235,0.8), #42C6EB) 100% calc(3*100%/4)/50.1% calc(100%/5),
/*fifth row*/
linear-gradient(to top, rgba(66,198,235,0.2), rgba(66,198,235,0.8)) 0 100%/100% calc(100%/5);
background-repeat:no-repeat;
}
答案 1 :(得分:0)
与HTML中的div发生奇怪的交互,如果下一个div不在上一个div所在的同一行上开始,它将创建空白。我发现有两个修复程序。一种是在与上一个div末尾相同的行上开始每个div。另一个是像这样在两个div之间发表评论 :
</div><!--
--><div>