gpt4 book ai didi

css - 使用 :target for data attribute in CSS

转载 作者:行者123 更新时间:2023-11-28 04:09:14 25 4
gpt4 key购买 nike

我有一个 anchor ,它使用数据属性链接到元素,在定位时需要特殊样式。

我的逻辑

span[data-anchor="my-data"]:target {
/* styles */
}

<a href="#my-data">anchor</a>

<span data-anchor="my-data">My Data</span>

我正在使用 Shortcodes Ultimate (WP) https://gndev.info/shortcodes-ultimate/

最佳答案

:target 作用于当前事件的 anchor 它真的不需要选择器

尝试这样的事情:

html:

<a href="#my-data">anchor</a>
<span id="my-data">My Data</span>

CSS:

:target {
background-color: red;
}

在这里查看一个工作示例- https://jsfiddle.net/0fkh8n09/

关于css - 使用 :target for data attribute in CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42795918/

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