Can we define min-margin and max-margin, max-padding and min-padding in css?

后端 未结 19 1532
情话喂你
情话喂你 2021-01-31 01:01

Can we define min-margin and max-margin, max-padding and min-padding in CSS ?

19条回答
  •  长情又很酷
    2021-01-31 01:33

    Unfortunately you cannot.
    I tried using the CSS max function in padding to attempt this functionality, but I got a parse error in my css. Below is what I tried:

    padding: 5px max(50vw - 350px, 10vw);
    

    I then tried to separate the operations into variables, and that didn't work either

      --padding: calc(50vw - 350px); 
      --max-padding: max(1vw, var(--padding));
      padding: 5px var(--max-padding);
    

    What eventually worked was just nesting what I wanted padded in a div with class "centered" and using max width and width like so

     .centered {
       width: 98vw;
       max-width: 700px;
       height: 100%;
       margin: 0 auto;
    }
    

    Unfortunately, this appears to be the best way to mimic a "max-padding" and "min-padding". I imagine the technique would be similar for "min-margin" and "max-margin". Hopefully this gets added at some point!

提交回复
热议问题