<ul>
<li>
<a href='#q1' class='contentlink'>
Question One?
</a>
</li>
<li>
<a href='#q2' class='contentlink'>
Question Two?
</a>
</li>
</ul>
<h3 id='q1'>
This is Question One?
</h3>
<p>
This is the answer to question one.
</p>
<h3 id='q2'>
This is Question Two?
</h3>
<p>
This is the answer to question two.
</p>
不使用jQuery,是否有一种方法可以让我使用某种
:active
CSS设置问题样式,从而使选择问题变成其他颜色?我试着做:<h3 id='q3' class='faq'>This is the question?</h3>
然后在我的样式表中:
h3.faq:active {
color: yellow;
}
但这并没有改变问题的颜色。
最佳答案
您正在寻找的是目标伪类。它定位ID出现在URL中“#”之后的元素。
看看这个小提琴:http://jsfiddle.net/9MXq3/
CSS示例:
h3:target{
background: #ddd;
}
关于css - 在常见问题解答上,如何在用户仅使用CSS单击事件q之后设置其样式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20081955/