gpt4 book ai didi

html - CSS 倾斜和变换在 Chrome 和 Edge 上添加了不需要的轮廓

转载 作者:太空宇宙 更新时间:2023-11-04 01:12:21 26 4
gpt4 key购买 nike

如本例所示 https://jsfiddle.net/xozytmbv/5/有一个奇怪的 1px 深色边框(我假设背景是 #nav 元素。最初它存在于所有浏览器中。

我通过添加 translateZ(1px) 找到了 Firefox 的解决方案,如下所示 Unwanted outline on border when parent is transformed但它不适用于 Chrome 或 Edge。

#nav {
background-color: #183650;
overflow: hidden;
}
ul {
margin: 0 auto;
width: 100%;
display: flex;
justify-content: center;
align-content: center;
}
li {
padding: 9px 0;
list-style: none;
}
li.last,
li.first {
background: none transparent;
position: relative;
}
li.last::after {
content: "";
position: absolute;
top: 0;
left: 100%;
width: 1000px;
height: 100%;
background-color: #20bef2;
}
li a {
border: none;
color: #FFF;
text-transform: uppercase;
font-size: 17px;
letter-spacing: 1px;
padding: 0.75em 0.7em;
}
li.last {
background-color: #20bef2;
border-left: 3px solid #FFF;
}
li a {
text-decoration: none;
}
li a:hover {
background: none transparent;
}
li:last-child {
background-color: #20bef2;
transform: translateZ(1px) skew(-15deg);
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
li:last-child a {
transform: translateZ(1px) skew(15deg);
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}

Firefox(根据需要):

enter image description here

Chrome 和 Edge:

enter image description here

边框不仅在右侧可见,顶部和底部也可见,并且超出了 li.last

最佳答案

调整 :after 元素的位置使其重叠并避免这种情况。因此,将 left:100% 改为 left:0 并调整 z-index:

#nav {
background-color: #183650;
overflow: hidden;
}

ul {
margin: 0 auto;
width: 100%;
display: flex;
justify-content: center;
align-content: center;
}

li {
padding: 9px 0;
list-style: none;
}

li.last,
li.first {
background: none transparent;
position: relative;
}

li.last::after {
content: "";
position: absolute;
top: 0;
left: 0; /*changed this */
z-index:-1; /*Added this*/
width: 100vw;
height: 100%;
background-color: #20bef2;
}

li a {
border: none;
color: #FFF;
text-transform: uppercase;
font-size: 17px;
letter-spacing: 1px;
padding: 0.75em 0.7em;
}

li.last {
background-color: #20bef2;
border-left: 3px solid #FFF;
}

li a {
text-decoration: none;
}

li a:hover {
background: none transparent;
}

li:last-child {
background-color: #20bef2;
transform: translateZ(1px) skew(-15deg);
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}

li:last-child a {
transform: translateZ(1px) skew(15deg);
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
<div id="nav">
<ul>
<li class="first"><a href="#">Item</a></li>
<li><a href="#">Item</a></li>
<li class="last"><a href="#">Item</a></li>
</ul>
</div>

关于html - CSS 倾斜和变换在 Chrome 和 Edge 上添加了不需要的轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50911300/

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