{"id":3388,"date":"2015-04-14T12:15:48","date_gmt":"2015-04-14T09:15:48","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=3388"},"modified":"2018-01-09T09:16:08","modified_gmt":"2018-01-09T07:16:08","slug":"css-multiple-classes-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/","title":{"rendered":"CSS Multiple Classes Example"},"content":{"rendered":"<p>In this example we are going to have a look at multiple classes<br \/>\nthat you can apply on an element of html.<\/p>\n<p>It has become more and more useful declaring some standard classes in CSS (actually referring to them, even though they do not exist) and using these classes whenever we need in our elements. <\/p>\n<p>It basically is the inverse process of giving an element a class on html and then referring to that element in css to give attributes. In this case, you predefine some classes (that is, give them attributes) and then include them in your elements.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;nAkUl5IbAjqlXSla&#8217;]<\/p>\n<h2>1. Predefine Classes &amp; Attributes in CSS<\/h2>\n<p>In this step, let&#8217;s create different kind of classes and give attributes to them to set up a group of classes that we can later use in html. So, first <strong>create a basic html file<\/strong> with a <code>style<\/code> tag in it where we can add the css, like below:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n\t&lt;title&gt;Multiple Classes on Elements&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n\t&lt;!-- STYLE SECTION --&gt;\r\n\r\n\t&lt;style type=&quot;text\/css&quot;&gt;\r\n\r\n  \t&lt;\/style&gt;\r\n\r\n\t&lt;!-- HTML SECTION --&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<h3>1.1 Alignment Classes<\/h3>\n<p>Creating alignment classes will enable us to easy align elements on the web page. Let&#8217;s name two alignment classes:<\/p>\n<p><code>.pull-left<\/code> &#8211; this will align an element to the left<br \/>\n<code>.pull-right<\/code> &#8211; this will align an element to the right<\/p>\n<p>The respective CSS code for these classes would be:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n&lt;style type=&quot;text\/css&quot;&gt;\r\n\r\n  body{\r\n   font-family: &quot;Arial&quot;, &quot;sans-serif&quot;;  }      \/* just added custom font *\/\r\n\r\n  \/* ALIGNMENT CLASSES *\/\r\n\r\n  .pull-left {                    \/* pull-left class referred and given attributes *\/\r\n    float: left !important;\r\n  }\r\n\r\n  .pull-right {                   \/* pull-right class referred and given attributes *\/\r\n    float: right !important;\r\n  }\r\n\r\n&lt;\/style&gt;\r\n<\/pre>\n<h3>1.2 Color Classes<\/h3>\n<p>Creating color classes will let us color elements\/backgrounds on the web page easier.<\/p>\n<p>Let&#8217;s name four color classes and three background color classes:<\/p>\n<p><code>.red<\/code> &#8211; this will give a text element or the border of a shape the red color.<br \/>\n<code>.green<\/code> &#8211; this will give a text element or the border of a shape the green color.<br \/>\n<code>.blue<\/code> &#8211; this will give a text element or the border of a shape the blue color.<br \/>\n<code>.white<\/code> &#8211; this will give a text element or the border of a shape the white color.<\/p>\n<p><code>.bg-red<\/code> &#8211; this will give an element a red background color.<br \/>\n<code>.bg-green<\/code> &#8211; this will give an element a green background color.<br \/>\n<code>.bg-blue<\/code> &#8211; this will give an element a blue background color.<\/p>\n<p>The respective CSS code for these classes would be:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n  \/* COLOR CLASSES *\/\r\n\r\n  .red, .red li, .red a {               \/* red class referred and given color attribute *\/\r\n    color: #e85139;\r\n  }\r\n\r\n  .green, .green li, .green a {         \/* green class referred and given color attribute *\/\r\n    color: #4ca640;\r\n  }\r\n\r\n  .blue, .blue li, .blue a {            \/* green class referred and given color attribute *\/\r\n    color: #319cd6;\r\n  }\r\n\r\n  .white, .white li, .white a {           \/* green class referred and given color attribute *\/\r\n    color: white;\r\n  }\r\n\r\n  .bg-red     {                  \/* bg-red class referred and given backgrounf color attr *\/\r\n      background-color: #e85139;\r\n    }\r\n\r\n  .bg-green  {                  \/* bg-green class referred and given background color attr *\/\r\n      background-color: #4ca640;\r\n    }\r\n\r\n  .bg-blue   {                  \/* bg-blue class referred and given background color attr *\/\r\n      background-color: #319cd6;\r\n    }\r\n\r\n<\/pre>\n<p>Note that we also added the color attributes for <code>li<\/code> or <code>a<\/code> tags on the html.<\/p>\n<p>That is so we can access li&#8217;s or a&#8217;s directly with these classes.<\/p>\n<h3>1.3 Size Classes<\/h3>\n<p>Creating size classes will let you control the elements sizes on the web page. Let\u2019s name three size classes:<\/p>\n<p><code>.small<\/code> \u2013 this will make an element look small on the screen.<br \/>\n<code>.normal<\/code> \u2013 this will make an element look medium on the screen.<br \/>\n<code>.large<\/code> \u2013 this will make an element look large on the screen.<\/p>\n<p>The respective CSS code for these classes would be:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n   \/* SIZE CLASSES *\/\r\n\r\n   .small {                     \/* small class referred and given sizing attributes *\/\r\n      font-size: 1em;\r\n      padding: 0.2em;\r\n      width: 50%;\r\n      height: 50%;\r\n   }\r\n\r\n   .normal {                    \/* normal class referred and given sizing attributes *\/\r\n      font-size: 1.5em;\r\n      padding: 0.4em;\r\n      width: 100%;\r\n      height: 100%;\r\n   }\r\n\r\n   .large {                     \/* large class referred and given sizing attributes *\/\r\n      font-size: 2em;\r\n      padding: 0.6em;\r\n      width: 150%;\r\n      height: 150%;\r\n   }\r\n<\/pre>\n<h3>1.4 Text Classes<\/h3>\n<p>Creating text classes will make it easier to control text appearance. Let&#8217;s name four text classes:<\/p>\n<p><code>.decor1<\/code> &#8211; this will make the text <code>underline<\/code> and <code>uppercase<\/code>.<br \/>\n<code>.decor2<\/code> &#8211; this will make the text <code>overline<\/code> and <code>lowercase<\/code>.<br \/>\n<code>.decor3<\/code> &#8211; this will make the text <code>line-through<\/code> and <code>capitallize<\/code>.<br \/>\n<code>.center<\/code> &#8211; this will make the text align center.<\/p>\n<p>The respective CSS code for these classes would be:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n   \/* TEXT CLASSES *\/\r\n\r\n   .decor1 {                        \/* decor1 class referred and given text attributes *\/\r\n    text-decoration: underline;\r\n    text-transform: uppercase;\r\n    font-weight: bold;\r\n   }\r\n\r\n   .decor2 {                        \/* decor2 class referred and given text attributes *\/\r\n    text-decoration: overline;\r\n    text-transform: lowercase;\r\n    font-weight: bold;\r\n   }\r\n\r\n   .decor3 {                         \/* decor3 class referred and given text attributes *\/\r\n    text-decoration: line-through;\r\n    text-transform: capitalize;\r\n    font-weight: bold;\r\n   }\r\n\r\n    .center {                       \/* center class referred and given attributes *\/\r\n    position: relative;\r\n    bottom: 0px;\r\n    text-align: center;\r\n   }\r\n<\/pre>\n<h3>1.5 Elements Classes<\/h3>\n<p>It is time to create some specific elements classes, which will represent the initial attributes of the elements we are going to give several classes. Here is what we will create:<\/p>\n<p><code>.button<\/code> &#8211; a very popular element which will be used to demonstrate.<br \/>\n<code>.menu<\/code> &#8211; a four links menu with very little prestyled attributes.<br \/>\n<code>.rectangular<\/code> &#8211; a prestyled fixed width and height element as example.<\/p>\n<p>The respective CSS code for these classes would be:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n   \/* ELEMENTS CLASSES *\/\r\n\r\n   .button {                     \/* refers to a button class, given several attributes *\/\r\n    border: 0.1em solid;\r\n    border-radius: 0.3em;\r\n    width: 5em;\r\n    height: 2em;\r\n    line-height: 2em;\r\n    margin-top: 5em;\r\n    margin-bottom: 2em;\r\n   }\r\n\r\n   .menu li {                   \/* refers to a menu class, given several attributes *\/\r\n    display: inline;\r\n    padding-right: 1em;\r\n    text-decoration: none;\r\n   }\r\n\r\n   .menu {\r\n    margin-bottom: 2em;         \/* just a margin for better view of the elements *\/\r\n   }\r\n\r\n   .rectangular {               \/* refers to a rectangular class, given several attributes *\/\r\n    border: 0.1em solid;\r\n    width: 10em;\r\n    height: 5em;\r\n    line-height: 5em;\r\n    margin-bottom: 2em;\r\n   }\r\n<\/pre>\n<h2>2. Application of Multiple Classes in HTML<\/h2>\n<p>Here is where the magic happens, we will first create the basic elements structure in html <\/p>\n<p>and then continue adding appropriate classes to each elements to see the results of what we;ve done so far!<\/p>\n<h3>2.1 Set up the HTML<\/h3>\n<p>Under your <code>tag<\/code> start the <code>html<\/code> code. Add four elements: a button, a menu, a rectangular and an image like so:<\/p>\n<p>(Do not give these elements classes, we will do that next)<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n  &lt;!-- HTML SECTION --&gt;\r\n\r\n  &lt;!-- button element --&gt;\r\n  &lt;div class=&quot;&quot;&gt;&lt;a href=&quot;#&quot;&gt;Button&lt;\/a&gt;&lt;\/div&gt; \r\n\r\n  &lt;!-- menu element --&gt;\r\n  &lt;div class=&quot;&quot;&gt;\r\n  &lt;ul&gt;\r\n    &lt;li class=&quot;&quot;&gt;&lt;a href=&quot;#&quot;&gt;Home&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;li class=&quot;&quot;&gt;&lt;a href=&quot;#&quot;&gt;About&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;li class=&quot;&quot;&gt;&lt;a href=&quot;#&quot;&gt;Help&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;li class=&quot;&quot;&gt;&lt;a href=&quot;#&quot;&gt;Contact&lt;\/a&gt;&lt;\/li&gt;\r\n  &lt;\/ul&gt;\r\n  &lt;\/div&gt;\r\n\r\n  &lt;!-- rectangular element --&gt;\r\n  &lt;div class=&quot;&quot;&gt;I'm a rectangular&lt;\/div&gt;\r\n\r\n  &lt;!-- image element --&gt;\r\n  &lt;img src=&quot;images\/image.png&quot;&gt;\r\n<\/pre>\n<p>Because none of these elements is styled (or better say, not given a class) the view we would get is this:<\/p>\n<figure id=\"attachment_3445\" aria-describedby=\"caption-attachment-3445\" style=\"width: 597px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-3445\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes1.jpg\" alt=\"Initial View of the Elements in HTML\" width=\"597\" height=\"292\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes1.jpg 597w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes1-300x147.jpg 300w\" sizes=\"(max-width: 597px) 100vw, 597px\" \/><\/a><figcaption id=\"caption-attachment-3445\" class=\"wp-caption-text\">Initial View of the Elements in HTML<\/figcaption><\/figure>\n<p>Now let&#8217;s give them the respective classes like this:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n  &lt;!-- HTML SECTION --&gt;\r\n\r\n  &lt;!-- button element --&gt;\r\n  &lt;div class=&quot;button&quot;&gt;&lt;a href=&quot;#&quot;&gt;Button&lt;\/a&gt;&lt;\/div&gt; \r\n\r\n  &lt;!-- menu element --&gt;\r\n  &lt;div class=&quot;menu&quot;&gt;\r\n  &lt;ul&gt;\r\n    &lt;li class=&quot;&quot;&gt;&lt;a href=&quot;#&quot;&gt;Home&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;li class=&quot;&quot;&gt;&lt;a href=&quot;#&quot;&gt;About&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;li class=&quot;&quot;&gt;&lt;a href=&quot;#&quot;&gt;Help&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;li class=&quot;&quot;&gt;&lt;a href=&quot;#&quot;&gt;Contact&lt;\/a&gt;&lt;\/li&gt;\r\n  &lt;\/ul&gt;\r\n  &lt;\/div&gt;\r\n\r\n  &lt;!-- rectangular element --&gt;\r\n  &lt;div class=&quot;rectangular&quot;&gt;I'm a rectangular&lt;\/div&gt;\r\n\r\n  &lt;!-- image element --&gt;\r\n  &lt;img src=&quot;images\/image.png&quot;&gt;\r\n<\/pre>\n<p>Note that the <code>img<\/code> element doesn&#8217;t still have a class, because we did not create attributes especially for it.<\/p>\n<p>Now lets see what we&#8217;ve got in the browser.<br \/>\n<figure id=\"attachment_3539\" aria-describedby=\"caption-attachment-3539\" style=\"width: 780px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes9.jpg\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes9.jpg\" alt=\"Basic classes applied on elements\" width=\"780\" height=\"420\" class=\"size-full wp-image-3539\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes9.jpg 780w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes9-300x162.jpg 300w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/a><figcaption id=\"caption-attachment-3539\" class=\"wp-caption-text\">Basic classes applied on elements<\/figcaption><\/figure><\/p>\n<p>We&#8217;ve created the most basic version of our final html.<\/p>\n<h3>2.2 Add multiple classes<\/h3>\n<p>Now lets go ahead and add classes that we&#8217;ve already given attributes to in css to make elements look better.<\/p>\n<p>The way you apply multiple classes to an element is just by seperating them with a space inside the quotes like this:<\/p>\n<p><code>class=\"example class1 class2 class3 class4 class5\"<\/code><\/p>\n<p><strong>1. Adding Classes to the Button<\/strong><\/p>\n<p>I will add 4 more classes to our <code>button<\/code> element:<\/p>\n<p><code>center<\/code> &#8211; add this class to make the text align center.<br \/>\n<code>bg-blue<\/code> &#8211; this class will make the button background blue.<br \/>\n<code>white<\/code> &#8211; this will change the color of the text to white.<br \/>\n<code>large<\/code> &#8211; add this class to make the whole element larger.<\/p>\n<p>And this is how the code will look like:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n  &lt;!-- button element --&gt;\r\n  &lt;div class=&quot;button center bg-blue white large&quot;&gt;&lt;a href=&quot;#&quot;&gt;Button&lt;\/a&gt;&lt;\/div&gt;\r\n<\/pre>\n<p>Now look at this nice button view we get:<\/p>\n<figure id=\"attachment_3476\" aria-describedby=\"caption-attachment-3476\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes31.jpg\"><img decoding=\"async\" class=\"size-full wp-image-3476\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes31.jpg\" alt=\"Button Element - Classes Applied\" width=\"800\" height=\"575\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes31.jpg 800w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes31-300x216.jpg 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-3476\" class=\"wp-caption-text\">Button Element &#8211; Classes Applied<\/figcaption><\/figure>\n<p><strong>2. Adding Classes to the Menu<\/strong><\/p>\n<p>Lets add 3 more classes, 2 of them to the <code>menu<\/code> and 1 to the <code>li<\/code>&#8216;s:<\/p>\n<p><code>red<\/code> &#8211; gives the text of this element a red color.<br \/>\n<code>pull-right<\/code> &#8211; alignes the whole element on the right side of the screen.<\/p>\n<p><code>decor1<\/code> &#8211; makes the text in the list underlined, uppercase and bold.<\/p>\n<p>This is how it should be in the code:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n  &lt;!-- menu element --&gt;\r\n  &lt;div class=&quot;menu red pull-right &quot;&gt;\r\n  &lt;ul&gt;\r\n    &lt;li class=&quot;decor1&quot;&gt;&lt;a href=&quot;#&quot;&gt;Home&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;li class=&quot;decor1&quot;&gt;&lt;a href=&quot;#&quot;&gt;About&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;li class=&quot;decor1&quot;&gt;&lt;a href=&quot;#&quot;&gt;Help&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;li class=&quot;decor1&quot;&gt;&lt;a href=&quot;#&quot;&gt;Contact&lt;\/a&gt;&lt;\/li&gt;\r\n  &lt;\/ul&gt;\r\n  &lt;\/div&gt;\r\n<\/pre>\n<p>And the expected view in the browser would be like this:<\/p>\n<figure id=\"attachment_3504\" aria-describedby=\"caption-attachment-3504\" style=\"width: 815px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes6.jpg\"><img decoding=\"async\" class=\"size-full wp-image-3504\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes6.jpg\" alt=\"Menu Element - Classes Applied\" width=\"815\" height=\"434\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes6.jpg 815w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes6-300x160.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes6-620x330.jpg 620w\" sizes=\"(max-width: 815px) 100vw, 815px\" \/><\/a><figcaption id=\"caption-attachment-3504\" class=\"wp-caption-text\">Menu Element &#8211; Classes Applied<\/figcaption><\/figure>\n<p>Note that the <code>decor1<\/code> attributes also define underlined text, but you don&#8217;t see it because of this code I added when dealing with the button element, which had the browser pre-styled any-link underlined attribute:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n  a:-webkit-any-link {\r\n  color: -webkit-link;\r\n  text-decoration: none;\r\n  }\r\n<\/pre>\n<p>It means do not underline any links by default, and that was needed for our button.<\/p>\n<p><strong>3. Adding Classes to the Rectangular<\/strong><\/p>\n<p>For the rectangular element, lets add 5 more classes after the <code>rectangular<\/code> basic class:<\/p>\n<p><code>center<\/code> &#8211; this will center the text inside the rectangular.<br \/>\n<code>bg-green<\/code> &#8211; this will give it a green background color.<br \/>\n<code>white<\/code> &#8211; this will make the text color white<br \/>\n<code>decor3<\/code> &#8211; this decor will make the text <code>line-through<\/code>, <code>capitallize<\/code> and <code>bold<\/code>.<br \/>\n<code>normal<\/code> &#8211; this will adjust the size of the rectangular to what we defined <code>normal<\/code>.<\/p>\n<p>By now you should have learned how to add these classes, it will look like this in the code:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n  &lt;!-- rectangular element --&gt;\r\n  &lt;div class=&quot;rectangular center bg-green white decor3 normal&quot;&gt;I'm a rectangular&lt;\/div&gt;\r\n<\/pre>\n<p>Now notice the rectangular view:<\/p>\n<figure id=\"attachment_3509\" aria-describedby=\"caption-attachment-3509\" style=\"width: 811px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes7.jpg\"><img decoding=\"async\" class=\"size-full wp-image-3509\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes7.jpg\" alt=\"Rectangular Element - Classes Applied\" width=\"811\" height=\"426\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes7.jpg 811w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes7-300x158.jpg 300w\" sizes=\"(max-width: 811px) 100vw, 811px\" \/><\/a><figcaption id=\"caption-attachment-3509\" class=\"wp-caption-text\">Rectangular Element &#8211; Classes Applied<\/figcaption><\/figure>\n<p><strong>4. Adding Classes to the Image<\/strong><\/p>\n<p>There is not too much (from what we&#8217;ve done in css) that we can add to the image element, however lets see these:<\/p>\n<p><code>bg-red<\/code> &#8211; this will give the image (which is png) a red background color.<br \/>\n<code>pull-right<\/code> &#8211; this will align the image on the right like the menu.<\/p>\n<p>In the image element, first add a <code>class<\/code> tag and then add classes inside:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n  &lt;!-- image element --&gt;\r\n  &lt;img class=&quot;bg-red pull-right&quot; src=&quot;images\/image.png&quot;&gt;\r\n  &lt;!-- added a class tag and then classes --&gt;\r\n<\/pre>\n<p>And our final element would look this way:<\/p>\n<figure id=\"attachment_3512\" aria-describedby=\"caption-attachment-3512\" style=\"width: 816px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes8.jpg\"><img decoding=\"async\" class=\"size-full wp-image-3512\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes8.jpg\" alt=\"Image Element - Classes Applied \" width=\"816\" height=\"441\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes8.jpg 816w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/classes8-300x162.jpg 300w\" sizes=\"(max-width: 816px) 100vw, 816px\" \/><\/a><figcaption id=\"caption-attachment-3512\" class=\"wp-caption-text\">Image Element &#8211; Classes Applied<\/figcaption><\/figure>\n<p>You now have the concept of using multiple classes on elements that have been previously styled in css.<\/p>\n<h2>3. Some Considerations<\/h2>\n<p>The mupltiple classes application seems a great method for saving time and creating some standards for yourself, and it is, but there are also certain aspects and considerations you should keep in mind.<\/p>\n<h3>3.1 Do not Overwrite<\/h3>\n<p>Given the element specific classes for various types of look, alignment, color ect you want, do not write other\/extra classes of the same property you have previously used. Depending on the case, it will sometimes apply the first\/second class, or none of them at some cases. The code like below would be logically wrong:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n  &lt;!-- rectangular element --&gt;\r\n  &lt;div class=&quot;rectangular center bg-green bg-white white red blue decor3 decor1 normal&quot;&gt;\r\n<\/pre>\n<p>And guess what, the rectangular is still the same in the browser view, nothing has changed.<\/p>\n<p>So there is no reason to use multiple classes to apply the same property.<\/p>\n<h3>3.2 Avoid Cluttered Code<\/h3>\n<p>You might have noticed that we did not use all of the classes we referred to in html. <\/p>\n<p>For example, we didn&#8217;t use <code>pull-left<\/code> because by default all our elements were aligned on the left, we didn&#8217;t also use the <code>small<\/code> class because it made elements we needed too small, and so on and so forth with come color classes. Knowing that, you are recommended to follow one of the practices below:<\/p>\n<p>1. Do not use classes that you think will never be needed on the elements you are going to use.<br \/>\n2. Use any class you like or think will be needed, and clean up the unused classes when you finish your project.<\/p>\n<p>Done that, you will have a more organised code suited to your needs.<\/p>\n<h3>3.3 Consider using Frameworks<\/h3>\n<p>You might get deep into this and create a set of classes (like, a lot of them) and this would be the approach of a css framework. If you have reached a level of professionalism that you feel you can do that, go ahead.<\/p>\n<p>Otherwise, feel free to use popular and productive frameworks like Bootstrap (<a title=\"Bootstrap\" href=\"http:\/\/getbootstrap.com\/\" target=\"_blank\">http:\/\/getbootstrap.com\/<\/a>) which have thousands of predefined classes you can use to get your project going.<\/p>\n<h2>4. Conclusion<\/h2>\n<p>To conclude, there is a lot you can do using multiple classes on elements, like easier and faster create forms, menus,buttons, tables, align, color elements ect, and there are advantages to using it in your projects, but always remember  to give them names according to the main function they do, so that you won&#8217;t get stuck in long code projects and have it easier to understand what has been used each class for, without having to search in the css code.<\/p>\n<p>Play around with it to see how this works by yourself.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/Multiple-Classes.zip\">Multiple Classes Example<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example we are going to have a look at multiple classes that you can apply on an element of html. It has become more and more useful declaring some standard classes in CSS (actually referring to them, even though they do not exist) and using these classes whenever we need in our elements. &hellip;<\/p>\n","protected":false},"author":75,"featured_media":917,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-3388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CSS Multiple Classes Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this example we are going to have a look at multiple classes that you can apply on an element of html. It has become more and more useful declaring\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CSS Multiple Classes Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this example we are going to have a look at multiple classes that you can apply on an element of html. It has become more and more useful declaring\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/fabiocimo\" \/>\n<meta property=\"article:published_time\" content=\"2015-04-14T09:15:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T07:16:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Fabio Cimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fabiocimo\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fabio Cimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/\"},\"author\":{\"name\":\"Fabio Cimo\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22\"},\"headline\":\"CSS Multiple Classes Example\",\"datePublished\":\"2015-04-14T09:15:48+00:00\",\"dateModified\":\"2018-01-09T07:16:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/\"},\"wordCount\":2578,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\",\"articleSection\":[\"CSS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/\",\"name\":\"CSS Multiple Classes Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\",\"datePublished\":\"2015-04-14T09:15:48+00:00\",\"dateModified\":\"2018-01-09T07:16:08+00:00\",\"description\":\"In this example we are going to have a look at multiple classes that you can apply on an element of html. It has become more and more useful declaring\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/css\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"CSS Multiple Classes Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22\",\"name\":\"Fabio Cimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g\",\"caption\":\"Fabio Cimo\"},\"description\":\"Fabio is a passionate student in web tehnologies including front-end (HTML\/CSS) and web design. He likes exploring as much as possible about the world wide web and how it can be more productive for us all. Currently he studies Computer Engineering, at the same time he works as a freelancer on both web programming and graphic design.\",\"sameAs\":[\"https:\/\/www.facebook.com\/fabiocimo\",\"https:\/\/al.linkedin.com\/in\/fabiocimo\",\"https:\/\/x.com\/fabiocimo\",\"https:\/\/www.youtube.com\/fabiocimo1\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/fabio-cimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CSS Multiple Classes Example - Web Code Geeks - 2026","description":"In this example we are going to have a look at multiple classes that you can apply on an element of html. It has become more and more useful declaring","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/","og_locale":"en_US","og_type":"article","og_title":"CSS Multiple Classes Example - Web Code Geeks - 2026","og_description":"In this example we are going to have a look at multiple classes that you can apply on an element of html. It has become more and more useful declaring","og_url":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/fabiocimo","article_published_time":"2015-04-14T09:15:48+00:00","article_modified_time":"2018-01-09T07:16:08+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","type":"image\/jpeg"}],"author":"Fabio Cimo","twitter_card":"summary_large_image","twitter_creator":"@fabiocimo","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Fabio Cimo","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/"},"author":{"name":"Fabio Cimo","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22"},"headline":"CSS Multiple Classes Example","datePublished":"2015-04-14T09:15:48+00:00","dateModified":"2018-01-09T07:16:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/"},"wordCount":2578,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","articleSection":["CSS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/","url":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/","name":"CSS Multiple Classes Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","datePublished":"2015-04-14T09:15:48+00:00","dateModified":"2018-01-09T07:16:08+00:00","description":"In this example we are going to have a look at multiple classes that you can apply on an element of html. It has become more and more useful declaring","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/css\/css-multiple-classes-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"CSS","item":"https:\/\/www.webcodegeeks.com\/category\/css\/"},{"@type":"ListItem","position":3,"name":"CSS Multiple Classes Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22","name":"Fabio Cimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g","caption":"Fabio Cimo"},"description":"Fabio is a passionate student in web tehnologies including front-end (HTML\/CSS) and web design. He likes exploring as much as possible about the world wide web and how it can be more productive for us all. Currently he studies Computer Engineering, at the same time he works as a freelancer on both web programming and graphic design.","sameAs":["https:\/\/www.facebook.com\/fabiocimo","https:\/\/al.linkedin.com\/in\/fabiocimo","https:\/\/x.com\/fabiocimo","https:\/\/www.youtube.com\/fabiocimo1"],"url":"https:\/\/www.webcodegeeks.com\/author\/fabio-cimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/3388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=3388"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/3388\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/917"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=3388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=3388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=3388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}