Do CSS functions exist?

前端 未结 9 1676
我在风中等你
我在风中等你 2021-01-04 11:08

I\'m not sure what to call this, but basically let\'s say I have a style that I use a lot,

.somepattern{
    font-size:16px;
    font-weight:bold;
    borde         


        
9条回答
  •  情歌与酒
    2021-01-04 11:44

    Nope. No CSS functionality like you require. At least not directly.

    But there are at least two rather generic ways for you to use to accomplish what you need:

    Class combining

    You can of course combine as many classes as you like in any element like:

    Some heading
    Lorem ipsum dolor sit amet...

    and you'd have CSS defined as:

    .heading {
        color: #999;
        font-size: 16pt;
        font-weight: bold;
        border-bottom: 2px solid red;
        display: block;
        margin: 1.5em 0 .5em;
    }
    .run-in {
        display: inline;
        margin: 0;
        font-size: 1em;
    }
    

    LESS CSS

    And there is of course LESS CSS project that lets you define variables (and has other sugars as well) and use them in other classes.

    LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions. LESS runs on both the client-side (IE 6+, Webkit, Firefox) and server-side, with Node.js.

    If your server platform is .net there's a project DotLessCSS with a library in .net as well. And there's also T4 template by Phil Haack.

    Mind that there are many CSS preprocessors/enhancers like LESS CSS as well:

    • SASS
    • xCSS
    • HSS
    • CleverCSS

    And probably some others that I didn't mention. Some support nesting CSS3 selectors as well others don't. Some are aimed at particular server-side technology some don't. So choose wisely.

提交回复
热议问题