Automatically adjust the size of input control text based on the screen dimensions

I am facing an issue with resizing the text inside an input control when the window is resized. The problem occurs between the width range of 1032px to 575px, where the text inside the input control does not display completely. However, below 575px width, the textbox expands to the full length of the row and the text is visible. I am looking for a solution to resize the text inside the input control within the width range of 575px to 1032px. I have experimented with using "vw" and "vh" for the input control, but it results in the text size decreasing even below 575px width.

<div class="sidebar">
  <a href="#" onclick="home_trans()"><i data-feather="home"></i> Home</a>
  <a href="#"><i data-feather="plus-circle"></i> New Travel Application</a>
  <a href="#"><i data-feather="archive"></i> History</a>
</div>

<div class="content">
  <main role="main" class="col-lg-12 col-md-12 col-sm-12 ml-sm-auto px-4">
               <div id='loadingmessage' style='display: none'>
                                     <img id="loading-image" src="Images/Loading.gif" alt="Loading..." />
                </div>
  <div class="form-group" style="margin-top: 90px" id="mai">
                <div class="form-group row">
                    <label for="disabledInput" class="col-sm-3 col-form-label" style="text-align: left; font-size: medium">Name:</label>
                    <div class="col-sm-3">
                        <input runat="server" class="form-control" id="emp_name" type="text" placeholder="Emp Name" disabled="disabled" />
                    </div>
                    <label for="disabledInput" class="col-sm-3 col-form-label" style="text-align: left; font-size: medium">Reporting Manager:</label>
                    <div class="col-sm-3">
                        <input runat="server" class="form-control" id="rpg_mgr" type="text" placeholder="Reporting Manager" disabled="disabled" />
                    </div>                    
                    </div>
       <div class="form-group row" style="margin-top: 20px;">
            <label for="disabledInput" class="col-sm-3 col-form-label" style="text-align: left; font-size: medium">Emp ID:</label>
                    <div class="col-sm-3">
                        <input runat="server" class="form-control" id="emp_num" type="text" placeholder="Emp ID" disabled="disabled" />
                    </div>
                    <label for="disabledInput" class="col-sm-3 col-form-label" style="text-align: left; font-size: medium">Location:</label>
                    <div class="col-sm-3">
                        <input runat="server" class="form-control" id="loc" type="text" placeholder="Location" disabled="disabled" />
                    </div>
                </div>
      <div class="form-group row" style="margin-top: 20px;">
                    <label for="disabledInput" class="col-sm-3 col-form-label" style="text-align: left; font-size: medium">Designation:</label>
                    <div class="col-sm-3">
                        <input runat="server" class="form-control" id="desig" type="text" placeholder="Designation" disabled="disabled" />
                    </div>
                </div>

The CSS file for the code above is:

 body {
      margin: 0;
      font-family: "Lato", sans-serif;
      padding-top:55px;
    }
      #loadingmessage {
       width: 100%;
       height: 100%;
       top: 0;
       left: 0;
       position: fixed;
       display: block;
       opacity: 0.7;
       background-color: #fff;
       z-index: 99;
       text-align: center;
    }

                #loading-image {
      position: absolute;
      top: 50%;
      left: 50%;
      z-index: 100;
    }
    .feather {
      width: 16px;
      height: 16px;
      vertical-align: text-bottom;
    }
    .sidebar {
      margin: 0;
      padding: 0;
      width: 150px;
      background-color: #f1f1f1;
      position: fixed;
      height: 100%;
      overflow: auto;
      overflow-x:hidden;
      padding-top: 55px;
    }

    .sidebar a {
      display: block;
      color: black;
      padding: 16px;
      text-decoration: none;
    }

    .sidebar a.active {
      background-color: #4CAF50;
      color: white;
    }

    .sidebar a:hover:not(.active) {
      background-color: #555;
      color: white;
    }

    div.content {
      margin-left: 150px;
      margin-top:80px;
      padding-right:16px;
    }

    @media screen and (max-width: 700px) {
      .sidebar {
        width: 100%;
        height: auto;
        position: relative;
      }
      .sidebar a {float: left;}
      div.content {margin-left: 0;}
      div.content{
          margin-top:unset;
      }
    }

    @media screen and (max-width: 400px) {
      .sidebar a {
        text-align: center;
        float: none;
      }
      div.content{
          margin-top:unset;
      }
    }

Answer №1

To optimize font sizes for different screen sizes, use Media Queries.

/* Define font sizes for .form-control */
.form-control{
  font-size: 16px;
}

/* If screen width is 992px or less, set font-size to 14px */
@media screen and (max-width: 992px) {
  .form-control{
    font-size: 14px;
  }
}

/* Adjust font-size to 12px on screens 600px or less */
@media screen and (max-width: 600px) {
  .form-control{
    font-size: 12px;
  }
}

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

Differences in CSS text padding when rendered in Firefox compared to Chrome and other web

Seeking assistance with a site issue that has been causing frustration. I have spent the entire evening trying to solve it without success. The issue at hand involves modifying tag appearance after each article on my website. The problem arises when viewi ...

