We we’re looking at Cloud Gaming Services and found a Hero Banner that looks absolutely stunning. We found it on Boosteroid and have made something inspired by it.
See the Pen
Hero Banner with overlapping PNG by Nico Pahl (@gooloonetwork)
on CodePen.
This comprises of three components. JavaScript to close the Hero Banner, CSS, and HTML.
HTML
Change the Title in the h2 class, it’s the most-outer left text.
<div class="banner">
<div class="banner__content-wrap">
<h2 class="banner__title">Title</h2>
<button class="banner__button">Button</button>
<button class="close-button" aria-label="Close banner">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="banner__image-overlay"></div>
</div>
CSS
In .banner::before, change the URL to an transparent image, that fits the entire Hero Banner. We’ve just used a public domain Image of a Fox from Pixabay.
In .banner__image-overlay change the URL to a transparent avatar, image, or else, that you want to overlap the Hero Banner Section.
.banner {
position: relative;
background: linear-gradient(90deg, #4b6cb7 0%, #182848 100%);
padding: 20px;
overflow: visible;
height: 120px;
}
.banner::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: url('https://cdn.pixabay.com/photo/2022/08/23/11/40/fox-7405603_1280.png');
background-size: cover;
background-position: center;
opacity: 0.2;
z-index: 1;
pointer-events: none;
}
.banner__content-wrap {
position: relative;
display: flex;
align-items: center;
height: 100%;
z-index: 2;
max-width: 1200px;
margin: 0 auto;
padding-right: 40px; /* Add space for the close button */
}
.banner__title {
color: #ffffff;
font-size: 24px;
font-weight: bold;
margin: 0;
margin-right: 20px;
}
.banner__button {
background: none;
border: 2px solid #ffffff;
color: #ffffff;
font-size: 16px;
padding: 8px 16px;
cursor: pointer;
transition: background-color 0.3s ease, color 0.3s ease;
}
.banner__button:hover {
background-color: #ffffff;
color: #4b6cb7;
}
.close-button {
position: absolute;
top: 10px;
right: 10px;
background: none;
border: none;
color: #ffffff;
font-size: 24px;
cursor: pointer;
padding: 5px;
transition: opacity 0.3s ease;
z-index: 3;
}
.banner__image-overlay {
position: absolute;
top: -30px;
left: 50%;
transform: translateX(-50%);
width: 300px;
height: 160px;
background-image: url('https://placehold.co/300x160');
background-size: contain;
background-repeat: no-repeat;
background-position: center;
z-index: 1;
}
.banner.hidden {
opacity: 0;
visibility: hidden;
}
JavaScript
This enables the closing of the Hero Banner.
document.addEventListener('DOMContentLoaded', function() {
const banner = document.querySelector('.banner__content-wrap');
const closeButton = document.querySelector('.close-button');
closeButton.addEventListener('click', function() {
banner.closest('.banner').classList.add('hidden');
// Optional: Remove the banner from the DOM after the transition
setTimeout(() => {
banner.closest('.banner').remove();
}, 300); // Match this to the transition duration in CSS
});
});
Leave a Reply