Adjusting the font size within a container based on the mobile zoom level

My webpage contains highly visual content rather than text. I bring this up because mobile users typically use pinch-to-zoom to view the complete page or focus on specific details.

<meta name="viewport" content="minimum-scale=0.3, maximum-scale=1.2">

For mobile devices, I have a div placed at the bottom of the page using the following CSS:

.bottom-bar{
    position: absolute; 
    height: 10%;
    bottom: 0; right: 0; left: 0;
}

This ensures that the div always occupies the bottom 10% of the screen, which is where I want to display text that remains visible. However, I encountered an issue - when zooming in, the text becomes too large and when zooming out, it becomes tiny. Therefore, I need a solution to resize the text so that it always fits the height of the container div.

I tried using fitText, but it was not entirely successful as the text often remained too large after zooming in.

Answer №1

If you're curious about how to determine the zoom level of a page in all modern browsers, take a look at this resource. Once you have that information, you can use JavaScript to adjust the font-size property of your text in the opposite direction. For instance, if the zoom level is 1.2, you would divide your default font size by 1.2 to get 13.33px. By setting this value, your text will appear unchanged in size while the background image appears to be enlarged.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering issues with uploading files using ajax

Developing my own custom CMS requires me to enable file and image uploads. Despite attempting to integrate the blueimp uploader, I encountered difficulties. The goal is to transmit formData through a jquery script to interact with my CMS. In PHP code (rec ...

What is the best way to connect an HTML image to effortlessly switch between displaying and hiding an element (specifically, a table) using JavaScript?

Apologies if my question is a bit confusing and poorly written, as I am new to coding and Stack Overflow. What I am trying to achieve is the ability to click on each image and have a different table pop up for each planet with facts (an example of the Merc ...

Upon clicking the button, input numbers into multiple number type inputs

I recently implemented a button in my application that increments the value of input type='number' after it is clicked. While everything seems to be working fine, I noticed that the numbers start from 0 instead of 1. Is there a way for me to ens ...

Using the Loop Function in Node.js with EJS Templates

Seeking help with a node.js application that utilizes bootstrap. I am trying to display the bootstrap cards in rows of 3, with each row containing data from my dataset in columns. However, my current implementation using two for loops is leading to repeate ...

Internet Explorer fails to account for the height of table cells when using overflow-x:auto, leading to hidden content. In contrast, Chrome adjusts for this automatically. What steps can be taken to address

Chrome: https://i.sstatic.net/bzgOT.jpg Internet Explorer: https://i.sstatic.net/qHH1r.jpg The image at the top shows how the content should appear on Chrome, while the one below demonstrates how it is displayed on IE11. The issue seems to be that on In ...

Crafting a bison grammar specifically tailored for WDI: A comprehensive guide

I am seeking assistance with constructing a grammar for bison. Referencing my previous question: I am working on developing a meta-language for writing markup code (such as xml and html) that can be directly integrated into C/C++ code. Here is a basic exa ...

I need to connect data to a textarea element within an ASP.NET MVC view

<div class="col-md-6"> <label>Share Your Business, Accomplishments & Dreams (500 Words Maximum)</label> <textarea name="Description" type="text" placeholder="SHARE YOUR BUSINESS, ACCOMPLIS ...

Positioning a div with text over an image in a way that it

Hey everyone, I've run into a bit of an issue with my project. I'm trying to create a system where text appears over an image, but the problem is that my div is set to absolute position and I can't switch it to relative without causing major ...

jquery: displaying repeated divs on mouse hover - a tutorial

Let's say we have a div like this: <div class="y1"> <img src="i/o.png" /> </div> Also, we have this div for pre-loading: <!-- pre load --> <div class="p1" style="display:none"> <h5 class="ob">Title</h5> < ...

Adjusting the size of menus and text on the screen

A while back, I enlisted the services of a web developer to create my website, but unfortunately, it was never properly optimized for resizing windows. Despite numerous attempts to contact him for fixes over the past 5 months, he claims to be too busy at t ...

Guide to adding dividing lines between columns with bootstrap

https://i.sstatic.net/FHO1v.pngCan someone help me with adding separators between columns in my HTML code? I've tried the code below but it's not working. Is there a way to achieve this? I've attached a screenshot of what I'm expecting. ...

Adding an image to a jQuery class name on the fly

I am attempting to add an image before a div by using its className with jQuery. function insertImage(obj) { var dynamicClass = $(obj).prop("className"); After retrieving the classname, I now encapsulate it in single quotes and add a dot to access t ...

Two separate functions combined into a single onSubmit event

I am currently working on making two functions operate with just one onsubmit function. Here is the code I have created: onsubmit="return validateForm1(); return validateForm2()"> The issue I am encountering is that only the validateForm1() function s ...

Connecting a remote CSS file to a React component: Step-by-step guide

I am currently working on a React component and I want to incorporate Google's MDL (Material Design Lite) into it. I followed the instructions provided on their website here, which state that I need to link the CSS from their server. However, when I a ...

Javascript is experiencing a decrease in the variability of its content

I currently have multiple pages structured like this: <body> <table><tr><td align="center" width="100%"> --PAGE HTML-- </td></tr></table> </body> For a temporary period, I need to change the str ...

Extract the content within the span tags while preserving any line breaks

I have a situation where a span element contains text with line breaks, and there is a function in place to copy this content to the clipboard. My goal is to maintain the line breaks when the data is pasted into another tool or page that supports HTML. C ...

Import JSON data into a Bootstrap data table

I have created an HTML table and now I am looking to populate it with JSON data. I found a helpful example on this YouTube video. Below is my JavaScript code: $(document).ready(function () { $.getJSON("my.php", function(json){ myjson = json; ...

Issues with updating table data when clicking the "Remove Selected" button a second time in Angular 8

Whenever I click the "Remove Selected" button on my table, the selected rows with checkboxes should be deleted. The issue is that it works perfectly fine the first time I click the button, but if I repeat the same steps (click the checkboxes and then click ...

Issue with confirming deletion of tabulated records

HTML Code: <td>random_data_1</td><td><button id="random_data_1"></button></td> <td>random_data_2</td><td><button id="random_data_2"></button></td> <td>random_data_3</td ...

The feature "text-underline-position: under" is not functioning properly in Android Chrome

Take a look at this example page: html, body { margin: 0; padding: 0; } header { padding: 16px 0; text-align: center; background: black; } header img { width: 234px; height: 222px; ...