一页上可以有两个或多个:target选择器,而不会互相干扰? [英] Can there be two or more :target selectors on one page without them interfering each other?

查看:98
本文介绍了一页上可以有两个或多个:target选择器,而不会互相干扰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以仅使用CSS来做到这一点?每个新的:target似乎都会更改URI(.html#我的目标名称出现在这里),并且很自然会弄乱/重置其他先前的行为.

Is it possible to do it just with CSS? Every new :target seems to change the URI (.html#my target name comes here) and naturally that messes / resets the other previous behavior.

如果只有一种方法可以将其他:target分配为无声的"或不可见的",这样它就不会影响URI,并且:targets都可以发挥各自的作用.还是会破坏这个选择器的全部目的?

If only there would be a way to assign other :target to be "silent" or "invisible", so that it doesn't affect the URI and both :targets could function on their separate rights. Or would this defeat the whole purpose of this selector?

推荐答案

在一致的HTML页面中,一次只能有一个:target元素.

In a conforming HTML page, there can only ever be one :target element at a time.

导航到另一个目标的那一刻,URI中的散列片段就会更改,从而使以前的历史记录(无双关)不再与URI相关.同样,:target将不再适用于以前是目标元素的任何元素.

The moment you navigate to another target, the hash fragment in the URI changes, making the previous one history (no pun intended) and no longer relevant to the URI. In the same way, :target will no longer apply to whichever element previously was the target element.

因此,的确,您要实现的行为将破坏HTML文档的:target选择器的目的.目前,仅使用CSS仍无法继续基于此类行为对其应用样式.

So, indeed, the behavior you're trying to achieve would defeat the purpose of the :target selector for HTML documents. There is currently no way to continue applying styles to it based on such behavior using only CSS.

这篇关于一页上可以有两个或多个:target选择器,而不会互相干扰?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