Z
Z
zencd2018-02-28 04:39:10
css
zencd, 2018-02-28 04:39:10

Less CSS - How to Stop Writing Responsive Design Rules Twice?

Now in Less CSS I have to write the code twice, which is frustrating:

// правила для малых экранов
div {
  margin: 10px;
}
@media (min-width : 400px) {
  // правила для широких экранов
  div {
    margin: 20px;
  }
}

Question: Is it possible to reduce code duplication like below? It's good if using Less CSS, but not necessarily.
// правило описывается однажды
div {
  margin: @margin;
}
@margin: 10px;
@media (min-width : 400px) {
  @margin: 20px;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Bulba, 2018-02-28
@Xserber

Haven't used Less in a while, but Sass allows you to write like this:

div {
  margin: 10px;

  @media (min-width : 400px) {
    margin: 20px;
  }
}

PS Styles, in my opinion, also allows

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question