0

What method would you use to convert the following css into more dry less code:

nav ul,
nav ol,
ul.reset,
ol.reset {
    list-style: none;
    margin: 0;
    padding: 0;
}

3 Answers 3

2

Absolutely nothing. That CSS/LESS is great and there isn't a nicer/DRYer way to write it in LESS.

Sign up to request clarification or add additional context in comments.

Comments

1

This is the best I could think of:

.resetList() {
    list-style: none;
    margin: 0;
    padding: 0;
}
nav {
    ul, ol {
        .resetList;
    }
}
ul, ol {
    &.reset {
        .resetList;
    }
}

However because of the way mixins work the above would compile to this:

nav ul,
nav ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
ul.reset,
ol.reset {
  list-style: none;
  margin: 0;
  padding: 0;
}

So I would agree with @ascii-lime that pure CSS is probably the better route for something this simple. Hopefully less will provide an alternative in the future.

Comments

0

It won't help much if you want to convert it into LESS. The code will instead become longer by using LESS techniques. It's better to keep it the way it is.

If you still wish to do this, you can try this:

nav {

    list-style: none;
    margin: 0;
    padding: 0;

    ul, ol {

        list-style: none;
        margin: 0;
        padding: 0;

        &.reset {

            list-style: none;
            margin: 0;
            padding: 0;

        }

    }

}

4 Comments

It will work? Thanks for sharing your knowledge, first time I am seeing a css like this...
@SarinJacobSunny Yeah. It will work. You can check out [LESS](lesscss.org). LESS is a stylesheet preprocessor. So you can play around with your stylesheet in a better manner :)
I tried the following code in a html page, butnot working. can you help me to find error <style type="text/css"> table { margin: 0; padding: 0; border:1px double #FF0000; td { background:#3300FF; } } </style>
That won't output the same css. your less requires all .reset classes to be children of a <nav> element to be styled, and your example is nothing close to being dry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.