Stack Overflow
  1. 首页
  2. 工具
  3. 网站转让
  1. 首页
    1. 导航
    2. 问题
    3. 标签
    1. Teams
      Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
    2. Teams
    3. Create free Team
Collectives on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more

javascript - 单击元素时应用新的 CSS 规则

翻译自:https://stackoverflow.com/questions/21653035 2014-02-08T23:21:42.557
64 次
This question shows research effort; it is useful and clear
0
This question does not show any research effort; it is unclear or not useful
Bookmark this question.
Show activity on this post.

我目前正在尝试设计和开发自己的轻量级灯箱。这个想法是当有人点击<a href="#tab1">它时,它会改变<div id="tab1">fromdisplay: none到的属性display: block。一旦灯箱弹出,它将有另一个链接,例如<a href="#tab1_close">将 CSS 属性反转回display: none.

我已经input[name='name'] ~ #id在我的网站上使用了很多其他部分,我想知道是否可以更改它,以便输入将其识别<a>为输入并在点击时应用 CSS 更改。

理想情况下,我可以添加id="tab_1"到<a>, 然后代码将类似于a#tab_1:active ~ #tab1 { display: block }但该代码似乎没有做任何事情。

这是我的代码笔

javascripthtmlcsstransitioncombinators
4

2 回答 2

This answer is useful
1

如果你想要 CSS 只尝试:target选择器:

#tab1:target {
  display: block;
}

http://codepen.io/anon/pen/okEqr

于 2014-02-08T23:30:54.503 回答
This answer is useful
0

jQuery 的 toggleClass() 会满足你的需要:https ://api.jquery.com/toggleClass/

于 2014-02-08T23:26:48.237 回答

Related

3
ios - 防止在 iPad 上意外关闭 U​​IActionSheet
3
html - 嵌套 div 中的 z-index
1
solr - 按非搜索字段加权 Solr 得分
3
linux - 如何确保正在运行的进程是我期望正在运行的进程?
5
php - PEAR 包安装失败
3
mysql - INSERTS 上的 MySQL 事务行为
3
sql - SQL Server - 加入查询
1
crm - 按计划为每个客户生成 Microsoft CRM 4 报告
2
android - 字符串字母消失
3
java - 不使用 doGet/doPost 获取 cookie

Reference

php × 1429865
c/c++ × 756500
nginx × 49975
mongodb × 159057
mybatis × 3233
anaconda × 13410
pycharm × 14671
python × 1902243
vscode × 56040
docker × 110988
github × 49000
flask × 49129
ffmpeg × 24037
jmeter × 16910
matplotlib × 63493
bootstrap × 54641
Stack Overflow 中文网

遵从 CC BY-SA 知识共享许可协议。