What impact does zoom have on the width of the image?

For more information, you can check out the code here: http://codepen.io/anon/pen/VvdyQb?editors=010

I'm struggling to comprehend how the viewport width changes when zooming in or out. My media queries are activated based on changes in width measured in em units.

My query is this: Why does the viewport adjust when I zoom? Is it related to the increase or decrease in font size? The 'em' unit is linked to the font size of the parent container. If the default font size for the body element is 16px, then 1em equals 16 pixels. But what happens during zooming? Does 1em no longer equal 16px and instead becomes larger or smaller depending on the level of zoom? I presume that text size affects the parent container's size, but I find it challenging to understand how it impacts the overall width of the page. How is width connected to zooming and em? It seems like the page width decreases upon zooming in and expands when zoomed out?

html,
body {
  background-color: lightblue;
}
div#nav {
  position: relative;
  width: 50%;
  background: white;
  box-shadow: 1px 1px 15px #888888;
}
div#logo {
  border-right-style: solid;
  border-width: 1px;
  border-color: rgba(0, 0, 0, 0.15);
  font-family: 'Myriad Pro Regular';
  font-weight: normal;
  color: #1E3264;
  font-size: 2em;
}
@media (min-width: 50em) and (max-width: 99em) {
  #logo {
    background: orange;
    font-size: 0px;
  }
}
@media (min-width: 100em) and (max-width: 149em) {
  #logo {
    display: none;
  }
}
@media (min-width: 150em) {
  #logo {
    display: initial;
  }
<div id="nav">
  <div id="logo">TEST</div>
</div>

Answer №1

It is crucial to understand the drawbacks of the styles and media queries you have implemented. One key concept to grasp is the use of media queries in responsive design.

min-width

The term min-width indicates that your container must be at least as wide as this specified width or wider. When designing for responsiveness, it is ideal to consider the maximum range within which your query should operate. Therefore, using max-width would be more appropriate in such scenarios. min-width is typically utilized for specific intervals, like targeting a range between 20em and 30em, where you would specify

max-width: 30em and min-width: 20em
.
On the other hand, if you only need to target a maximum range of 20em, then utilize max-width: 20em in your query.
For responsive design, it is often recommended to use pixels (px) instead of em units. This is because em sizes are relative and may not provide absolute ranges required for media queries. I trust this explanation will enhance your understanding significantly.

Answer №2

Hey there, the `em` unit is a relative length parameter that relies on pre-defined absolute font-sizes. It's essential to understand that `em` is not an absolute measurement like `16px`. The default absolute font-size for browsers like Chrome is typically `16px`, making it seem like `1em = 16px`. However, this isn't always true.
If you establish your base sizes before applying styles, such as setting `html{ font-size:20px; }`, then using `1em` within your content will actually equate to `20px`. Essentially, `em` adjusts proportionally based on these default absolute font-sizes rather than being a fixed value.

Answer №3

When zooming in or out, em-based media queries remain unaffected. The same goes for adjusting the font-size of the root HTML element (although it will impact the size of an em used elsewhere in your stylesheet, like the font-size of child elements).

In most cases, 1em equals 16px in media queries, unless the user has changed their browser's default font size settings. Typically, browsers have a default font size of 16px, but if a user sets it to 24px, then 1em would be equal to 24px; this means that a 50em breakpoint would correspond to 1200px (50 x 24px) instead of 800px (50 x 16px).

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

What is the best way to modify CSS and HTML with a post request?

I'm currently in the process of working on a webpage with multiple sections. One section includes a form that sends a POST request. Once this form is successfully submitted, I want to update the CSS style of another element to make it visible. Given ...

Activate the button solely when the text field has been populated without any spaces

Searching for a solution to my query, but all the suggestions I've encountered don't consider spaces as valid input. In the join function I have, the button should be disabled if the user enters only spaces. A requirement is for actual text inpu ...

I am looking to integrate a WordPress blog post into my Bootstrap website

Is there a way to showcase the 3 most recent posts from my WordPress blog (www.xyz.wordpress.com) on my Bootstrap HTML website without using PHP? Feedburner got me close, but I'm limited in CSS styles and don't want the "Headline by Feedburner" ...

