Media query failing to target HTML form element

Is it possible to dynamically adjust the font size of form labels and input fields based on browser width?

I've heard that fonts can't automatically 'scale down' when the browser width decreases, requiring media queries instead. I attempted using a media query at the top of my style tags to set label and input font sizes to 10px at a screen size of 1460px, but it didn't work. The rest of my code functions properly, indicating there might be an issue with how I implemented the media query.

If anyone could provide assistance, it would be greatly appreciated. Here is the relevant code snippet:

@media only screen and (max-width: 1460px) {
  label input {
    font-size: 10px;
  }
}
/*Rest of CSS code here*/
<div class="container">
  <form action="signin.php" method="post">

    <div class="left">
      <div class="row">
        <div class="col-25">
          <label for="fname">First Name</label>
        </div>
        <div class="col-75">
          <input type="text" id="fname" name="firstname" placeholder="* Please complete">
        </div>
      </div>
    </div>;

    // Rest of HTML code here

  </form>
</div>;
// End of code

Answer №1

The CSS selector you're using — label input — is not finding any matching elements in your HTML.

There are no input elements that are children of your label elements.

You may have intended to target both label elements and input elements by using label, input. However, even if you make this change, it still won't work because later on in your code you specify the font size for input with a more specific selector (and in CSS, the most specific selector takes precedence) and handle label in a similar manner (even though it doesn't have a more specific selector, when selectors are equal, the last one declared wins).

Answer №2

Yes, it is possible to adjust font sizes according to the viewport size using a combination of calc() and vw units. By setting a rule like font-size: 3vw and then defining maximum and minimum font sizes, you can achieve scaling based on the viewport size. For more information, you can check out this resource link from Smashing Magazine. The article provides additional insights on the topic.

To take it a step further, consider optimizing font sizes with media queries for enhanced responsiveness.

Enjoy experimenting with this technique! :)

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

The video being shown in Jupyter Notebook is unable to be played

I'm attempting to insert a video stored on my local drive into Jupyter Notebook. The file goes by the name "openaigym.video.6.7524.video000000.mp4" and is located within a folder named "gym-results". Despite using the code below, I am not seeing any ...

Having trouble with IE7 - unable to interact with elements below popup form

<script type="text/javascript">var switchTo5x=true;</script> <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script> <script type="text/javascript">stLight.options({publisher:'b42661f5-2dc5 ...

Ways to fill ng-style with a CSS object

Creating a dynamic form to manipulate CSS properties in real time has been my latest project. I've managed to define the CSS property names and values within an object, but now I'm struggling to style the item elegantly on the page as the user in ...

Retrieve the height of a div element in an AngularJS framework, and assign this value to a corresponding attribute of another element

Is it possible to retrieve the height of an element using AngularJS and assign it to another div's attribute? In my Bootstrap website, I have a fixed sidebar that needs to stop before reaching the footer. To achieve this, I currently have to manually ...

When compiled on a device, Cordova is not utilizing CSS and JS files

I am currently in the process of developing an app using Cordova with an HTML file. However, after building the app, I encountered issues where it is not incorporating CSS and does not seem to be utilizing JavaScript. <!doctype html> <html la ...

What is the reason behind the Placeholder not functioning in IE8?

Whenever I trigger the onblur event on an input of type "password", it will hide both the placeholder text and the input itself. Check out the GitHub link for this plugin ...

Guide for making an accordion with a close button that is specific to multiple dynamic IDs

I am looking to create an accordion feature. The idea is that when the user clicks on "Show," the text "Show" should be hidden, and the content along with a "Close" button should be displayed. Then, when the user clicks on "Close," the content and "Close" ...

Keep moving the box back and forth by pressing the left and right buttons continuously

Looking to continuously move the .popup class left and right by clicking buttons for left and right movement. Here is the js fiddle link for reference. This is the HTML code structure: <button class="right">Right</button> <button class="l ...

Can a Chrome App access a user's files on their hard drive with proper permissions?

I'm currently working on a Chrome Packaged App that includes video playback functionality. My main goal is to enable users to stream online media (such as MP4 videos) while also giving them the option to save the video to a location of their choice. ...

Attempting to create a lineup of bricks with varying widths that are directly related to the overall width of the canvas

I'm attempting to create a row of randomly sized bricks on a canvas. The bricks should have varying lengths, but must stay within the confines of the canvas. The canvas has a length of 400, and I want there to be a 10px padding on each side between ...

Steps for displaying an HTML table in Excel by clicking on a button

My goal is to open an HTML table in XLS format with a single click of a button. Currently, I have a JavaScript function that allows me to export the HTML table to XLS using the "save as" option. However, I want to enhance this functionality so that clickin ...

I encountered an issue where I am unable to subtract from jQuery's .outerHeight() within an if statement

I've been working on creating an ajax request that triggers when a div is scrolled to the bottom. I thought I had it figured out with this code, but I've run into an issue. Everything works fine without subtracting 100 from the elem.outerHeight() ...

Sticky sidebar following a complete-page header

I recently added a fixed sidebar to my website: However, I'm facing an issue where the sidebar appears in front of my full-page header when I set its position to fixed. What I actually want is for the sidebar to start after the header as if it were p ...

When the left/top/right/bottom properties are not specified, using position:fixed produces the desired results in Firefox and Internet Explorer, but not in Safari

It's unfortunate that I have to bring up another question related to position:fixed, but after going through various other questions and forum threads, I'm still not clear on this particular issue. The code below is a simple illustration of how ...

CSS Transition not activating upon initial mouseover

My attempt at a simple transition is not working properly on Safari. I am trying to change background images from A to B on hover, but the transition is not smooth when I first hover over the element. Instead of gradually fading in/out, it instantly change ...

The bottle framework has run into a problem due to exceeding the maximum recursion

I've encountered a maximum recursion depth error while trying to add a path for my web app. def runSQL(sql): db = sqlite3.connect('zadanie.db') c = db.cursor() c.execute(sql) data = c.fetchall() db.commit() c.close() ...

Is the CSS after-before property not functioning properly?

In my CSS code, I am utilizing the after and before tags. This is the structure of my div. However, I am facing an issue where my after tag is not functioning as expected. While everything else seems to be working fine, the after and before tags are not di ...

Creating a button that allows the menu to open either by clicking on the button itself or on the marker within the leaflet

I am currently using a sidebar similar to this one: . I have removed the source code from the Github repository found here: https://github.com/Turbo87/sidebar-v2/blob/master/examples/index.html. However, I am facing an issue where clicking on the marker ...

What is the best way to arrange a bootstrap .container?

I've been struggling to position a content DIV on a bootstrap carousel, but so far I haven't been successful in figuring it out. Below is a screenshot of the current output from my code, which is not what I am aiming for. What I'm trying t ...

Tips on looping through a universal array and retrieving user input

My current project involves creating a news site using the Guardian API. I want to implement a search feature that allows users to input keywords and retrieve the webTitle attribute for matching elements. While I could simply insert the user input directly ...