Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply CSS Rules Only If 2 Classes are Set to an Element [duplicate]

Possible Duplicate:
Can you target an element with CSS only if 2 classes are present?
CSS Selector that applies to elements with two classes

Is there a way to apply a CSS style to an element only if 2 classes are applied to it?

For example, apply my custom styles to this:

<div class="one two">Text</div>

But not to these:

<div class="one">Text</div>
<div class="two">Text</div>
like image 875
Dzhuneyt Avatar asked Jul 30 '12 14:07

Dzhuneyt


People also ask

Can an element have 2 CSS classes?

HTML elements can be assigned multiple classes by listing the classes in the class attribute, with a blank space to separate them.

How do I use multiple CSS classes on a single element?

To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element.

When multiple conflicting CSS rules match the same element?

What is Specificity? If there are two or more CSS rules that point to the same element, the selector with the highest specificity value will "win", and its style declaration will be applied to that HTML element.


2 Answers

Sure:

.one.two { border: 1px red solid }
like image 66
Jon Avatar answered Sep 23 '22 01:09

Jon


Try to use in css selector .one.two

like image 38
Danil Speransky Avatar answered Sep 26 '22 01:09

Danil Speransky