Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reusing CSS LESS code

Tags:

less

For instance you have the following:

#nav {
position: relative;
background: transparent;
width: 100%;
color: #FFF;

.block {
    padding-top: 2em;
}

ul {
    border: none;
    margin: 0;

    li {
        border: none;
        .inline-block;
        font-size: 1em;
        padding: 0 0.4em;
        text-shadow: 1px 1px 1px #171717;

        a:link, a:visited {
            padding: 0;
            color: #777;
        }

        a:hover {
            color: @hover;
        }

        &.highlight a {
            color: @highlight;
        }

        &:hover {
            background: none;
            border: none;
        }
    }
}

}

If you wanted to use this same code 3 times in a stylesheet, is there a way of saving it as a variable or similar with LESS?

like image 850
ccdavies Avatar asked Aug 29 '26 09:08

ccdavies


1 Answers

Sure, you can use previously defined class and id rulesets as properties for other definitions, like this:

.classname {
    #nav;
    /* further styling here */
}

for more info, see this link: http://lesscss.org/#-mixins

like image 110
Sander Avatar answered Sep 01 '26 04:09

Sander