How to pass parameters to css classes

前端 未结 8 2108
我在风中等你
我在风中等你 2020-12-08 09:57

I want to know is it possible to add some flexibility to css via this:

where .round i

8条回答
  •  死守一世寂寞
    2020-12-08 10:09

    You can't define the border radius separate from its value because it's all one property. There's no way to tell an element to have rounded corners "in general" without also specifying how much to round them by.

    However, you can do something kind of similar with multiple classes and different properties:

    HTML:

    CSS:

    .rounded {
        border-radius: 5px;
    }
    .blue {
        background: blue;
    }
    .green {
        background: green;
    }
    

    The .rounded class adds the border radius and the .blue and .green classes add the background color.

    (I like to name and order the classes such that they read logically, like

    , etc.).

提交回复
热议问题