A
A
Alexander Shapoval2016-03-11 20:35:10
css
Alexander Shapoval, 2016-03-11 20:35:10

How to remove css (less) style overrides? Too many styles are repeated?

There is a less file which has a lot of style defined like:

.btn-default,
.btn-default:hover,
.btn-default:focus,
.btn-default:active,
.btn-default.active,
.btn-default.focus,
.btn-default:active,
.btn-default:focus,
.btn-default:hover,

There is a repetition of .btn-default:hover , .btn-default:active , .btn-default:focus , and there are a lot of such styles. Is there an online service or plugin for Sublimetext/PhpStorm/Brackets to remove these repetitions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2016-03-12
@AppFA

You can run your styles through a minifier such as "clean-css" or "cssnano", it combines repetitive code. Further, if necessary, you can decompress with some kind of "prettify".

A
Andrew, 2016-03-12
@byte916

If you have styles that have repeating rules in their selectors, then there is only one thing (I didn’t find others, but I really looked for) that will clear css from such rules - https://github.com/purifycss/purifycss
At the same time, it will clean from styles that aren't used on the page (it's so smart that it even takes into account js-generated class names)
This applies to styles like

.btn-default:active,
.btn-default.active,
.btn-default.active,
.btn-default.focus,
.btn-default:active{
  color: #FFF;
}

In the case of different styles with one selector, any css minifier will help you (an overview of different minifiers is here -> https://habrahabr.ru/post/181880/)
This applies to such styles, like:
.btn-default:active{
  color: #FFF;
}
.btn-default:active{
  text-align: center;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question