I wish to adjust the font size as well as resize the table elements simultaneously

Adjusting the height and width of the table should automatically adjust the font size as well.

<!doctype html>
<html lang="en">

    <head>
        <meta charset="utf-8">
        <title>jQuery UI Resizable - Default functionality</title>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes  
    /smoothness/jquery-ui.css">
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
        <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
        <link rel="stylesheet" href="/resources/demos/style.css">
        <style>
            #resizable {
                width: 150px;
                height: 150px;
                padding: 0.5em;
            }
            #resizable h3 {
                text-align: center;
                margin: 0;
            }
        </style>
        <script>
            $(function() {
                $("#resizable").resizable();
            });
        </script>
    </head>

    <body>
        <div class="ui-widget-content">
            <table id="resizable">
                <tr>
                    <th>I want to resize this font-size, directly proportionally while resizing this table</th>
                </tr>
            </table>
        </div>
    </body>

</html>

http://jsfiddle.net/frozentoor/nguk1tfu/1/

Answer №1

Perhaps this method could work for you

http://jsfiddle.net/nguk1tfu/11/

$(function() {
  $( "#resizable" ).resizable();
  initialWidth = $( "#resizable" ).width();
  initialHeight = $( "#resizable" ).height();

  $( "#resizable" ).resize(function(){
       currentWidth = $( "#resizable" ).width();
       currentHeight = $( "#resizable" ).height();
      // This determines the index for font increase or decrease
      ratio = (currentWidth/initialWidth) * (currentHeight/initialHeight); 
   if( ratio >= 1)
   {

      ratio = ratio*2; // Modify as needed
      $( "#resizable" ).css('font-size', 11 + ratio);
   }
   else
   {
       ratio = ratio*2;
      $( "#resizable" ).css('font-size', 11 - ratio);
   }
   });

 });

Answer №2

One way to style text is by using viewport units for font-size, like this:

p{
  font-size: 1vw;
}

Here are some other viewport units you can explore:

1vw = 1% of viewport width
1vh = 1% of viewport height
1vmin = 1vw or 1vh (whichever is smaller)
1vmax = 1vw or 1vh (whichever is larger)

For more information, check out CSS Tricks

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

Determining when props are updated in Vue.js 2 when passing an object as a prop

Let's say there is an array feedsArray, with a sample value like this: this.feedsArray = [ { id: 1, type: 'Comment', value: 'How are you today ?' }, { id: 2, type: 'Meet', name: 'Daily ...

Clicking a button in a custom dialog header using jQuery

I am in the process of developing a jQuery Dialog that covers the entire screen. To create a personalized header for the Dialog, I have set up a custom <div>. Within this <div>, there is a nested <table>. The <table> consists of 1 ...

I have to define a specific identifier in Django so that I can easily incorporate it into Bootstrap later on

I am working on creating a portfolio in Django. I have a section in my HTML code that connects to my jobs list in Django using {% for ... %} in order to display images, summaries, and titles of my projects. However, there is an ID within this div that refe ...

Vuejs is throwing an uncaught promise error due to a SyntaxError because it encountered an unexpected "<" token at the beginning of a JSON object

I am currently attempting to generate a treemap visualization utilizing data sourced from a .json file. My approach involves employing d3 and Vue to assist in the implementation process. However, upon attempting to import my data via the d3.json() method ...

Tips for displaying the HTML content within the autocomplete box

My situation involves a text input and an HTML form where users can submit their name to retrieve information. I am using AJAX to display the usernames dynamically. <div class="hidesearch" id="search" style="width:"400px;"> <inp ...

Error encountered: $(...).dataTable(...).row does not exist as a function

I am currently working with a datatable and I would like to implement a feature where the selected row is removed when clicked on. Below is the code snippet for the datatable: $('.data-table').dataTable({ "aaSorting": [], "oLanguage": {"sSe ...

How to Use jQuery Post Method to Submit a Form Without Redirecting

I am looking to enhance the user experience of my form by preventing it from reloading upon submission. Specifically, I want to trigger the call to index.php when the submit button named "delete-image" is clicked in the scenario outlined below. It's i ...

What methods can be used to send JSON data in the body of an express router.get request?

I am currently working on setting up an express endpoint to fetch data from an API and return the JSON response in the body. We are receiving JSON data from a rest API as an array and my goal is to utilize express router.get to present this formatted JSON ...

Best Practices for Utilizing NPM Modules with TypeScript

I am interested in developing an npm module using TypeScript. Can anyone suggest a best practice guide on how to start? Here are my questions: Node.js does not natively support TypeScript, so what is the recommended way to publish an npm module? Shoul ...

The NodeJs and Express API, integrated with Ejs files, encounters a crash when attempting to retrieve data from the database on the second attempt

I've been assigned the task of developing an API that retrieves data from a database and presents it on the frontend. This is my first time working with APIs, and I've encountered some challenges along the way. The database I'm using is call ...

Making AngularJS 'PUT' requests: The process of submitting only the data in a form

I am facing an issue while updating user data in Angular. When I send a 'PUT' request, the entire user $scope is being sent instead of only the fields visible on the form. To retrieve and update the data, I am using a Factory. Below is my edit f ...

Exploring the world of JMeter: capturing sessions with JavaScript and jQuery

I need to capture a user session in order to conduct a performance test. I have been using the JMeter HTTP(S) Test Script Recorder, but unfortunately it is not recognizing javascript and jquery. The error message I'm receiving is: JQuery is not def ...

Encountering issues while attempting to utilize pdf2json in a TypeScript environment

When attempting to import pdf2json (3.0.1) into my Node project using TypeScript, I encountered the following error: "Could not find a declaration file for module 'pdf2json'." I also tried installing @types/pdf2json for TypeScript but found tha ...

Find the total number of records in fnClick: (datatables.net)

I am struggling with some code where I need to retrieve the total number of records. I posted about it on the datatables.net forum but unfortunately, no one was able to help me... tableTools: { "sSwfPath": window.STATIC_BASE + "scripts/datatable/s ...

Issue with Flask app's template rendering when trying to search for a book

Currently, I am working on a Flask web application that has the functionality for users to search for books and view detailed information about them. However, an obstacle I am encountering is that the form does not get sent to the specified URL. Below is ...

Introducing a pause in the function while rendering objects

After inserting setInterval into the code, it is causing all lasers to be delayed by one second. I am looking to have them fired in this order: - initially fire laser1 and laser2. - then take a 1-second break before firing another set of lasers, a ...

Strategies for retaining additional fields added via JavaScript when the page is refreshed

var newField = document.createElement("lastExp"); newField.innerHTML = 'insert new form field HTML code here'; document.getElementById("lastExp").appendChild(newField); I have a button that adds an additional form field with a simple click. ...

Unusual layout issues arise when combining images and text

Check out this jsFiddle My goal is to display images and text side by side in a horizontal layout. The text sections are using the jQuery Cycle Lite Plugin to cycle through a list of words. However, when you view the provided jsFiddle link, you'll no ...

Delete the "img" and "a" elements from the content within the specified node

Is it possible to only extract text from my HTML content? var sb = new StringBuilder(); doc.LoadHtml(inputHTml); foreach (var node in Doc.DocumentNode.ChildNodes) { if (node.Name == "strong" || node.Name == "#text" || node.Name == "br" || no ...

I plan to add new information to my table only when the user clicks on the submit button. This is what I have accomplished until now

<!DOCTYPE html> <html> <head> <title>Sign up page</title> </head> <body> <form method="get" action="signup_redirect.php"> username: <input type="text" name="username" placeholder=" ...