Skip to content

Instantly share code, notes, and snippets.

@BillRaymond
Created April 23, 2020 17:02
Show Gist options
  • Save BillRaymond/e62c2a2c189e4f2cbdca87be4b246725 to your computer and use it in GitHub Desktop.
Save BillRaymond/e62c2a2c189e4f2cbdca87be4b246725 to your computer and use it in GitHub Desktop.
Responsive CSS Grid hero image, masthead, banner image
<div class="top-banner-section">
<div class="banner-image-div">
<img class="banner-image" src="https://source.unsplash.com/random" alt="Banner Image" />
</div>
<div class="banner-overlay-div"></div>
<div class="banner-text-div">
<span class="banner-text">
<p class="banner-h1-text">Remain relevant in today's technology-driven economy</p>
<p class="banner-body-text">Learn how agile can give you a competitive edge.</p>
<p class="banner-btn"><a class="banner-btn-item" href="https://www.cambermast.com">Get started &#8594;</a></p>
</span>
</div>
</div>
// Styles for the top banner on the home page
// Create three grid boxes that overelap each other.
// Grid box 1: Image
// Grid box 2: Gradient overlay
// Grid box 3: Call to action text/content
.top-banner-section {
display: grid;
grid-template-columns: 1fr; // stretch to the full frame
grid-template-rows: 350px; // 350 pixels tall
grid-column-gap: 0px;
grid-row-gap: 0px;
align-content: center;
justify-content: center;
.banner-image-div {
grid-area: 1 / 1 / 2 / 2;
} // image
.banner-overlay-div {
grid-area: 1 / 1 / 2 / 2;
} // gradient or other overlay
.banner-text-div {
grid-area: 1 / 1 / 2 / 2;
} // overlay objects like text, buttons, etc.
}
// Banner image (layer 1)
.banner-image {
min-width: 350px; // Do not resize to smaller than this.
width: 100%;
height: 100%;
object-fit: cover; // Using this so the image can be any size and still look halfway decent.
display: block;
}
// gradient overlay going from black to transparent.
// note: search for a gradient overlay generator to make this easier.
.banner-overlay-div {
max-width: 100%;
background: black;
background: linear-gradient(
60deg,
rgba(0, 0, 0, 0.7777485994397759) 30%,
rgba(255, 255, 255, 0) 100%
); // start at black at the bottom left'ish and goes at a 60% angle. This will make the white easy to read with nearly any image.
}
// banner text
.banner-text-div {
display: grid;
align-items: center;
margin-left: 15px;
margin-right: 15px;
}
// Typograhy: *** This is all the stuff you change
.banner-h1-text {
// font can get larger, but no smaller than 10 points.
font-size: calc(10pt + 0.15vw);
letter-spacing: 0.05em;
font-weight: bolder;
text-transform: uppercase;
color: white;
}
.banner-body-text {
// font can get larger, but no smaller than 10 points.
font-size: calc(10pt + 0.15vw);
margin-top: 0.5em;
color: white;
text-decoration: none;
&:hover {
color: white;
}
&:visited {
color: white;
}
&:active {
color: white;
}
}
.banner-btn {
margin-top: 1em;
}
.banner-btn-item {
font-size: calc(8pt + 0.15vw); // responsive size, but keep a minimum.
padding-top: calc(0.5em + 0.08vw);
padding-bottom: calc(0.5em + 0.08vw);
padding-left: calc(0.5em + 0.08vw);
padding-right: calc(0.5em + 0.08vw);
color: blue;
background-color: white;
text-align: center;
text-transform: uppercase;
font-weight: bold;
border: 1px solid white;
&:link {
text-decoration: none;
}
&:visited {
text-decoration: none;
}
}
@BillRaymond
Copy link
Author

BillRaymond commented Apr 23, 2020

This is a pure CSS Grid with a banner image, gradient overlay, and content. It layers three grid items on top of each other. In my basic tests, it works in Chrome, Edge, and IE. Requires a SASS pre-processor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment