I am struggling to position the text 'About' at the bottom of an image. The red line marks the spot where I want the text aligned at the bottom. However, every method I try results in inconsistent outcomes when viewed on desktop and mobile devices. It currently displays correctly on my laptop, you can view it here (click the image to see the slide.)
This is what the HTML looks like: (hosted on GitHub using liquid tags)
<div class="slide_title">
<span>{{ include.title }}</span>
</div>
<div class="slide_heading clickable">
<img src="{{ include.image }}" width="100%" alt="{{ include.title }}"/>
</div>
The CSS:
.slide .slide_title {
font-size: 4.938em;
color: #f8f8f8;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
pointer-events:none;
position: absolute;
left: 0.000em;
top: 14.188em; /*default when no JavaScript is used, otherwise set in JS*/
}
.slide .slide_title span {
position: absolute;
bottom: -0.24em;
white-space: nowrap;
text-shadow: 0 0 0.05em #999999;
}
The text is within a div, styled with position: absolute
, and positioned alongside my image (so the bottom of the div aligns correctly with the bottom of the image). Now I am trying to accurately position the text within the div.
Everything I have attempted has yielded inconsistent results. While it appears correctly on my desktop, there is a different offset on mobile devices.
Methods I have tried (to the best of my recollection):
- I attempted giving the div a fixed offset in my script for positioning.
- Adjusting the height of the div, which moved the text as desired.
- Placing the text in a span inside the div and adjusting the span by setting its
bottom
property. This is the current method, and is the closest I have come to achieving consistent alignment across all platforms.
I also experimented with setting the vertical-align of the div to bottom, but the text did not shift at all.
Is there a reliable way to align text in this manner that will work universally?
Thank you!
Note: JQuery is being used to position the div.