I’m trying to build a responsive website using Bootstrap, which is totally new to me. I want to make a hero image with a text inside positioned right in the middle. As my background image resizes, my text just stays positioned at the same place and doesn’t adjust to a smaller viewport. So i end up with something like this:
Here is what I’ve attempted:
HTML:
<header class="header-container">
<!-- background img -->
<div class="bg-image d-flex justify-content-center align-items-center">
<div class="text-center">
<h1 class="h1-hero h-font">where great ideas come to life</h1>
<p class="p-hero text-font">Passionate creative studio helping startups grow their
business!
</p>
</div>
</div>
</header>
CSS:
.header-container {
padding: 48px 50px 0px;
max-width: 100%;
}
.bg-image {
background-image: url('../img/hero.png');
background-size: 100%;
height: 100vh;
background-repeat: no-repeat;
}
.h1-hero {
font-size: var(--font-size-h1);
font-weight: 500;
line-height: 106px;
letter-spacing: 4.5px;
text-transform: uppercase;
color: white;
}
.p-hero {
font-family: var(--font-family-text);
font-size: 20px;
color: white;
opacity: 80%;
font-weight: 300;
line-height: 23px;
letter-spacing: 1.3px;
padding-top: 12px;
}
3
Answers
Something you could attempt is adding a flexbox display to your text-center div. This would align the h1 and p tags without having to rely on line-height.
You can also try accounting for smaller viewport sizes using media queries. I added an example of one which changes the font size at a breakpoint of 600px.
I also changed the background size of the image from 100% to cover to better display the size of the background image and the container the text is within.
You can centre the text using a combination of flexbox and relative and absolute positioning:
some modifications made
2.To make the text responsive, use container sizing units, viewport units or clamp. Read more here about Viewport units and about clamp
well done on learning bootstrap.