Using min() and max() In Divi 5 To Create Intelligent Layouts

by | Apr 18, 2025 | Etcetera | 0 comments

CSS min() and max() are two flexible but underutilized purposes in responsive internet design, and Divi 5 has complete enhance for each because the Advanced Units replace. Whilst we’ve in the past 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 the right way to use those purposes the usage of Divi (Divi 5 is ready for you to use on new web sites, with a advice for migration for current websites coming quickly). The rest you’ll be able to 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 Good judgment

For those who’ve already explored clamp(), you’re midway to mastering min() and max()! For those who be mindful, clamp() makes use of 3 values concurrently (min, most popular, and max), min and max in clamp() is similar idea however with only one/third of the good judgment at a given time.

What Do min() And max() Do?

The min() and max() purposes permit you to set two or extra values, with the smallest (min) or the biggest one (max) being displayed in response to display length.

Visualizing CSS min() and max()

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 Price

Use min() to stop extensive displays from stretching content material excessively. That is superb for layouts that shouldn’t develop too extensive on huge displays however will have to have numerous flexibility to scale downward as display sizes get smaller.

 width: min(100%, 500px); 

On this instance, the component’s width won’t ever exceed 500px however might be 100% whether it is below that 500px mark.

max(): All the time Chooses The Higher Price

Use max() to stop content material from changing into too slim or small, specifically on smaller displays or when the content material wishes a minimal length to stay legible or practical. That is superb for layouts that shouldn’t shrink past a definite level on small displays (a set worth) however can amplify to house greater areas (with a relative worth).

 width: max(80%, 300px); 

On this instance, the component’s width will all the time be the bigger possibility: 80% of its container or 300px. On smaller displays or in tight bins, if 80% calculates to not up to 300px, the component will nonetheless be no less than 300px extensive. On greater displays, the component will amplify to 80% of the container’s width, however by no means shrink underneath 300px. This way is helping be certain that the component remains usable on small displays whilst scaling responsively on greater ones.

See also  Divi Product Highlight: Divi Essential

Why Mix Relative And Mounted Values In min() and max()?

While you first stumble upon min() or max() in CSS, you could surprise why they regularly mix values like a proportion and a pixel. That’s as a result of every unit kind performs a distinct position in responsive design.

For example, min(100px, 200px) will all the time get to the bottom of to 100px. it’s simply choosing the smallest of 2 mounted values. However whilst you combine devices, like min(100%, 500px), you’re telling the browser: “Use whichever is smaller between 100% of the dad or mum’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 dad or mum component, the viewport, or inherited font sizes. Mounted devices like px keep consistent in CSS, making them predictable.

By means of combining mounted and relative values, min() and max() permit you to construct versatile designs that adapt whilst nonetheless imposing length barriers.

How To Use min() And max() With Divi

Now that we’ve coated 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 by way of opening up CSS purposes like min() and max() you’ll be able to do the similar factor however use one much less design box (and output rather less CSS to your web page as smartly).

In Divi, in the event you move to a component (in our case, a Row), the Design tab, after which to Sizing, you’ll to find a few choices for adjusting the width. By means of making the Width 95% and atmosphere the Max Width to 900px, you may have one thing that appears excellent on cell units but in addition provides you with a structure with a large number of unfavourable house at the left and proper for desktop presentations.

Setting Row Using Width and Max-Width in Divi 5

That is like the usage of CSS like this for the Rows:

 .container {
width: 95%;
max-width: 900px;
} 

With Divi 5’s Complicated Devices, you currently have some other, extra consolidated possibility. You’ll be able to enter all you want inside of simplest the width box and reach the similar consequence.

Setting Row Width Using Only Min() in Divi 5

That is like the usage 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 an alternative of atmosphere each a Width and Max Width. Both possibility achieves the similar consequence as demonstrated on this video:

See also  WordPress Logging: What It Is & Why You Will have to Use It

This actual use case isn’t all that thrilling, however it does display the ability of min() and max() and the way it can change older CSS declarations.

