How can I create a webpage that is fully responsive to both width and height, with text that automatically scales to fit the

I am currently using Bootstrap and Angular to develop a single-screen webpage tailored for small screens such as the Adafruit 2.2" or 2.8" screen for the Raspberry Pi, or mobile phone displays. I aim to make all content (specifically about 3-4 rows of a table) expand perfectly to fit the screen, without exceeding 100vh or 100vw and without any scrollbars or cutoff text.

Despite my efforts, I am struggling to achieve this. Here is a JSFiddle showcasing what I am attempting to accomplish, albeit without the inclusion of Bootstrap/Angular elements:

CSS:

#statusController {
  background: #333;
  height: 100vh !important;
  min-height: 100vh !important;
  max-height: 100vh !important;
}

td {
  font-size: 100vh;
}

body,
html {
  padding: 0;
  margin: 0;
  color: white;
  height: 100vh !important;
  min-height: 100vh !important;
  max-height: 100vh !important;
}

HTML:

<div id="statusController">
  <table>
    <tr>
      <td>Hello</td>
      <td>World</td>
    </tr>
    <tr>
      <td>Hello</td>
      <td>World</td>
    </tr>
    <tr>
      <td>Hello</td>
      <td>World</td>
    </tr>
    <tr>
      <td>Hello</td>
      <td>World</td>
    </tr>
    <tr>
      <td>Hello</td>
      <td>World</td>
    </tr>
    <tr>
      <td>Hello</td>
      <td>World</td>
    </tr>
  </table>

http://jsfiddle.net/kjt7jLn6/

I have also experimented with jQuery and various Angular plugins like BigText, fitText, textFit, among others, yet faced the same issue - the text expands beyond the page's boundaries, requiring scrolling to view it entirely.

Any suggestions or ideas would be greatly appreciated.

UPDATE: After reviewing similar answers, my question remains distinct as it pertains more to the need for scrolling rather than expanding text. I may need to modify the provided code sample to address the issue of text scaling extending past the bottom when there is sufficient content, which is something I wish to avoid.

Answer №1

It is my belief that the desired styles can be achieved using basic HTML and CSS techniques.

-http://www.w3schools.com/html/html_tables.asp <--- This link provides information on adjusting table width in HTML5 to make it fill the screen.

-Is it possible to dynamically scale text size based on browser width? offers insights on scaling text dynamically based on browser width.

Additionally, a helpful resource for adding divs to tables can be found at https://css-tricks.com/using-divs-inside-tables/

Answer №2

Through the utilization of jQuery and dynamic height calculations, I successfully resolved my specific issue.

http://jsfiddle.net/kjt7jLn6/6/

No longer do I require CSS or alterations to tables. Just a brief snippet of Javascript at the beginning of the page that executes upon page load and resize:

$(window).resize(function () {
  var tcount = $("table tr").length
  var tsize = ($(window).width() / $(window).height() * 2)
  $("table tr").css("height", (100 / tcount) + "vh")
  $("table tr").css("font-size", (100 / tcount / tsize) + "vh")
}).resize()

This script selects all tr elements in the table and stores them as tcount. Each tr's height is then set to 100 / tcount for even distribution across the page.

The variable tsize represents the window's width divided by its height multiplied by 2. The font size is determined by dividing 100 / tcount / tsize.

Thus far, this solution functions quite effectively. It may encounter issues when the window is taller than it is wide, with only one row present, or with rows containing excessive text. These challenges can be addressed by factoring in row height for tsize.

Now, my compact user interface effortlessly adjusts in size and remains easily legible on both my phone (in landscape mode) and on my PiTFT screen (although some adjustments are still needed).

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

Attempting to create a JavaScript class within an HTML document

Having an issue with instantiating a JavaScript class in a separate HTML file. The JavaScript class looks like this: class Puzzle { constructor(fenStart, pgnEnd) { this.fenStart = fenStart; this.pgnEnd = pgnEnd; } } module.exports = Puzzle; ...

Having trouble with string matching in JavaScript?

My attempts to verify my Ajax response with a string have consistently resulted in a fail case being printed. Below is the section of code relating to my ajax request: var username = document.getElementById("name").value; var password = document.getEle ...

"Enhance Your Website with jQuery: Organized Lists with Fixed Length, Connected,

I currently have a list that is separated into three columns, structured as follows: Column1 Column2 Column3 1 4 7 2 5 8 3 6 9 The list ranges from 1 to 9 and each column consists of a fixed number of rows (3). I am lo ...

