When it comes to designing responsive layouts, I find it useful to have a wrapper that prevents the content from sticking to the side of the screen on mobile.
I do this by simply adding padding to the left and right of the grid.
.wrap { padding-inline: 1rem;}How I wrap
I tend to use this wrapper above my macro layout so I don’t have to think about subtracting this 1rem of padding from the max-width that I like to set for the layout.
<div class="wrap"> <div class="vertical max-w-standard mx-auto"> <!-- Content here --> </div></div>Responsive Wrappers
It might be a personal pet peeve, but I discovered it’s more pleasing to the eye if the inline padding increases at tablet viewports. So there is more breathing room since tablets are larger than phones.
.wrap { padding-inline: 1rem;
@media (width >= 800px) { padding-inline: 2rem; }}Here’s an example of it at work:
Choose to commit to the journey, not to any particular engagement.
Because you’re dancing in the frontier, it’s impossible that all your work will resonate. Great work isn’t popular work; it’s simply work that was worth doing.
— Seth Godin
The Wrap Utility
I make this wrapper so often that I just decided to make a wrap utility that does what you’ve just seen.
@utility wrap { padding-inline: var(--spacing-wrap);}Then I can adjust the inline padding without having to mess around with the padding property itself.
.wrap { --spacing-wrap: 1rem;
@media (width >= 800px) { --spacing-wrap: 2rem; }}As you can see, this is a very simple utility here. So I hope to show you that utilities do not have to be complicated. They can be as simple as this, as long as they are useful to you.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson