URL中的CSS选择器 [英] CSS selector in the URL
问题描述
当你有这样一个url www.example.com/#signup
时,浏览器所做的只是将它的视图集中在id为注册
,是吗?
When you have a url like this www.example.com/#signup
, what the browser does is just to focus it's view on the HTML element with id signup
, is that right?
如果以这种方式聚焦元素,是否可以更改元素的CSS样式?
Is it possible to change the element's CSS style if it's focused in that way?
Eg 假设我有一个div元素,id 注册
,那么如果我输入 www.example.com
,div的背景为白色,如果输入 www.example.com/#signup
它是黄色的。就像强调注册表单一样。这是可能的吗?
E.g. let's say I have a div element, with the id signup
, then if I enter www.example.com
, the div's background is white and if I enter www.example.com/#signup
it's yellow. Like "emphasizing" the sign up form. Is this at all possible?
推荐答案
:target { background-color: yellow; }
The :target
psuedo-class does exactly this.
这篇关于URL中的CSS选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!