Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 2109

General Questions/New to Joomla! 4.x • Re: Text over image in JCE

$
0
0
To ensure that the text resizes dynamically with the image as the window size changes, you will need to use responsive CSS. This involves setting the font size using viewport units, which scale based on the size of the viewport (the visible area of the web page).

Here's how you can adjust the CSS in your HTML snippet to make the text resize with the image:

Adjusted HTML and CSS

-------------------------
<div style="position: relative; text-align: center;">
<img src="your-image-url.jpg" alt="Descriptive Text for Image" style="width: 100%;">
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; font-size: 3vw;">
Your Title Here
</div>
</div>
------------------------

Explanation

- Font Size (`font-size: 3vw`): The font size is set using viewport width units (`vw`). `1vw` is equal to 1% of the width of the viewport. This setting will make the font size adjust based on the width of the screen. For example, `3vw` will make the font size 3% of the viewport width. You can adjust this value to get the desired text size at different screen sizes.

- Image Scaling (`width: 100%`): The image is set to scale to 100% of the width of its container. As the window resizes, the image will scale accordingly, and so will the text because its size is based on the viewport width.

- Test on Various Devices: Preview your page on different devices and screen sizes to ensure the text scales properly with the image. Adjust the `vw` unit as necessary to optimize readability across devices.
- Min and Max Font Size**: Sometimes using `vw` alone can make the text too small on very narrow screens or too large on very wide screens. To handle this, you can use CSS clamps or media queries to set minimum and maximum font sizes:

font-size: clamp(12px, 3vw, 24px);

This example sets the minimum font size to 12 pixels, the preferred size to 3% of the viewport width, and the maximum size to 24 pixels.

Best,
Jan

Statistics: Posted by cms-4all — Mon Apr 22, 2024 4:36 pm



Viewing all articles
Browse latest Browse all 2109

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>