I would like the 3 groups of text:
To be evenly spaced apart over the image.
Not overflow past the image when the page is reduced in width.
Does anyone have any ideas, please?
The image is placed inside a flexbox.
I have tried adding top % to the code, however, when I reduce the page width, the text then overflows the image, as shown.
This is my HTML code:
<!-- mountain background -->
<div class="container">
<div class="item2">
<h2 class="mtn1">A 44-letter alphabet.</h2>
<h2 class="mtn2">
A phonetically <br />
consistent language.
</h2>
<h2 class="mtn3">
A determined teacher <br />
you can count on
</h2>
<img
class="img4"
src="pictures/output-onlinepngtools.png"
alt=""
style="width: 100%"
/>
</div>
<!-- mountain end -->
</div>
This is my CSS code:
/* mountain photo */
.img4 {
height: auto;
width: 100%;
min-height: 400px;
}
.container {
width: 100vw;
position: absolute;
display: flex;
flex-wrap: wrap;
}
.item2 {
width: 100vw;
}
.mtn1 {
float: left;
text-align: left;
position: absolute;
top: 46%;
font-family: "LiberationSansRegular";
font-style: normal;
font-size: 70px;
}
.mtn2 {
float: left;
text-align: left;
position: absolute;
top: 65%;
font-family: "LiberationSansRegular";
font-style: normal;
font-size: 70px;
}
.mtn3 {
float: left;
text-align: left;
position: absolute;
top: 85%;
font-family: "LiberationSansRegular";
font-style: normal;
font-size: 70px;
}
2
Answers
This is a more minimalistic approach, just to show how it works:
Only one class, and two attributes needed.
if you want a specific distance you have two approaches.
You either set a height on the parent, or you set
gap: 25px;
if you want a spacing of 25px. Remember that some elements have margin/paddings, that might interfere, so you will have to either remove those or take them into account.If you want the text to adjust its size, I think you are best off with a media query. This will be in relation to the window however, and not the size of the box/parent.
So you could use percentages… and play around to see if you find a size that fits what you need.
You do not need flex box for this.
You can work it out with
background-image
.