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 {
  background-color: lightgray;
.box.green {
  background-color: green;
<div class="box"></div>
<div class="box green"></div>

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


Click here to write/view comments