Specifying multiple max-width values for an element
You could just use:
#element {
width: 90%;
max-width: 800px;
}
This way #element
's width
will always be exactly 90%
of the parent's if that's lower than 800px
or 800px
otherwise.
Alternatively, depending on what you are trying to do, you should use media queries or a wrapping element.
Why unsetting max and min width/height css properties require different values?
The none
value only applies to max-height
/ max-width
. This is because there is no limit on the height / width of the box. Hence, the default value for these properties is none
.
The none
value is not permitted on min-height
/ min-width
because boxes cannot have negative height / width. Hence, the default value for these properties is 0
.
Spec references:
- 10.4 Minimum and maximum widths:
min-width
andmax-width
- 10.7 Minimum and maximum heights:
min-height
andmax-height
How to scale multiple div dynamically using min- and max-width?
You could do this simply with Flexbox. Just add this to your CSS with the following two updated classes
CSS
.pagination-number--demo-multiple-numbers {
width: 100%;
margin: 0 auto;
display: flex;
flex-flow: wrap;
justify-content: center;
}
.pagination-number {
font-size: 0.875rem;
border: 0.0625rem solid #ffffff;
border-radius: 4px;
text-align: center;
flex: 1;
margin: 10px;
}
.pagination-number--demo-multiple-numbers { width: 100%; margin: 0 auto; display: flex; flex-flow: wrap; justify-content: center;}.pagination-number { font-size: 0.875rem; border: 0.0625rem solid #ffffff; border-radius: 4px; text-align: center; flex: 1; margin: 10px;}.pagination-number--smaller { height: 2.25rem; line-height: 2.125rem;}.pagination-number--narrow-to-wide { min-width: 2rem; max-width: 2.75rem; width: 100%;}.pagination-number--active { font-weight: 700; background-color: #eeeeee;}
<div class="pagination-number--demo-multiple-numbers"> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div> <div class="pagination-number pagination-number--smaller pagination-number--narrow-to-wide pagination-number--active "> 42 </div></div>
In CSS, does min-height always have priority over max-height in all browsers?
Yes min-height
is always the winner according to the specification:
The following algorithm describes how the two properties influence the used value of the 'height' property:
- The tentative used height is calculated (without 'min-height' and 'max-height') following the rules under "Calculating heights and margins" above.
- If this tentative height is greater than 'max-height', the rules above are applied again, but this time using the value of 'max-height' as the computed value for 'height'.
- If the resulting height is smaller than 'min-height', the rules above are applied again, but this time using the value of 'min-height' as the computed value for 'height'.
As you can see, the min-height
is the last one to be proceeded. We first calculate the height without min/max. Then we introduce max-height
that may change the computed value of height and at the end we do the same with min-height
.
Worth to note that the same happen with min-width
ref
As far as I know, nothing can override min-height/width, even the shrink feature of flexbox cannot make an element shrink past its min-height/width. Related: Why is a flex item limited to parent size?
Also related: min-width and max-width with the same value?
Related Topics
How to Figure Out Proper Min-Width and Max-Width Values for Responsive CSS
Is the Hash Necessary in Svg Font-Face Declarations
How to Set Responsive Image's Max Width (Bootstrap 4)
Pure CSS Drop Down Menu - Unable to Keep Top <Li> Highlighted When Hovering Over Sub-Menu
Override Angular Material CSS Differently in Different Components
Draw a Line That Doesn't Get Thicker When Image Stretches
CSS Solution to Hide Div After X Amount of Seconds
Maintain Perfectly Circular Corners on Variable-Height Element
How to Add Background Colour to Group Layout in Javafx
Django Forms Template Design Classes
Bootstrap 3 Nav-Bar Change Color Cause Showing a White Border or White Line
Box Sizing on Inputs in Firefox Hides Text
Change Only One of Multiple Backgrounds on Hover
Internet Explorer Creates Horizontal Scrollbar for Vertical Scrollbar's Width
Edit Microsoft Chatbot UI Design
Select Element Based on Child Class