When the usage of min() or max() for spacing, sizing, or borders (they are able to be used on extra fields in Divi 5), I strongly counsel that you just set them in both Option Group Presets or Element Presets. This manner, you’ll be able to get constant scaling regardless of the place you employ them.

2. Row Padding And Border Width

Under, I’ve a design that warrants extra inside padding and a bigger border width as display sizes get greater. To house this, I’ve used the max() serve as to set proper/left/best/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 make a selection whichever is larger in no matter scenario it’s being carried out 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 might be is 5px, and the biggest is 1vw).

Here’s what max() on this scenario looks as if in Design >Spacing > Padding at the Row in Divi:

Setting max() on Row Padding in Divi UI
Here’s what max() on this scenario looks as if in Design > Border > Border Width at the Row in Divi:

Setting max() on Border Width in Divi UI

In combination, I am getting the impact of getting much less padding at the inside the row and a thinner border width on smaller displays. However it scales up as display sizes get larger and the vw worth (be mindful, it’s a relative worth) turns into larger than the mounted pixel worth.

This is helping maximize the supply of smaller displays, whilst wider displays can fill the distance extra.

3. Complete Peak Hero Sections

The use of the min() worth on a piece’s peak, you’ll be able to create a hero segment this is no less than a definite peak however in a different way suits 90% of the full-screen peak (and not more) the usage of a easy min() serve as.

 peak: min(800px, 90vh) 

This has the impact of getting a full-height hero segment excluding on greater (taller) displays, which might then display the following segment underneath it. In Divi Sizing settings, this can also be carried out with two other box inputs (width and max-width), however the usage of the min() serve as, we will get the similar impact the usage of just one box within the sizing.

Min Height on Hero Section in Divi 5

It helps to keep the hero segment as the principle factor for many display sizes however doesn’t transform too giant within the few circumstances with taller display resolutions.

4. Font Sizing

The use of min or max for font sizes assist you to reach 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 length prerequisites. Set the pixel/rem worth to the small absolute length you wish to have to make use of and use a relative worth to scale upward.

See also  What Is Web Design? What It Entails & How To Master It

1rem equals the foundation font length (generally 16px except custom designed for your web page kinds); 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 be able to see, at the smallest units, the font length is about to 1rem/16px. At a definite level, the bigger worth turns into 2vw and scales the font length upward, making the font greater as display sizes get larger.

For font sizing, I don’t counsel the usage of min or max however as an alternative clamp(). Min/max simplest provides you with dynamic scaling in just one path, and to get on the subject of 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 ways more uncomplicated to easily use clamp).

Distinction Between min()/max() And clamp()

You’ll be able to perceive clamp() as a mixture of min() and max() with a most popular worth in between. Clamp() takes one worth for the minimal cap, one worth as the utmost cap, and a 3rd worth (within the heart) as the most popular worth 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 might be atmosphere won’t ever be smaller than 16px or greater than 40px. Then again, the velocity it adjustments (in response to display length) is decided by way of the most popular worth within the heart.

Learn my devoted article on using clamp() to look my most popular Fluid Typography generator that creates your clamp() purposes for you.

Check out min() And max() With Divi 5

Min() and max() may no longer get as a lot consideration as clamp() or calc(), however they’re crucial gear for smarter, more practical, and cleaner responsive designs in Divi 5.

Those CSS purposes provide you with distinctive tactics to regulate your web site’s responsiveness. As soon as you recognize 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 fashionable browsers, and Divi makes imposing them easy. Divi 5 is ready to be used on new web sites.

The submit Using min() and max() In Divi 5 To Create Intelligent Layouts seemed first on Elegant Themes Blog.

WordPress Maintenance Plans | WordPress Hosting

read more

0 Comments

Submit a Comment

DON'T LET YOUR WEBSITE GET DESTROYED BY HACKERS!

Get your FREE copy of our Cyber Security for WordPress® whitepaper.

You'll also get exclusive access to discounts that are only found at the bottom of our WP CyberSec whitepaper.

You have Successfully Subscribed!