CSS min() and max() are two flexible but underutilized purposes in responsive internet design, and Divi 5 has complete beef up for each for the reason that Complicated Gadgets replace. Whilst we’ve up to now explored fluid typography with clamp() and dynamic calculations with calc(), min() and max() provide you with even more practical tactics to succeed in responsive design.
On this submit, we’ll display you how one can use those purposes the use of Divi (Divi 5 is in a position so that you can use on new web sites, with a advice for migration for current websites coming quickly). Anything else you’ll do to make use of responsive purposes will cut back your dependence on media queries, CSS is a gorgeous factor!
CSS min() And max(): Smarter Layouts With More practical Common sense
For those who’ve already explored clamp(), you’re midway to mastering min() and max()! For those who consider, clamp() makes use of 3 values concurrently (min, most popular, and max), min and max in clamp() is similar thought however with just one/third of the good judgment at a given time.
What Do min() And max() Do?
The min() and max() purposes mean you can set two or extra values, with the smallest (min) or the biggest one (max) being displayed in response to display screen length.

The “Transition Level” is decided respective to the 2 values you put, so that is just for visualization functions
min(): All the time Chooses The Smaller Worth
Use min() to stop huge monitors from stretching content material excessively. That is ultimate for layouts that shouldn’t develop too huge on massive monitors however must have numerous flexibility to scale downward as display screen sizes get smaller.
width: min(100%, 500px);
On this instance, the component’s width won’t ever exceed 500px however can be 100% whether it is below that 500px mark.
max(): All the time Chooses The Better Worth
Use max() to stop content material from changing into too slim or small, in particular on smaller monitors or when the content material wishes a minimal length to stay legible or purposeful. That is ultimate for layouts that shouldn’t shrink past a definite level on small monitors (a hard and fast price) however can make bigger to deal with higher areas (with a relative price).
width: max(80%, 300px);
On this instance, the component’s width will all the time be the bigger choice: 80% of its container or 300px. On smaller monitors or in tight packing containers, if 80% calculates to lower than 300px, the component will nonetheless be a minimum of 300px huge. On higher monitors, the component will make bigger to 80% of the container’s width, however by no means shrink beneath 300px. This way is helping ensure that the component remains usable on small monitors whilst scaling responsively on higher ones.
Why Mix Relative And Fastened Values In min() and max()?
While you first come upon min() or max() in CSS, you may surprise why they steadily mix values like a share and a pixel. That’s as a result of every unit kind performs a unique position in responsive design.
For example, min(100px, 200px) will all the time unravel to 100px. it’s simply choosing the smallest of 2 fastened values. However whilst you combine devices, like min(100%, 500px), you’re telling the browser: “Use whichever is smaller between 100% of the mum or dad’s width and 500px.” This makes it responsive.
Relative devices like %, vw, and em modify in response to the context — whether or not that’s the mum or dad component, the viewport, or inherited font sizes. Fastened devices like px keep consistent in CSS, making them predictable.
By means of combining fastened and relative values, min() and max() mean you can construct versatile designs that adapt whilst nonetheless implementing length obstacles.
How To Use min() And max() With Divi
Now that we’ve lined the fundamentals of min() and max(), let’s speak about some examples.
1. Responsive Row Widths With Fewer Fields
You’ve all the time been in a position to set a width and a max width on container parts with Divi. However via opening up CSS purposes like min() and max() you’ll do the similar factor however use one much less design box (and output rather less CSS in your web page as smartly).
In Divi, for those who pass to a component (in our case, a Row), the Design tab, after which to Sizing, you’ll in finding a few choices for adjusting the width. By means of making the Width 95% and environment the Max Width to 900px, you could have one thing that appears excellent on cellular units but in addition will give you a structure with a large number of unfavourable area at the left and proper for desktop shows.
That is like the use of CSS like this for the Rows:
.container { width: 95%; max-width: 900px; }
With Divi 5’s Complicated Gadgets, you presently have every other, extra consolidated choice. You’ll enter all you wish to have inside handiest the width box and succeed in the similar end result.
That is like the use of this CSS at the row container:
.container { width: min(95%, 900px); }
It’s one line of CSS as opposed to two strains. Extra importantly, it calls for one much less step and price each and every time you employ min() as a substitute of environment each a Width and Max Width. Both choice achieves the similar end result as demonstrated on this video:
This actual use case isn’t all that thrilling, nevertheless it does display the ability of min() and max() and the way it can exchange older CSS declarations.
When the use of min() or max() for spacing, sizing, or borders (they may be able to be used on extra fields in Divi 5), I strongly suggest that you simply set them in both Possibility Crew Presets or Component Presets. This fashion, you’ll get constant scaling regardless of the place you employ them.
2. Row Padding And Border Width
Underneath, I’ve a design that warrants extra internal padding and a bigger border width as display screen sizes get higher. To deal with this, I’ve used the max() serve as to set proper/left/most sensible/backside border width and padding on a Row. The CSS could be one thing like this:
.container { padding: max(10px, 2vw) max(10px, 2vw) max(10px, 2vw) max(10px, 2vw); border-width: max(5px, 1vw) max(5px, 1vw) max(5px, 1vw) max(5px, 1vw); }
Because of this the max() serve as will select whichever is greater in no matter state of affairs it’s being implemented to. The smallest padding on every aspect is 10px and the biggest is 2vw. In a similar way, for the border width, the smallest it ever can be is 5px, and the biggest is 1vw).
Here’s what max() on this state of affairs looks as if in Design >Spacing > Padding at the Row in Divi:
Here’s what max() on this state of affairs looks as if in Design > Border > Border Width at the Row in Divi:
In combination, I am getting the impact of getting much less padding at the within the row and a thinner border width on smaller monitors. Nevertheless it scales up as display screen sizes get larger and the vw price (consider, it’s a relative price) turns into larger than the fastened pixel price.
This is helping maximize the provision of smaller monitors, whilst wider monitors can fill the gap extra.
3. Complete Top Hero Sections
The usage of the min() price on a bit’s peak, you’ll create a hero phase this is a minimum of a definite peak however differently suits 90% of the full-screen peak (and less) the use of a easy min() serve as.
peak: min(800px, 90vh)
This has the impact of getting a full-height hero phase aside from on higher (taller) monitors, which might then display the following phase beneath it. In Divi Sizing settings, this will also be carried out with two other box inputs (width and max-width), however the use of the min() serve as, we will get the similar impact the use of just one box within the sizing.
It assists in keeping the hero phase as the principle factor for many display screen sizes however doesn’t turn into too large within the few cases with taller display screen resolutions.
4. Font Sizing
The usage of min or max for font sizes assist you to succeed in extra dynamic sizing than static pixel values. For this, you’d wish to use max() to scale up the font length in response to display screen length stipulations. Set the pixel/rem price to the small absolute length you need to make use of and use a relative price to scale upward.
1rem equals the foundation font length (in most cases 16px except custom designed on your website online types); a font length of max(1rem, 2vw) would take the bigger of the 2 values and would by no means be smaller than 16px.
As you’ll see, at the smallest units, the font length is about to 1rem/16px. At a definite level, the bigger price turns into 2vw and scales the font length upward, making the font higher as display screen sizes get larger.
For font sizing, I don’t suggest the use of min or max however as a substitute clamp(). Min/max handiest will give you dynamic scaling in just one path, and to get just about the impact of clamp(), you’d wish to set your min/max font sizing laws at a couple of breakpoints (which is imaginable however a long way more uncomplicated to easily use clamp).
Distinction Between min()/max() And clamp()
You’ll perceive clamp() as a mixture of min() and max() with a most popular price in between. Clamp() takes one price for the minimal cap, one price as the utmost cap, and a 3rd price (within the heart) as the most well liked price that determines the slope of exchange between your min and max.
An instance:
font-size: clamp(16px, 4vw, 40px);
This implies the font length you’re environment won’t ever be smaller than 16px or higher than 40px. On the other hand, the speed it adjustments (in response to display screen length) is decided via the most well liked price within the middle.
Learn my devoted article on the use of clamp() to peer my most popular Fluid Typography generator that creates your clamp() purposes for you.
Check out min() And max() With Divi 5
Min() and max() would possibly now not get as a lot consideration as clamp() or calc(), however they’re very important gear for smarter, more practical, and cleaner responsive designs in Divi 5.
Those CSS purposes provide you with distinctive tactics to keep watch over your website online’s responsiveness. As soon as you know when to make use of min() and max(), you’ll surprise the way you controlled responsive design with out them. They’re absolutely supported throughout trendy browsers, and Divi makes imposing them simple. Divi 5 is in a position for use on new web sites.
The submit The usage of min() and max() In Divi 5 To Create Clever Layouts gave the impression first on Sublime Topics Weblog.
WordPress Web Design