Solved

Stacking css pseudo class selectors and pseudo elements

Posted on 2015-02-22
5
91 Views
Last Modified: 2015-02-26
Hey Experts,
I'm wondering how "stackable" css class selectors and pseudo elements are. For example, I'm trying to have a hover effect on selected text. This fiddle has a simple example: http://jsfiddle.net/3nfj6Ltv/
The desired effect in this case would be the background color of the selected text to be orange and the text color to be green, but then on hover the text color changes to red. However, in my example the text stays red. Is this possible with css alone, or would I have to use Javascript/jQuery? I imagine that event handlers would make this easier.
I've never tried to do anything like this before, but anything for the client, am I right? Haha.
Thanks!
0
Comment
Question by:Mikkel Sandberg
  • 3
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 40625365
I doubt you're going to get consistent results using this. The selection pseudo element was discussed and considered for CSS3, but then dropped, so it's not an official part of CSS anymore. It may work partly in some browsers, and not at all in others. Use at you own risk. Your code, for example, doesn't work at all in FireFox!!

As for generally stacking classes and pseudo elements, they're as stackable as you want them to be.
0
 
LVL 6

Author Comment

by:Mikkel Sandberg
ID: 40626036
So using Javascript may be the way to go in this instance? Or is there some other CSS trickery I can use to accomplish this?
0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 40626112
I'm not aware of any CSS that can do what you're after.

As for JS, I'm sure it can be done. There's probably already code out there, or even a plugin for something like jQuery. You may need to build your own solution.

Not much more I can say really...
0
 
LVL 6

Author Comment

by:Mikkel Sandberg
ID: 40626155
Ok. I'll give it another day to see if anyone else has input. Otherwise, I'll give you all the points and close out this question.
0
 
LVL 6

Author Comment

by:Mikkel Sandberg
ID: 40634005
I meant to do this sooner, but I'm closing this out.
Thanks Chris!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now