【问题标题】:psuedo a:hover, a:link a:active etc class overiding .class伪 a:hover、a:link a:active 等覆盖 .class 的类
【发布时间】:2012-11-24 18:41:20
【问题描述】:

您好人们在使用 jquery 工具选项卡时遇到问题 [http://jquerytools.org/documentation/tabs/index.html][1]

我已设置所有选项卡,以便它们具有正确的悬停、活动、已访问、链接状态

jQuery 工具将 .current 类应用于当前选定的选项卡。

当我查看 firebug 时,当前选项卡确实具有当前类,但它似乎继续使用伪类而不是我为其定义的当前类。

我的 CSS 代码是: HTML:

<div id="TMSEMenu">


    <ul id="TMSEtabs">
        <ul id="TMSEtabs">
            <li><a href="#Home">Home</a></li>
            <li><a href="#Together">Together</a></li>
            <li><a href="#Make">Make</a></li>
            <li><a href="#Share">Share</a></li>
            <li><a href="#Experience">Experience</a></li>
        </ul>
    </div>

我的 CSS 是:

ul#TMSEtabs {
  cursor: default;
  list-style-type: none;
  margin: 0 0 0 0;
  padding: 0 0 0 0;
  z-index:5000;
}
ul#TMSEtabs ul {
  cursor: default;
  list-style-type: none;
  margin: 0 0 0 0;
  padding: 0 0 0 0;
}
ul#TMSEtabs ul li {
  background-image: none;
  float: none;
}
ul#TMSEtabs li {
  background-image: none;
  float: left;
  padding: 0 0 0 0;
  position: relative;
  white-space: nowrap;
  z-index: 100;
}
ul#TMSEtabs li ul {
  display: none;
  top: 0;
}
ul#TMSEtabs li:hover > ul {
  display: block;
  position: absolute;
}

ul#TMSEtabs li.hover > ul {
  display: block;
  position: absolute;
}

ul#TMSEtabs li.current > ul {
  position: absolute;
}
ul#TMSEtabs > li {
  background-image: none;
}
/* currently selected tabs */
ul#TMSEtabs .current a:link{
    background-color: #FFFFFF;
    color: #FFDD38;
    font-weight: normal;
    text-decoration: none;
    outline-style: none;
}
ul#TMSEtabs a:link {
    background-color: #FFFFFF;
    background-image: none;
    color: #BC1F5D;
    display: block;
    font: normal normal bold 14px Arial, Helvetica, sans-serif;
    height: auto;
    line-height: normal;
    margin: 0 0 0 50px;
    padding: 0px 5px 0px 5px;
    text-align: left;
    text-decoration: none;
    text-transform: uppercase;
    width: auto;
    outline-style: none;
}
ul#TMSEtabs a:visited {
    background-color: #FFFFFF;
    color: #BC1F5D;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-style: normal;
    font-weight: bold;
    line-height: normal;
    text-align: left;
    text-transform: capitalize;
    outline-style: none;
}
ul#TMSEtabs a:hover{
    background-color: #FFFFFF;
    color: #FECC38;
    font: normal normal bold 14px Arial, Helvetica, sans-serif;
    line-height: normal;
    text-align: left;
    text-decoration: none;
    text-transform: uppercase;
    outline-style: none;
}
ul#TMSEtabs a:active{
    background-color: #FFFFFF;
    color: #FECC38;
    font: normal normal bold 14px Arial, Helvetica, sans-serif;
    line-height: normal;
    text-align: left;
    text-decoration: none;
    text-transform: uppercase;
    outline-style: none;
}

我的js是:

// tabs

  $("#TMSEtabs").tabs("#tabPanes > div", {
      event: 'click',
      effect: 'dizzySlide',
      rotate: true,
      current: 'çurrent'
  });
  var w;
  $.tools.tabs.addEffect("dizzySlide", function(i, done) {

        // store original width of a pane into memory
        if (!w) { w = this.getPanes().eq(0).width(); }

        // set current pane's width to zero
        this.getCurrentPane().animate({width: 0},1000, function() { $(this).hide(); });

        // grow opened pane to it's original width
        this.getPanes().eq(i).animate({width: w},1000, function() { 
            $(this).show();
            done.call();
        });

    }); 
  var api = $("#TMSEtabs").data("tabs");
    $('#nextTab').click(function() {
        api.next();
    });
    $('#prevTab').click(function() {
        api.prev();
    });

我的页面可以在这里找到: [JSFiddle][2]

更新:

我已经按照下面的答案进行了更改。

我可以让 .current 类显示的唯一方法是删除 :visited 和 :active 状态

【问题讨论】:

  • 当前的c 有一个小尾巴伸出来,这意味着该类实际上不是current,而是çurrent
  • 这就是导致我在阅读 charlietfl 的回答后所做的更改不起作用的原因,谢谢,我刚刚更换了我的笔记本电脑键盘,因为咖啡溢出,新键盘有一些奇怪的字符,需要一些东西也用过

标签: jquery css jquery-tools


【解决方案1】:

解决这个问题很简单,需要对 CSS 规则排名进行一些研究。您可以在 google 快速搜索中找到大量有关 CSS 排名的研究资源。

不幸的是,a:link 的排名非常高……我讨厌仅仅因为这个原因而使用它。

要覆盖,您需要向选项卡规则添加额外的选择器,例如更改:

.tabsClass a.current{ /* properties*/}/* class made up for example only*/

.tabsClass a.current, .tabsClass a:link.current { /* properties*/}

或者简单地为 .tabsClass a:link.current 添加额外的规则,包括与插件 css 规则匹配的所有属性,并覆盖您想要更改的 a:link 当前属性

使用浏览器控制台检查规则排名会有所帮助,您可以在控制台中编辑规则以提高特异性和排名

编辑:更简单的解决方案是在您的 css 中删除 :link

【讨论】:

  • 感谢您的回答我做了一个搜索是有道理的,还有什么可以代替 :link?我猜 jQuery 可以处理这个问题,但有非 javascript 方式吗?
猜你喜欢
  • 2011-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-30
  • 2010-11-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多