I'm trying to put some text in the upper left corner of a div that contains an image and the text. I can get it to work using CSS absolute positioning, but the text is not responsive and moves based on the screen size. I need the text to be responsive and adjusts based on the screen size so it stays in the same position relative to the image.
I'm also using bootstrap, which I don't think has an effect but it could be something deep under the covers that I don't know about.
Here is the code I'm currently using:
HTML
<div class="container-fluid">
<div class="col-md-12 d-flex jumbo">
<img class='img-fluid jumbo-image'
src= 'https://i.postimg.cc/8cXs8gZ9/working-horse.jpg' />
<h2 class='jumbo-text'>Jungers Farm</h2>
</div>
CSS
.jumbo {
position: relative;
}
.jumbo-image {
margin-top: 85px;
box-shadow: 15px 15px grey;
}
.jumbo-text {
display: inline-block;
font-size: 3em;
color: #3386ff;
text-shadow: 2px 2px 5px red;
position: absolute; /* remove from document flow */
left: 5%; /* Left */
top: 18%; /* Top */
}
As you can see in the following code pen, the text is not responsive and moves over the image as the screen changes. Thus the reason why my positioning is not a straight left: 0% and top: 0%. But it generally looks like what I want, more or less, when the screen is greater than 768px.
Following is my attempt at using flexbox, but the text is displaying off screen to the right:
Is this even possible with flexbox? If not, is it possible to get the text to be responsive using the straight CSS Absolute positioning method?