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

后端 未结 19 1723
情话喂你
情话喂你 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:43

    I ran across this looking for a way to do a max-margin for responsive design. I need a 5% margin for mobile/tablet devices up to 48 pixels wide. Berd gave me the answer by using media queries.

    My answer: 48 * 2 = 96 total max margin 96 is 10% of total width. 10 * 96 = (960) 100% of vw where 48px is the first time I want it to overwrite the % .

    So my media queries to control my margins become:

    @media (max-width: 959px) {
        .content {
            margin: 30px 5% 48px;
        }
    }
    @media (min-width: 960px) {
        .content {
            display:block;
            margin: 30px 48px 48px;
        }
    }
    

提交回复
热议问题