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

Guide to displaying a Highcharts graph in a pop-up window?

Looking for guidance on how to open a popup window and display a highcharts graph by clicking on a button in the main window. While I've come across various discussions and examples for opening a larger graph in a popup from an existing graph on the c ...

react-basic-photo-carousel: adjust size and dimensions

As a newcomer to React JS, I decided to use react-simple-image-slider for my image slider component. However, I am facing an issue with making the images responsive on mobile devices. I tried setting the width and height using vw, vh or percentage units, ...

"Preventing scrolling in Safari with CSS overflow:hidden isn't working as expected

Why does overflow: hidden on the body tag not disable scrolling on the page in Safari? It works in Chrome but not in Safari. I'm struggling to find a solution. Can anyone help? ...

Displaying a List of Files Uploaded with Jquery File Upload in an ASP.NET MVC Application

I have successfully installed the NuGet Jquery File Upload Plugin. The uploader functions flawlessly, allowing me to easily drag and drop files for upload to my server. However, there are two issues that are hindering the completion of this project: Aft ...

CSS that creates a repeated background image sourced from an 'image map'

I have created an image map with coordinates and dimensions specified (apologies for the rough drawing...) https://i.sstatic.net/CxQAk.png The numbers represent x-coordinate, y-coordinate, width, and height. For instance, 5, 5, 25, 25 indicates that the ...

Transferring image data to a different webpage

Currently, I am facing an issue with obtaining image data from a camera and photo album on a mobile device. Although I have successfully retrieved the chosen image using the provided code snippet below, my dilemma lies in transferring this image data to an ...

Display the icon beneath the list item label

How can I display the ion-edit icon below the list names? The icons are currently appearing on the right side of each list name, but I want them to be aligned below with some spacing. When clicking on "Data Source Connections," a sublist will be shown whe ...

Jquery with horizontal scroll feature

I am having an issue with my horizontal scroll feature. Despite inspecting in Chrome and finding no errors, I still cannot locate the problem. Can someone please help me identify where the issue lies? <html> <head> <script src="http ...

Resolving Conflicting CSS Styles

It's frustrating to constantly have to ask questions. I've been struggling to implement code on my website, but every time I try to add something new, it just doesn't work. I even tried changing the CSS names, thinking that might solve the i ...

What is the best place in Rails to add @media CSS tags?

Currently, my layout.html.erb contains some CSS rules with @media queries. <style> @media (max-width: 900px) { .green-button{ display: none!important; } .chat_button{ margin-top: 20px!important; } #myCarousel{ ...

Moving the words from textArea to each 'ol' element using JavaScript

When a word is entered in the textarea, it should be assigned to a specific class within an 'ol' tag. Each subsequent word will be placed in the next class sequentially. If there are no more words, the remaining classes should remain empty. <! ...

The image fails to display when using THREE.js and Panolens.js

Trying to create a 360-degree environment with informational buttons using THREE.js and Panolens.JS However, I'm unable to resolve why the image is not appearing. Continuously encountering the error: Uncaught ReferenceError: process is not defined. ...

While HTML and CSS collaborate seamlessly during development, CSS mysteriously disappears when transitioning to production mode

I am brand new to this field and I apologize in advance for any mistakes. Currently, I am working on a node.js project using webpack and HTML loader. To test the project, I am utilizing the dev server dependency to run it locally. All models, views, and te ...

Tips for validating html:options collection in Struts 1.3?

A Treemap is populated with values from a database using the following Java code: Map<String, String> treeMap = new TreeMap<String, String>(map); Iterator mapIterator = mapSet.iterator(); while (mapIterator.hasNext()) { Map.Entry mapEntry = ...

Having issues with $_POST not retrieving values from .post

Below is the javascript snippet that I have written: function submitForm() { var name = document.getElementsByName('name').value ,email = document.getElementsByName('email').value ,subject = document.getElementsBy ...

Colorful radial spinner bar

I am interested in replicating the effect seen in this video: My goal is to create a spinner with text in the center that changes color, and when the color bar reaches 100%, trigger a specific event. I believe using a plugin would make this task simpler, ...

CSS only accordion divs that are all opened by default with no need for jquery

My current setup involves: jsfiddle.net/wromLbq5 I would like to enable the functionality of having multiple accordion sections open simultaneously upon page load. This means that when one section is opened, the others should not close. Is there a way to ...

additional one hour of generated report added >

My Select option code is causing some issues. When I view the uploaded data, there seems to be a duplication and an extra tag at the end: <option value="Running Request |Running > 1 hour">Running Request |Running > 1 hour</option> The ...

Dynamic React animation with sliding elements

When jumping between the second and third "page" of content, I am unable to determine the reason why it is happening. The content is displayed as an absolute position. Check out the sandbox here: https://codesandbox.io/s/nostalgic-bhabha-d1dloy?file=/src ...

Error: The Android Phonegap framework encountered an issue when trying to access the getDuration function without a properly initialized media

Encountering a LogCat error that I need assistance with. The web app code functions properly on iOS, but presents an error message on Android. Unable to call getDuration as mediaplayer is invalid Your help is greatly appreciated. ...