A sleek CSS text link for a stylish video carousel

I am attempting to create a CSS-only text link to video slider within our Umbraco CMS. Due to the limitations of TinyMCE WYSIWYG, I am restricted in the amount of code I can use as it will strip out most of it. So far, I have developed a basic CSS slider ...

adjust the fixed div's width to match the percentage-defined width of its parent element

My goal is to make a div with the position: fixed property have the same width as its parent element, which is a td. However, I am having trouble achieving this. Here is my current code: HTML: <table style="width: 90%; border: 1px solid black;"> & ...

What steps can be taken to resolve the issue of the <td> element not being allowed as a child of an <a> tag?

https://i.stack.imgur.com/nsdA7.png How can I address these warnings? I utilized the material UI table component and suspect that the warnings are originating from component={Link} to={/patient/${patient.id}} <TableContainer className={styles.tableCo ...

Issues arise with the functionalities of FireFox related to transformations and transitions

I've been working on my CSS and here is what I have: img.buttonImg { -webkit-transition: all 0.5s ease-in-out; -moz-transition: all 0.5s ease-in-out; -o-transition: all 0.5s ease-in-out; -ms-transition: all 0.5s ease-in-out; transition: ...

Tips for validating the input type "password"

Below is the Jquery Script that I am using: $(document).ready(function(){ $("#myForm").validate({ rules: { username: { required:true }, password: { required:true ...

Tips on retrieving an item using jQuery's select2 plugin

How can I retrieve the value (flight_no) from the processResults function in order to populate the airline name with the respective flight number when selected? I've attempted to access the (flight_no) within the processResults function, but I'm ...

Navigate through each element with a specific class name in a block of HTML code using

Currently, I am dealing with an HTML string that is being retrieved through AJAX. Let's assume it looks like this: var htmlString = '<div class="post"></div><div class="post"></div>'; I want to find a way to iterat ...

Is the issue with AJAX and a global variable a result of my misunderstanding?

My goal is to use AJAX to load client data onto a page and then replace a company ID with the corresponding name from a different company table in the same database. However, I am facing an issue where the global JavaScript variable is not being updated wi ...

What is the best way to execute two asynchronous calls sequentially in JavaScript?

When using a common generic function for AJAX calls, the initial request retrieves all data from the server and maintains it within local scope. However, subsequent requests are still hitting the server, even when the data is already available locally. Thi ...

Incorporating fresh visuals into the Fotorama presentation

Currently in search of a reliable jQuery image slider with thumbnail previews for a web application I am developing. Initially interested in Fotorama.js as it meets most of my criteria, but unsure if it supports adding additional images via AJAX after in ...

Guide to building an interactive slider with PHP, MySQL, and jQuery

I had a vision to develop a website with dynamic content, specifically a slider similar to this. Currently, it is hard coded and I am looking to make it dynamic by loading images from a folder in my-sql db. I want to use a php script to update the databa ...

A serene web service that delivers XML data

I'm currently trying to navigate a restful webservice that responds with xml data. I'm fairly new to working with restful web services, so I'm feeling a bit lost on what steps to take next. From what I understand, it seems like the issue lie ...

Tips for circumventing the use of responsive tables in Buefy

I am facing a challenge with displaying data in a Buefy table in a way that it appears as a conventional table with columns arranged horizontally on all devices, rather than the stacked cards layout on mobile. In order to accommodate the content appropriat ...

The issue of an unsuccessful Ajax call arises in a WordPress plugin when utilizing wp_remote_get

Encountering difficulties with the wp_remote_get function in my Wordpress plugin. The objective is to invoke a method within my primary public class using ajax. However, every time I attempt to make the call with the wp_remote_get function, it fails. This ...

HTML5 audio recording

I have been exploring different methods to record audio using HTML5, but so far I have not found a solution. I attempted to utilize this particular example without success. It seems that the statement about lack of support from any browser may be true. ...

Arranging sequence of jQuery functions

I have implemented a loop using jQuery that iterates through specific elements on an HTML page. During each iteration, I switch over a variable and add HTML code to particular locations. The issue arises when one of the appends requires importing another ...

JavaScript code for opening and closing buttons

I created a button that successfully opens, but I am struggling to figure out how to close it. Can someone assist me with this? Additionally, I have one more query: How can I remove the border when the button is clicked? document.getElementById("arrowb ...