0

I saw the following code style which is something that is completely new to me:

#nav {
  position: absolute;
  right: 0;
  ul {
    li {
      float: left;
      a {
        display: block;
        color: white;
        text-decoration: none;
        padding: 0 10px;
      }
    }
  }
}

What is the technical name for this and where can I read up on it?

3
  • 5
    That is code from a CSS-preprocessor, like SASS or LESS. Commented Sep 23, 2015 at 20:22
  • 2
    SASS: sass-lang.com and LESS: lesscss.org Commented Sep 23, 2015 at 20:23
  • If you're dealing a lot with CSS, I would really recommend to dig on either SASS or LESS, as they have made web development much much easier. Commented Sep 23, 2015 at 20:29

1 Answer 1

4

That is syntax for a CSS pre-processor. They allow you to use things like variables and selector nesting to create your CSS selectors.

For example a Less file might look like this:

@color: #CCC;

ul {
    background-color: @color;
    li {
        color: red;
        &:hover {
            color: blue;
        }
    }
    .home & {
        background-color: black;
    }
}

Would compile to:

ul {
    background-color: #CCC;
}
ul li {
    color: red;
    }
ul li:hover {
    color: blue;
    }
.home ul {
    background-color: black;
}

The two most popular options:

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

3 Comments

I saw it here codepen.io/JoelSutherland/pen/DzbfE though, no preprocessor is used. How is this possible?
They are using a preprocessor, noticed the middle column is labeled CSS and then in parenthesis it says (LESS).
Ah saw it now. Thanks!

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.