Why doesn't max-width override min-width?

后端 未结 2 476
粉色の甜心
粉色の甜心 2021-01-01 08:52

I\'m trying to create a responsive layout in which two boxes sit next to each other if the screen size allows it, and have them below each other if it doesn\'t. If the boxes

相关标签:
2条回答
  • 2021-01-01 09:30

    Because of the CSS standards:

    The following algorithm describes how the two properties influence the used value of the 'width' property:

    1. The tentative used width is calculated (without 'min-width' and 'max-width') following the rules under "Calculating widths and margins" above.
    2. If the tentative used width is greater than 'max-width', the rules above are applied again, but this time using the computed value of 'max-width' as the computed value for 'width'.
    3. If the resulting width is smaller than 'min-width', the rules above are applied again, but this time using the value of 'min-width' as the computed value for 'width'.

    As such min-width always 'wins'. Within a specific CSS rule there's no precedence anyway, all values are applied atomically. Precedence only occurs when different rules all apply to the same element, and even then it is based on specificity first before file order is considered.

    0 讨论(0)
  • 2021-01-01 09:44

    I know, I'm late ... But one exact solution could be this:

    p {
        display: inline-block;
        font-size: 15px;
        text-align: left;
        width: 50%;
        border: 1px solid blue;
        min-width: 350px;
    }
    @media (max-width: 700px) {
      p {
        width:100%;
        display:block;
      }
    }
    
    0 讨论(0)
提交回复
热议问题