Tips for implementing a floating label in a md-input-container when the ng-model is empty

My goal is to achieve one of the following: Option 1: Option 2: Existing Code: <md-input-container ng-if="!ctl.module.activeDate" placeholder = "NotSetted"> <label>Activation Date</label> <md-datepicker ng-model="" disable ...

The insertion of the script string from the ajax response was unsuccessful

When working with PHP, I encountered an array with two parts: array('threeRowHtml'=> '<HTML output string>', 'jsCode'=> '<script output string>' ) I decided to return this array for my ajax call. ...

Collection of numbers with decimal points

Can one use <li> numbers in this format?: 1.1 First Item 1.2 Second Item 2.1 Other item ...

Creating equal spacing between divs and the edges of the container

I need to arrange a set of divs equidistant from each other. My goal is to have the maximum number of divs fit side by side with equal spacing between them and the container edge. While I almost achieved this with the code below (credit to another post), ...

The text-decoration is here to stay

Currently, I am facing an issue with the customization of a wordpress theme related to the styling of links within posts. Although I have tried to change the color and remove underlining using CSS rules, I am unsuccessful so far: a, .entry-meta a, entry-c ...

`Center Google My Map Location - Embedded in the Middle of the Page`

Recently, I transitioned to using an embedded My Map for a business with 2 locations. However, I encountered some challenges in customizing the map's height, width, and centering on the page. Is there a way to resolve this issue? New HTML code which ...

Unable to Load CSS in New Magento Template

I have reached out to the template creator's website and Magento support for assistance, unfortunately, I have not received any response so far. Despite installing a custom theme that is said to be compatible with the latest version of Magento, the C ...

The color of active links in TailwindCSS remains unchanged

In my project, I am using NextJS along with Tailwind CSS to create a top navigation bar. My goal is to change the text color for active links within the navigation bar. Below is the code snippet I have implemented: const Header = () => { return( ...

Issues with padding in the h1 title of a mobile website

I am currently working on creating a mobile-friendly version of a website. However, I am facing an issue where the background image set for an H1 title is only taking into account the "text height" and not the actual picture height specified in the CSS. A ...

Managing the intersection of div elements

Can someone help me make the inner part of the red circle white, overlapping with the blue circle and transparent for the rest to reveal the green color underneath? If anyone has a solution, I would greatly appreciate it. #bigCircle { display: flex ...

Utilizing Jquery for toggling HTML elements and styling with CSS

I'm trying to implement a jQuery toggle button that switches between two states below; When I click the Toggle Button/link, everything in picture A (above the red line) should be hidden. Clicking the toggle button again would make it reappear. I&apo ...

When a button is undersized, the click event may not register

In my angular application, I have developed a directive for a tinyMCE editor. Upon setup, I have implemented two handlers: one for the blur event to hide the toolbar and another for the click event to show it. Additionally, I have created another directive ...

Changing the background color of navigation items when the navbar in Bootstrap 4 adjusts for responsiveness

Hi there, I'm having an issue with my Bootstrap 4 navbar. When I test the responsiveness of my page, the background color of my nav-items disappears and only the text is visible. Can someone guide me on how to maintain the navbar color when I click th ...

Hover over, enter the mouse

On my FAQ and Question page, I want the answer to a question to be shown when a user hovers over it. However, currently all the answers are displayed when hovering over any question. This is not the intended functionality - only the answer to the selected ...

Ways to troubleshoot an unusual margin issue in a static column of an HTML table

I have been exploring various resources to create an HTML table with a fixed first column using CSS only. Despite my efforts, the fixed column is consistently appearing lower than the rest of the content, and I'm unsure why. Check out the code I&apos ...

Enhance Your Website with Bootstrap 3.0 Affix

Looking to attach a right hand column to the top of the window as you scroll using Bootstrap 3.0 and 'affix' feature. Here is the HTML for the element: <div class="col-lg-4 right-hand-bar" data-spy="affix" data-offset-top="477"> This is ...

Splitting a list of accordions into two columns with CSS and React - a step-by-step guide!

I am looking for a way to showcase a list of Accordions in a two-column layout. Each Accordion consists of both a Summary and Details section, with the Details being visible only when the Summary is clicked. Unfortunately, I won't delve into the imple ...