0

Consider the following html:

<div id="rightBar">
    <div class="barElement">
        <div class="barText"><a href="#">Not underlined</a><br /></div>
        <div class="barLinks"><a href="#">Should be underlined</a></div>
    </div>
</div>

And the following css:

#rightBar a
{
    text-decoration: none;
}
#rightBar a.barLinks
{
    text-decoration: underline;
}

The 'Should be underlined' link is not underlined, shouldn't it be since it inherits both the class barLinks and the id rightbar. Also the '#rightBar a.barLinks' (0, 1, 1, 1) has more specificity than '#rightBar a' (0, 1, 0, 1), so it should override the latter right?

How else can I get the 'Should be underlined' link to be underlined without resorting to using any inline specifications (both css or html)

4

5 に答える 5

7

要素にクラスがありませabarLinks。これを行う:

#rightBar .barLinks a
{
    text-decoration: underline;
}

例: http: //jsfiddle.net/J34mj/2/

于 2011-07-01T15:59:44.193 に答える
2

これは特異性の問題ではありません。間違ったセレクターを使用しています。これである必要があります:

#rightBar .barLinks a {}
于 2011-07-01T15:59:48.673 に答える
1
#rightBar a.barLinks
{
    text-decoration: underline;
}

class = "barLinks"がオンになっていないため、機能しません<a>

これを試して;

#rightBar .barLinks a
{
    text-decoration: underline;
}

またはそれを失敗します。

#rightBar .barLinks a
{
    text-decoration: underline !important;
}
于 2011-07-01T16:02:49.710 に答える
0

そうすべきではありません。barLinksはタグにのみ適用できます。cssを#rightBar.barLinksに変更すると、機能するはずです。

于 2011-07-01T16:00:02.820 に答える
0

したがって、ここで私が見ている問題は、CSSセレクターを使用してアンカータグ要素に到達するための誤ったアドレスについて言及していることです。より長く、より目立つアドレスルートを使用する場合は、次のようになります。

#rightbar .barElement .barLinks a{
    text-decoration : underline;
}

しかし、より具体的なものを探しているので、アンカータグに独自のクラスがないという事実を除いて、アプローチは正しかったので、a.barLinkは何も見つけません。それはむしろ次のようになります:

#rightBar .barLinks a{
text-decoration : underline;
}
于 2019-09-17T18:35:17.803 に答える