Is it possible to make these CSS attribute selectors case-sensitive?

I've got this bit of HTML, adapted from an example on w3schools.com:

<!DOCTYPE html>
<html>
<head>
<title>List Test</title>
<style type="text/css">

ol[type="a"] li
{
   color: red;
}

ol[type="A"] li
{
   color: green;
}

</style>
</head>
<body>

<ol type="a">
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>

<ol type="A">
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>
 
</body>
</html>

Open in new window


Firefox and Chrome render both lists in green, because the type attribute is not case-sensitive in CSS attribute selectors. Is there a way around this, short of adding class names to all my ol elements?

(I ask because we have a less-specific rule on li elements on list-style-type and I'm trying to restore the expected behavior. The obvious solution is to make that less-specific rule more specific, but I'd like to avoid the ton of regression testing that would require.)
LVL 14
CPColinSenior Java ArchitectAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Paul MacDonaldConnect With a Mentor Director, Information SystemsCommented:
Seems to me you could use javascript to do something like this.
0
 
GaryCommented:
CSS is completely case insensitive so the only way around it is to use a unique identifier.
0
 
CPColinSenior Java ArchitectAuthor Commented:
When it comes to ID's, class names, and attributes that refer to ID's, CSS is definitely case-sensitive. I was hoping that a style rule that referred to an attribute that is case-sensitive in HTML5 would join those other case-sensitive parts and be case-sensitive itself.
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
CPColinSenior Java ArchitectAuthor Commented:
Using JavaScript for this feels like an unnecessary layer of complexity when the browsers' default behavior should be sufficient. It sounds like the only real solution is to make our rule on li elements more specific.
0
 
GaryCommented:
But we are not talking about ID and CLASS, your question is about TYPE and it is not case sensitive.
TYPE isn't a default CSS selector like ID and CLASS
Why not just add a class to the elements?
0
 
CPColinSenior Java ArchitectAuthor Commented:
You said, "CSS is completely case insensitive." I was merely correcting that statement and clarifying my question.
0
 
CPColinSenior Java ArchitectAuthor Commented:
My question was "Is there a way to make this case-sensitive?" and the only answer is, "Use JavaScript."

I'm going to keep looking, but that's the correct answer, based on how I phrased my question. Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.