css - How can I reduce this repetition -


i have css can see repeating same thing different categories...how can reduce code?

.dropdown .cars-category{    float: left;    margin-left: 1%;  }   .dropdown .trucks-category{     float: right;     margin-right: 1%; }   .dropdown .trucks-category > li > {     display: block;     clear: both;     line-height: 20px;     color: #546aa4; }  .dropdown .trucks-category > li.last > {     border-bottom-width: 0; }  .dropdown .trucks-category > li > a:hover, .dropdown .trucks-category > li > a:focus,  .dropdown .trucks-category > .active > a, .dropdown .trucks-category > .active > a:hover, .dropdown .trucks-category > .active > a:focus {     color: #546aa4;     text-decoration: none;     background-color: #e7eded;     outline: 0; }   .dropdown .cars-category > li > {     display: block;     clear: both;     line-height: 20px;     color: #546aa4; }  .dropdown .cars-category > li.last > {     border-bottom-width: 0; }  .dropdown .cars-category > li > a:hover, .dropdown .cars-category > li > a:focus,  .dropdown .cars-category > .active > a, .dropdown .cars-category > .active > a:hover, .dropdown .cars-category > .active > a:focus {     color: #546aa4;     text-decoration: none;     background-color: #e7eded;     outline: 0; } 

opt 1 - change html , reduce

using 2 classes instead of hyphenated class going reduce most. instead of class="trucks-category" in html, use class="trucks category" andclass="cars category". also, of last block unnecessary (assuming .active on li element). reduces 7 selectors:

.dropdown .cars.category { /*could eliminate .category if no other .cars under */     float: left;            /*the .dropdown menu, see .trucks example */    margin-left: 1%; }   .dropdown .trucks { /*removed category if not needed differentiate */     float: right;     margin-right: 1%; }   .dropdown .category > li > {     display: block;     clear: both;     line-height: 20px;     color: #546aa4; }  .dropdown .category > li.last > {     border-bottom-width: 0; }  .dropdown .category > .active > a, .dropdown .category > li > a:hover,  .dropdown .category > li > a:focus /* .dropdown .category > .active > a:hover, unneeded */ /* .dropdown .category > .active > a:focus unneeded */ {     color: #546aa4;     text-decoration: none;     background-color: #e7eded;     outline: 0; } 

opt 2 - target same value on class name

like option 1, keeping hyphenated classes. useful if not have other -category classes different css , under .dropdown. if not, works:

.dropdown .cars-category {     float: left;                margin-left: 1%; }   .dropdown .trucks-category {     float: right;     margin-right: 1%; }   .dropdown [class*="-category"] > li > {     display: block;     clear: both;     line-height: 20px;     color: #546aa4; }  .dropdown [class*="-category"] > li.last > {     border-bottom-width: 0; }  .dropdown [class*="-category"] > .active > a, .dropdown [class*="-category"] > li > a:hover,  .dropdown [class*="-category"] > li > a:focus {     color: #546aa4;     text-decoration: none;     background-color: #e7eded;     outline: 0; } 

i put option 1 1 because feel having separate class names more intuitive , more flexible.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -