CSS – style for element having two classes (both)

Sometime we need to define css style for elements having two or multiple clasess (all of them). It can defined by using syntax .class1.class2 (or div.class1.classs2). Note that there is no space between two class names and between element (div) and classname.

Here is the css example which uses two classes to define css style.

<style type="text/css">
.box {
  width:50px;height:50px;
  background-color: lightgray;
}
.box.green {
  background-color: green;
}
</style>
<div class="box"></div>
<div class="box green"></div>
refresh

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments