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
linux - 如何使用 Perl 调试器的 *supported* 编辑器?
1
javascript - 如何从另一个 js 文件中使用 setActiveTab
2
google-maps - 从移动设备打开时 gmap3 太小
2
java - 有图层问题的 PrimeFaces 菜单
0
javascript - 任何页面上的 ExecJS::RuntimeError,包括 coffeescript
4
c++ - 返回时指针的值是垃圾
1
regex - 在 Javascript 中匹配 IE7 和 IE8 中不可破坏的空格
3
php - 按发布时间对 PHP 回显输出进行排序
3
asp.net-mvc - Orchard CMS 最近的博客文章小部件备用视图
1
ruby-on-rails - 资产预编译因 twitter-bootstrap-rails gem 而失败

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