Could Chrome be miscalculating em unit values in media queries?

I have defined my media query breakpoints as shown below:

@media screen and (max-width:48em){
    /* phone */
}
@media screen and (min-width:48.063em){
    /* tablet */
}

After using a PX to EM calculator to get the 48.063em value (as I was advised to use em-units), I noticed that while it works fine in Firefox, Chrome seems to have an issue. The browser width of 769px falls in between the defined max-width and min-width values, causing neither to be applied. I know I can resolve this by adjusting the min-width to 48.01em. However, I have seen tutorials using 48.063em as well.

Could someone please confirm whether this is a bug in Chrome or a flaw in my approach?

Answer №1

I encountered the same issue and I believe you are right in assuming that your width is falling between the specified values, causing neither style to be applied. My suggestion is to eliminate the phone media query and include the phone styles at the top level instead, like this:

/* phone styles */

@media screen and (min-width:48.063em){
    /* tablet styles */
}

By doing this, your phone styles will be implemented unless the width reaches 48.063em or higher, at which point the phone styles will be overridden by similar ones in the media query (following a mobile-first design approach). This approach simplifies the cutoff point. You could also apply this concept to larger devices as well:

@media screen and (min-width:100em){
    /* even larger styles */
}

When examining the CSS for Foundation, you'll notice this methodology, which assisted me in resolving the issue. As to why the original code functions on browsers other than Chrome, I cannot say.

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

My Drop Down menu is not displaying the <a> in two lines, and I'm having trouble getting it to show correctly

Hello there! I've encountered an issue with my drop-down menu. The text within the <a> tags is too long to fit on a single line, and I'm struggling to make it display in two lines instead. I've been experimenting for the past couple o ...

Choosing <label> elements, while disregarding those <label> elements that include <input>

I need assistance with CSS rules to target only <label> elements that do not contain an <input> field inside of them. Is there a specific rule I can use for this? <label for="type">Regular Label</label> <label for="type"> ...

Steps to halt webkit animation within a div located inside a circle:

I have a series of nested circle divs, and I want to give them a pulse animation. The issue is that the text container is within one of these circles, causing the animation to apply to the text as well. I am unable to move the text container due to potenti ...

Angular routes cause a glitch in the Bootstrap navbar, causing it to shift to the left on certain active

Apologies for the simple question, I am new to web design and couldn't find a solution even after extensive googling and searching. The issue I am facing is that when clicking on "EX5" or "EX6" in my navbar, it shifts to the left side of the screen i ...

Clicking on a href link inside a scrollable div-container causes it to malfunction, causing the page to jump

I have a draggable div container that contains dynamically generated content. In order to display this container, I use the following code: $( function() { $( "#dialog-message" ).dialog({ modal: true, height: 400, buttons: { Fertig: functi ...

What is the best way to determine when an object is not clickable?

One way to confirm if an object is clickable is by using the following code snippet: - WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.XPATH, '//*[@id="table-defaults-7"]/div/div/div/div/span/button[2]'))) But what about checking ...

Issue with Bootstrap 5: Mobile Menu Failure to Expand

I’ve been struggling with this issue for days now. I’ve searched everywhere for a solution, but to no avail. That’s why I’m turning to the experts here for help :-) The problem I’m facing is that my mobile menu won’t open. Nothing happens when ...

What is the best way to vertically align a Material UI component to occupy the remaining space within a container

Issue with Material UI/Grids for Login Page As a newcomer to Material UI/Grids, I am currently working on creating a login page where the layout is split into two parts. The left side occupies 5 column spaces while the right side takes up 7 column spaces. ...

How to position radio buttons in line with labels containing inline inputs using Vue and Bootstrap

Currently, I am facing an issue with my form containing a radio button group where one of the radio button labels includes another numerical input. The layout is not aligned correctly, and I am struggling to adjust the spacing using CSS. I am unable to gr ...

What is the best way to horizontally align an element within a Material UI Grid item?

How do I align elements in the center of a Material UI Grid item? Check out this code snippet from my React project: <Grid container> <Grid item xs={4}> // Other content goes here </Grid> <Grid item xs={4}> // How can ...

Content within the p tag is failing to wrap onto separate lines

Take a look at the image below: Here is the code causing issues: <div class="excerpt"> <p>Manual for downloading and installing digital content from the Educational Canaima Project, comprised of learning resources that aim to promote interac ...

<container> rectangular form

.products { width: 100%; height: 500px; background: gray; } .box { width: 250px; height: 300px; background: darksalmon; border: 1px solid #000; } <div class="products"> <div class="box"> <p>Ola</p> </div> ...

Setting the width of colspan elements can be challenging when other columns have dynamic widths

I am working with a table setup that includes various columns for data tracking: <table > <thead style="width: calc(100% - 15px); display: table; table-layout: fixed;"> <tr> <th colspan="3">& ...

I'm looking to customize the text displayed on the screen from my JSON file. Is there a way to hide this text?

I am currently working with a JSON data file that contains values and displays them on the screen alongside a CSS property width. However, I do not want the output to be the actual numerical data; instead, I aim to connect the JSON file so that the value s ...

The automated test locator in Angular using Protractor is failing to function

I am facing a challenge with my angular web application as there are some elements that are difficult to interact with. One specific element is a checkbox that needs to be checked during testing: ` <div class="row form-group approval_label"> < ...

Changing the size of the logo as you scroll through the page

I have implemented the following code to resize the logo as I scroll down the page. $(document).on('scroll', function() { if ($(document).scrollTop() >= 10) { $('.logo img').css('width', '50px'); } else ...

What is the best way to make the child Div float to the bottom of the parent Div?

Screenshot I attempted various CSS techniques in an effort to make the .booknetic_appointment_container_footer float to the bottom of #booknetic_theme_5, but unfortunately, I was unsuccessful. The closest solution I found involved hardcoding padding, but ...

How can I achieve a full-width stepper in Bootstrap?

.row { background: #f8f9fa; margin-top: 20px; } .col { border: solid 1px #6c757d; padding: 10px; } <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <link href="https://useloope ...

What is the best method for arranging multiple images in a grid while keeping them within a specific maximum width and height?

I've been staring at this problem for a while now, attempting every possible solution to resize images and maintain aspect ratio, but none seem to work in my case. Here are two images that I manually resized so you can view them side by side: highly ...

Tips for testing the website's color modifications?

I recently had the task of replacing 10 specific colors with new ones in my CSS files. I used the find and replace method to make the changes in over 300 places throughout all the files. Now, I need a way to test if all the color replacements were done c ...