<div class="container">
<label class="label">Label</label>
<span class="span1">This is span 1</span>
<span class="span2">This is a</span>
</div>
CSS
.container {
display: grid;
grid-template-columns: auto auto auto; /* Each item takes its own space */
gap: 10px; /* Space between items */
align-items: center; /* Vertically align items */
}
.label {
background-color: lightblue;
transition: all 0.3s ease;
}
.span1,
.span2 {
white-space: nowrap; /* Prevent spans from breaking internally */
}
@media (max-width: 500px) {
/* Adjust to the point where spans would wrap */
.container {
grid-template-columns: 1fr 1fr; /* Forces spans to wrap */
}
.label {
grid-column: 1 / -1; /* Make the label span the entire row */
width: 100%; /* Full width of the container */
}
.span1,
.span2 {
justify-self: start; /* Keep the spans at their natural width */
}
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.