EN
CSS - style only elements with multiple classes
3 points
In this article, we would like to show you how to style only those elements that have multiple classes using CSS.
Quick solution:
xxxxxxxxxx
1
.class-1.class-2.class-N { /* <div class="class-1 class-2 class-N"></div> */
2
color: red;
3
}
Where:
class-1
,class-2
, ... ,class-N
are class names assigned to the HTML element at once.
In this example, we present how to style only those elements, that have assigned both class-1
and class-2
to them.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
.class-1.class-2 {
7
background: yellow;
8
}
9
10
</style>
11
</head>
12
<body>
13
<div class="class-1 class-2">Element with "class-1" and "class-2"</div>
14
<div class="class-1">Element with "class-1"</div>
15
<div class="class-2">Element with "class-2"</div>
16
</body>
17
</html>