2

I want all the anchor links within a <div class="status-outer"> to be white, except for those anchor links that are inside an <li> tag that is inside a <ul class="dropdown-menu"> tag.

Searching around, I came up with the following. Unfortunately, it doesn't work. It seems none of my anchor links are white.

.status-outer a:not(ul.dropdown-menu > li > a) {
    color: #fff;
    text-shadow: none;
}

Can anyone help me find the problem?

Note that I have found other articles about exclusion syntax (that's how I came up with the code above), but I couldn't find any examples that were specific to my needs.

4
  • Then, just give the <li> ones a new classname? Commented Mar 29, 2012 at 19:45
  • @hjpotter92: The problem seems to be that I don't have the correct syntax to exclude those anchor links withing an element with a particular class. So it seems I'd have exactly the same issue taking your suggestion as well. Commented Mar 29, 2012 at 19:47
  • @JonathanWood, can you post your applicable markup in a fiddle so we can play? Commented Mar 29, 2012 at 19:47
  • @James Hill: Thanks, but my actual markup is very complex and Chad's response seems to fit the bill. Commented Mar 29, 2012 at 19:51

4 Answers 4

3
.status-outer a { color: #FFF; }
.status-outer .dropdown-menu li a { color: #000; }
Sign up to request clarification or add additional context in comments.

Comments

1

The negation pseudo-class, :not(X), is a functional notation taking a simple selector

You'll need to do something like this:

.status-outer a { color: white; }
ul.dropdown-menu > li > a { color: inherit; }

Not sure, whether color may be inherit.

Comments

1

Add a second class to those list elements that you don't want to be white, with a CSS "color" rule to overwrite the previous.

Comments

1

The :not() pseudo-element can only take simple selectors, which basically means single things, such as body, #id, .class, or [attribute]. You can't specify an entire selector within it.

You'll have to specify two separate selectors. One that sets the anchor to white, by default, and another that sets it to inherit the color of its parent element, if its contained within a list.

.status-outer a {
    color: #fff;
    text-shadow: none;
}
.status-outer ul.dropdown-menu a {
    color: inherit;
}

The only problem you'll run into is that text-shadow does not have an inherit value, meaning you can't re-add it as its parent's value once you've removed it, you'll have to re-specify it. I don't know if that's 100% applicable here or not.

2 Comments

Thanks. text-shadow is not a problem. However, color: inherit seems to be. This is a dropdown menu (Twitter Bootstrap) that has a different color depending on if that menu item is highlighted. Using color: inherit seems to kill that.
@Jonathan: Ah, another option could be to put the styles that set the color of those links below this reset style, and make sure they're more specific so they just override this style anyways. ul.dropdown-menu li a is more specific than .status-outer a so you shouldn't have problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.