Bryan Robinson
Founder, Code Contemporary
Formerly:
VP, Design and Development
UX Strategist
Front-end Developer
https://codecontemporary.com
https://bryanlrobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
- Almost every client EVER
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
<div class="promos">
<div class="left-column column">
<a href="#" class="promo">Promo Space 1</a>
</div>
<div class="right-column column">
<a href="#" class="promo">Promo Space 2</a>
<div class="columns">
<a href="#" class="promo">Promo space 3</a>
<a href="#" class="promo">Promo space 4</a>
</div>
</div>
</div>
@brob - BryanLRobinson.com
.promos {
display: flex;
justify-content: space-between;
}
.column {
width: calc(50vw - .5rem);
display: flex;
flex-direction: column;
}
.columns {
display: flex;
justify-content: space-between;
}
.columns > .promo {
flex: 1;
}
.columns > .promo:first-child {
margin-right: 1rem;
}
.right-column > .promo {
margin-bottom: 1rem;
}
.promo {
display: flex;
justify-content: center;
align-items: center;
min-height: 30vh;
}
.left-column .promo {
height: 100%;
}
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
- Rachel Andrew
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
<div class="promos">
<a href="#" class="promo">Promo Space 1</a>
<a href="#" class="promo">Promo Space 2</a>
<a href="#" class="promo">Promo space 3</a>
<a href="#" class="promo">Promo space 4</a>
</div>
.promos {
display: grid;
grid-template-columns: 2fr 1fr 1fr;
grid-template-rows: minmax(30vh, 1fr) minmax(30vh, 1fr);
grid-gap: 1rem;
}
.promo:first-child {
grid-column: 1 / 2;
grid-row: 1 / 3;
}
.promo:nth-child(2) {
grid-column: 2 / 4;
grid-row: 1 / 2;
}
.promo:nth-child(3) {
grid-column: 2 / 3;
grid-row: 2 / 3;
}
.promo:nth-child(4) {
grid-column: 3 / 4;
grid-row: 2 / 3;
}
@brob - BryanLRobinson.com
.promos {
display: grid;
grid-template-columns: 2fr 1fr 1fr;
grid-template-rows: minmax(30vh, 1fr) minmax(30vh, 1fr);
grid-gap: 1rem;
}
.promo:first-child {
grid-column: 1 / 2;
grid-row: 1 / 3;
}
.promo:nth-child(2) {
grid-column: 2 / 4;
grid-row: 1 / 2;
}
.promo:nth-child(3) {
grid-column: 2 / 3;
grid-row: 2 / 3;
}
.promo:nth-child(4) {
grid-column: 3 / 4;
grid-row: 2 / 3;
}
@brob - BryanLRobinson.com
.promos {
display: grid;
grid-template-columns: 2fr 1fr 1fr;
grid-template-rows: minmax(30vh, 1fr) minmax(30vh, 1fr);
grid-gap: 1rem;
grid-template-areas: "main second second"
"main third fourth";
}
.promo:first-child {
grid-area: main;
}
.promo:nth-child(2) {
grid-area: second;
}
.promo:nth-child(3) {
grid-area: third;
}
.promo:nth-child(4) {
grid-area: fourth;
}
main
second
third
fourth
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
When you define display: grid on an item, it becomes a Grid Container.
When an element is the child of a Grid Container, it is a Grid Item.
@brob - BryanLRobinson.com
Images from the excellent Primer on CSS-Tricks:
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
If you want your layout to fully control where the content is. If you want your content to fully line up with rows and columns.
When you want to place or size content across TWO dimensions. Rows AND Columns.
The minute you start adding widths to flex items, you've probably strayed into Grid territory. ESPECIALLY if you use a calc() method in that width.
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
You still want to use flex for items that you want the intrinsic width of your content to size your layout. Use Flex.
When you want your content to flow around an item. Best case: a photo with text wrapping around it in an article.
When you want to move an item a few pixels from its initial placement. Use position: relative with top/right/bottom/left.
When you want to remove an item from the flow of the page. Use position: absolute.
@brob - BryanLRobinson.com
CSS Layout in 2021
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
https://labs.jensimmons.com
@brob - BryanLRobinson.com
https://jensimmons.com
@brob - BryanLRobinson.com
https://redonion.se/cssgrid/
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
as of 6/2/2021
@brob - BryanLRobinson.com
.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
Functional
Navigable
Useful
Quick
Content-equal
@brob - BryanLRobinson.com
CSS Feature Queries
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
.promos {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.promo {
width: calc(50% - .5rem);
min-height: 30vh;
margin-bottom: 1rem;
}
@brob - BryanLRobinson.com
.promos {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.promo {
width: calc(50% - .5rem);
min-height: 30vh;
margin-bottom: 1rem;
}
@supports (display: grid) {
.promo {
width: 100%; // overrides
margin: 0; // overrides
min-height: auto; // overrides
}
.promos {
display: grid;
grid-template-columns: 2fr 1fr 1fr;
grid-template-rows: minmax(30vh, 1fr) minmax(30vh, 1fr);
grid-gap: 1rem;
grid-template-areas: "main second second"
"main third fourth";
}
... etc ...
}
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
<section class="stripe">
<div class="stripe__content">
<h1>Hello Stripe world</h1>
<p>More stripe content can go here ...</p>
</div>
</section>
.stripe {
background-color: lavender;
padding: 2rem 0;
}
.stripe__content {
width: 90vw;
max-width: 1200px;
margin: auto;
}
@brob - BryanLRobinson.com
<section class="stripe">
<h1>Hello Stripe world</h1>
<p>More stripe content can go here ...</p>
</section>
.stripe {
display: grid;
grid-template-columns: minmax(auto, 1200px);
justify-content: center;
background-color: lavender;
padding: 2rem 1rem;
}
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
.card-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
grid-gap: 1rem;
}
@brob - BryanLRobinson.com
@brob - BryanLRobinson.com
@brob
BryanLRobinson.com
CodeContemporary.com
Don't like asking in front of people? Hit me up on Twitter (@brob) or after
@brob - BryanLRobinson.com