gpt4 book ai didi

html - 两个div之间的轻微透明空间

转载 作者:行者123 更新时间:2023-12-04 14:59:18 25 4
gpt4 key购买 nike

我有两个 div 一个在另一个上面。顶部 div 在底部有一个背景 .svg,其颜色与底部 div 的背景相同。这些应该完美对齐,然而,他们没有。它们之间有非常小的透明空间。这个空间在放大时消失,在进一步放大时重新出现(见屏幕截图)。

.top {
width: 100%;
height: 100vh;
background-color: #3772ff;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%25%22%20height%3D%22100%25%22%20viewBox%3D%220%200%20378%20378%22%3E%3Cpath%20d%3D%22M0%2C378l378%2C-0l-0%2C-47.25l-378%2C47.25Z%22%20style%3D%22fill%3A%2301161e%3B%22%2F%3E%3C%2Fsvg%3E");
background-repeat: no-repeat;
background-position: left bottom;
background-attachment: scroll;
background-size: 100%;
margin: 0;
}

.bottom {
background-color: #01161e;
padding: 128px 20%;
}
<div class="top"></div>
<div class="bottom"></div>

截图:

100% 缩放:

100% zoom

放大一点:

a bit zoomed in

进一步放大:

zooming in even further

最佳答案

可能有更优雅的解决方案,但只需将较低的元素拉高一个像素的一小部分即可克服亚像素舍入问题。

.top {
width: 100%;
height: 100vh;
background-color: #3772ff;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%25%22%20height%3D%22100%25%22%20viewBox%3D%220%200%20378%20378%22%3E%3Cpath%20d%3D%22M0%2C378l378%2C-0l-0%2C-47.25l-378%2C47.25Z%22%20style%3D%22fill%3A%2301161e%3B%22%2F%3E%3C%2Fsvg%3E");
background-repeat: no-repeat;
background-position: left bottom;
background-attachment: scroll;
background-size: 100%;
margin: 0;
}

.bottom {
background-color: #01161e;
padding: 128px 20%;
margin-top: -.5px;
/* transform: translateY(-.5px); alternative approach */
}
<div class="top"></div>
<div class="bottom"></div>

当然,你也可以设置 body 背景(或容器元素的背景)来隐藏它:

.container {
background-color: #01161e;
}

.top {
width: 100%;
height: 100vh;
background-color: #3772ff;
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22100%25%22%20height%3D%22100%25%22%20viewBox%3D%220%200%20378%20378%22%3E%3Cpath%20d%3D%22M0%2C378l378%2C-0l-0%2C-47.25l-378%2C47.25Z%22%20style%3D%22fill%3A%2301161e%3B%22%2F%3E%3C%2Fsvg%3E");
background-repeat: no-repeat;
background-position: left bottom;
background-attachment: scroll;
background-size: 100%;
margin: 0;
}

.bottom {
background-color: #01161e;
padding: 128px 20%;
}
<div class="container">
<div class="top"></div>
<div class="bottom"></div>
</div>

关于html - 两个div之间的轻微透明空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67267836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com