Can you please tell me the name of this specific graph? And could you explain how I can recreate it on a

I am fully aware that this information is just a Google search away. However, I am unsure of the specific name of the chart I am seeking. Therefore, I am unable to conduct an effective search for suitable plugins or APIs. Your understanding is greatly appr ...

What is stopping me from sorting the information using a specific identifier in Django?

My filter in view.py is working perfectly, but I'm facing an issue when using common abbreviations in my HTML code, such as {{form.as_p}} or {{form|crispy}}. The data retrieval process requires all fields to be filled in, even though in my forms and m ...

Difficulty implementing clickable dropdown buttons in a React navbar

After some tweaking, I was able to create buttons that trigger dropdown menus which disappear when clicked off. However, a problem arises when any button is clicked - all of the dropdowns appear at once. It appears that setting the state for one button a ...

Tips for updating the minimum value to the current page when the button is pressed on the input range

When I press the next button on the current page, I want to update the value in a certain way. https://i.stack.imgur.com/XEiMa.jpg I have written the following code but it is not working as expected: el.delegate(".nextbtn", "click", f ...

"Discover the proper method of referencing an iframe element from an HTML file using JavaScript

I am currently exploring the world of html and CSS, but now I am interested in delving into JavaScript, a topic I am completely unfamiliar with! My goal is to create a random button that displays a randomly selected embedded video (for example, from a poo ...

Guide on integrating React with Node.js and HTML

I've tried various methods, searched on Google, and checked the official site, but nothing seems to work. The code only functions properly when I include it in the HTML file of node.js like this: <!DOCTYPE html> <html lang="en"& ...

Potential dangers involved in sending HTML content through an AJAX request over a secure HTTPS connection

I am exploring the idea of dynamically loading HTML content, such as updating a Bootstrap modal dialog's contents using AJAX calls instead of refreshing the entire page. However, before I proceed, I want to understand the potential risks involved and ...

Is there a way to create automatic line breaks in this text?

Is there a way to automatically ensure the span spans multiple lines? I am working with HTML and CSS. Below is a modified version of my code, as some parts are in PHP: <div style='border: 1px solid; padding: 10px; margin-top: 5px;'> < ...

Tips on updating the highlighted color of the item currently selected in NavBarDropdown using react-bootstrap

I've been utilizing the react-bootstrap NavDropDown component from this source. Although I initially set it up correctly, I'm struggling to customize the background color of the navdropdow-items when they are in their normal or active (selected) ...

Leveraging the :checked state in CSS to trigger click actions

Is there a way to revert back to the unchecked or normal state when clicking elsewhere in the window, after using the :checked state to define the action for the clicked event? ...

What sets PHP fsockopen apart from WebSockets in HTML5?

Are there differences between server-side and client-side processing? Is it possible to send instant messages using PHP's fsockopen, or am I restricted to using JavaScript for polling on the client side? ...

Is the MDL drawer not reaching the full height of the page?

I am currently utilizing Material Design Lite to incorporate a fixed header and drawer into my Ruby on Rails application. In the following video, you can observe that when I switch to another page, the drawer menu on the left side of the page fails to fill ...

JavaScript application that features an audio player complete with a dynamic progress bar and customizable tags

Looking to create a custom audio player using HTML, CSS, and JS. The player should have basic functionality like a play button and progress bar. However, I want to allow users to add tags on the progress bar of the audio file, similar to how SoundCloud&apo ...

There is a slight gap between the svg element and the path

Here is the size of my path tag (g tag is same size) https://i.sstatic.net/Huk8j.png This is the size of my SVG tag https://i.sstatic.net/VBXQi.png There is a gap between them. These are the inline attributes... <svg preserveAspectRatio="none" cla ...

What causes the variation in size between the next/image and img HTML elements?

Two Images, Different Sizes! https://i.sstatic.net/vpoNG.jpg There seems to be a discrepancy in size between the image rendered by the next/img component and the one displayed using the img element. Interestingly, they both use the same image source and ar ...

Smart method for repositioning multiple elements on the display

Imagine we have multiple divs displayed on a screen: https://i.stack.imgur.com/jCtOj.png ...and our goal is to move them collectively, either to the left: https://i.stack.imgur.com/KBfXC.png ...or to the right: https://i.stack.imgur.com/c1cUw.png An ...

Tips for integrating CSS with Material UI TableContainer

I have utilized Material UI Grid to display data in a chart. However, the appearance of the chart does not match my expectations. Instead of resembling the desired "dense table," it looks different: Actual Look of the Chart Below is the code snippet I ha ...

Struggling with CSS button hover effect: can't get border and background change to work

Hello coding community! I am a beginner in programming and I'm eager to learn. Recently, I came across a stunning button effect on Codepen that caught my attention. You can check it out here. However, when I tried to replicate the code from this exam ...

Opening a dynamically generated HTML file in a separate window in Flutter web

I am facing an issue with the url_launcher package while attempting to open a link using the following code snippet: try { final Uri launchUri = Uri.dataFromString( '<html><body>hello world</body></html>', ...