1

I have the following CSS:

#content-button-panel ul li a.folder span {
  cursor: default;
}
#content-button-panel ul li a:not(.folder) span {
  cursor: pointer;
}

and the following HTML:

<a class="title-coffee"><span>Overview</span></a>

How can I make it so the HTML (with class of title-xxxxxxx) has a cursor of default? Note I need this to work with title-coffee or any class starting with title-

3
  • 1
    Why not add a second class to those links and target that instead? Commented Dec 24, 2012 at 16:24
  • So you want a.folder span and a.title-xxxxxxx span to have a default cursor, and everything else to be pointer? Commented Dec 24, 2012 at 16:44
  • @BoltClock - Yes that's correct Commented Dec 25, 2012 at 7:50

4 Answers 4

2

Why would you not just add new CSS classes like this:

.cursor {
    cursor: default;
}
.pointer {
    cursor: pointer;
}

And then you use each class specifically where needed like:

<a class="coffee cursor"><span>Overview</span></a>
<a class="folder pointer"><span>Pointer</span></a>
Sign up to request clarification or add additional context in comments.

Comments

1

You can use one of the many attribute selectors. This one selects all a elements whose class attribute begins with "title-"

 a[class^="title-"]

In your case you'd use it like this:

#content-button-panel ul li a.folder span,
#content-button-panel ul li a[class^="title-"] span {
  cursor: pointer;
}

3 Comments

I like this but can I combine this with not(.folder) In my case it's the other way around from yours. I want the class that starts with title- to be default.
Thanks but in my question what I need is for everything to be default except title- and the links with a class of folder. Sorry if the question is confusing.
No problem. Ok - does this do it? The cursor: pointer rule is applied to only those two. Others are left with cursor: default.
0

Negation with CSS can be done 2 ways 1 way:

input:not(.classA, .classB) /* personally, I've never seen this work */

or

input:not([type="radio"]):not([type="checkbox"])

Typically, I would recommend simply using a 3rd class instead of using :not. But in the case of input elements where some elements look better with the browser's default styling, writing out an inclusive selector to catch every single type I do want to style is considerably longer than writing out a negation selector for the types I don't want, I'll go for the shorter selector.

:not can be chained like any other simple selector or pseudo-class

a[class^="title-"]:not(.folder)

1 Comment

It cannot be done the first way in Selectors level 3; only the second (by chaining multiple negations). You may have either seen its use in jQuery (which implements :not() very differently; see here), or seen it in this article. However, the article is outdated and wrong; it only worked in Firefox 3 due to a bug.
0

Here is what I would do. I would rather use ID's on each object and target them specifically as needed. In cases you are targeting a class, it makes it harder to specify specific items which is why I recommend this method.

CSS:

.defaultCursor {
   cursor: default;
}

HTML:

<a id="ThisItemsID" ><span>Overview</span></a>

JS Code (wherever you need to apply the cursor, as needed):

$("#ThisItemsID").addClass('defaultCursor');

1 Comment

This won't work, cause specificity of your selector is much lower than those in the question.

Your Answer

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