gpt4 book ai didi

html - 嵌套 :visited declaration not being applied (vuejs, sass 内元素的样式)

转载 作者:行者123 更新时间:2023-11-27 23:17:38 25 4
gpt4 key购买 nike

真的被这个搞糊涂了。我有一个元素网格,其中包含用于包装图像的链接、图像覆盖 div 和标题。访问链接时,嵌套图像叠加层应更改其背景颜色不透明度。但它没有被应用。我可以验证 :visited 伪类是否生效,因为它将对嵌套标题应用颜色更改。但是不透明度不会改变。我已经尝试了很多应用它的方法。这是一支笔:

https://codepen.io/heaversm/pen/gOYNJQv

HTML

<div class="gallery__container">
<div class="gallery__item">
<a class="gallery__link" href="http://codepen.io">
<div class="gallery__image_container">
<img src="https://i.imgur.com/MQcuk3n.jpg">
<div class="gallery__overlay"></div>
</div>
<p class="gallery__title">Title</p>
</a>
</div>
<div class="gallery__item">
<a class="gallery__link" href="http://nonsensesite.com">
<div class="gallery__image_container">
<img src="https://i.imgur.com/MQcuk3n.jpg">
<div class="gallery__overlay"></div>
</div>
<p class="gallery__title">Title</p>
</a>
</div>
</div>

CSS

.gallery__container {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-gap: 1.375vw;
margin: 0 auto;
padding: 40px 50px;
}

.gallery__image_container {
position: relative;
}

.gallery__item {
width: 100%;
height: auto;
}

.gallery__link {
display: block;
width: 100%;
height: 100%;
&:visited {
color: red; //just to verify visited pseudoclass is applied
.gallery__overlay {
background-color: rgba(0,0,0,.1) !important; //NOT WORKING
}
}
}

.gallery__image {
//width: 100%;
//height: auto;
}

.gallery__overlay {
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background-color: rgba(black, 0.9);
z-index: 1;
}

最佳答案

来自 https://developer.mozilla.org/en-US/docs/Web/CSS/:visited

出于隐私原因,浏览器严格限制您可以使用此伪类应用哪些样式,以及如何使用它们:

允许的 CSS 属性是

color, background-color, border-color, border-bottom-color, border-left-color, border-right-color, border-top-color, column-rule-color, and outline-color.

允许的 SVG 属性是 fillstroke

允许样式的 alpha 组件将被忽略。将使用元素的非 :visited 状态的 alpha 组件,除非该组件为 0,在这种情况下,将完全忽略 :visited 中设置的样式。尽管这些样式可以更改最终用户的颜色外观,但 window.getComputedStyle 方法将撒谎并始终返回非访问颜色的值。

根据我自己的观察,链接的子元素也受到相同的样式限制。

关于html - 嵌套 :visited declaration not being applied (vuejs, sass 内元素的样式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58188666/

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