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

1
ember.js - 检测用户是否更改了新的 Ember Data 记录
2
ios - 使用 Xamarin.ios 将布局约束常量从一个值设置为另一个值
3
r - R中的滑动窗口用于不同的窗口大小
1
c - 获取 ELF 二进制文件的加载地址,dlopen 未按预期工作
1
php - php 上传进度不工作,$_SESSION[$key] 为空
2
jquery - 在调用模态之前验证表单
2
svn - SVN 解决合并中的树冲突
1
regex - 将文件夹重定向到子域并保持子域正常工作
2
c# - 搜索列表中对象的所有公共变量对于特定的字符串
2
requirejs - 使用 PhantomJS 运行 RequireJS/WireJS 应用程序

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 知识共享许可协议。