CSS measurements inconsistency

Suppose that 100%, 16px, 1em, and 1 are equivalent (for unitless line-height). In my observation, 162.5%, 26px, 1.625em, and 1.625 all represent the same value.

While setting line-height to 1.625, 1.625em, or 26px produces consistent results in Chrome, using 162.5% causes differences (although Firefox displays it correctly).

Does anyone know why this discrepancy exists? I've thoroughly checked for errors but couldn't find any. It's puzzling how some sources provide inconsistent values like stating 160% as 26px instead of 162.5%. Here is an example:

Check out the demo here: http://jsfiddle.net/tr9Nr/1/ (best viewed in Chrome or IE11; Firefox displays it correctly).

Answer №1

Your calculations are spot on: 100% = 16px = 1em = 1

The discrepancy you're noticing lies in how webkit browsers such as chrome handle decimal percentage values. It seems that in your situation, webkit rounds down the percentage line-height instead of rounding it up, resulting in 162.5% always being displayed as 162%; check out jsfiddle.

It's hard to label this as a bug since there aren't well-defined standards for sub-pixel rendering... this is simply how webkit operates.

The chart provided seems to round the pixel values.

Rest assured that your designs won't be off by more than a few pixels. Achieving pixel-perfect layouts across different browsers remains an elusive ideal to aspire towards. :-/

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

When using jqueryprint.js to print from Firefox browser, an additional blank page appears before the content

Seeking assistance in printing a section of an HTML page using PHP with a large header space for empty space after printing. Despite multiple attempts, achieving the desired result in Chrome, but facing issues with Firefox, which adds an additional page be ...

Passing the hex code value of the background-color to the .text() function

My goal is to dynamically read the hexadecimal code from the <span> tag and set it as the background color of the same tag using jQuery. Currently, I have code that achieves this with specific variables, but I want to make it more dynamic. $(docum ...

Is it required to double click checkboxes to uncheck them?

My checkboxes require 2 clicks to be unchecked, even though one click is enough to check them. This issue occurs in all 7 checkboxes and there is no onchange() function or similar in TS. import { Component, OnInit, Inject } from '@angular/core&apos ...

Ways to conceal text that is not wrapped in an HTML tag

<div class="padd10_m"> <a href="http://www.caviarandfriends.com/job_board/user-profile/admin/" class="grid_view_url_thing1">admin</a> <img src="http://www.caviarandfriends.com/job_board/wp-content/themes/PricerrTheme/images/flags/us.pn ...

Stylish dots emerging under navigation bar

Okay, so I've run into a simple issue, but I can't seem to figure out the solution. Ever since I wrote this code, I've noticed these small dots appearing below the menu. Take a look at the image for a clearer picture. https://i.sstatic.ne ...

Building a Collapseable and Non-Collapseable Bootstrap4 NavBar in ReactJS

Is there an easy solution for creating a collapsible horizontal NavBar? <Navbar inverse fixedTop fluid collapseOnSelect> <Navbar.Header> <Navbar.Toggle /> </Navbar.Header> <Navbar.Collapse> <Nav> ...

Create a non-responsive, one-line navbar for mobile in Bootstrap 4 that does not wrap around

I'm looking for a way to make my Bootstrap 4 navbar non-responsive with the toggler. Here is the issue I'm facing: Current Navbar in big screen: https://i.sstatic.net/e3f3p.png Navbar in mobile view:https://i.sstatic.net/7jMi5.png What I want ...

Transform the inline style attributes found in the HTML code into CSS styling

After creating a webpage using Bootstrap Studio, I realized that all the style attributes are inline and I want to move them to a separate CSS file. However, I am facing difficulty in doing so as when I add an image using 'background-image:url('i ...

Use the Segoe UI typeface on Internet Explorer for a sleek

I have implemented a custom Segoe UI font in my CSS file. While it displays correctly in Chrome, I am facing an issue where IE and Firefox are showing the default font in certain areas. Below is the snippet of the CSS code: body { margin:0px auto; ...

In HTML, utilize the "clone" div class

Upon inspecting the element of my website, I have observed that the top-header div contains a duplicate. Why did this occur? How can I eliminate the clone and retain the original div top-header? Visit my site Below is the HTML code: <div id="top-h ...

Switch from using a select tag to a check box to easily switch between a dark and light theme

I have implemented a feature on my website that allows users to toggle between dark and light themes using the select tag with jQuery. Here is the code snippet that I am currently using: $(function() { // Code for changing stylesheets based on select ...

What's the best way to ensure that a div remains fixed at the top of the page while also being centered?

I have a div that I've centered using margin left and right auto. However, I want this bar to be visible throughout my page, so I positioned it absolutely. But now the bar is not centered anymore, it's appearing on the left. How can I position th ...

An unexpected error has occurred in the browser console: The character '@' is not valid

I recently made the decision to dive into learning about Unit Testing with JavaScript. To aid in this process, I started using both Mocha.js and Chai.js frameworks. I downloaded the latest versions of these frameworks onto my index.html from cdnjs.com. How ...

Is there a way to make text smoothly scroll and fade in upon page initialization?

I want to create a unique effect where text loads on the page, revealing one letter at a time from left to right in a fading manner. However, I also desire for each letter to slightly increase and decrease in size once while loading, creating a wave-like m ...

Optimal method for showcasing a logo bigger than the navigation bar

Seeking Advice: I am trying to incorporate a 100px by 100px logo on the left side of my navigation bar, which is only 50px in height. What changes can I make to the HTML and CSS structure for this design? My current setup includes: <div id="h ...

How to Align col-md-5 in the Center Using Bootstrap?

Is anyone else struggling with this dilemma or is it just me? I've been searching everywhere for a solution to my problem but I can't seem to find one. According to the grid system, if you have a column size of col-md-5, centering it should be ...

Is it possible for CSS in React to cause the vanishing of all buttons

I'm encountering an issue where the CSS styling applied to every button in my NavBar is causing a specific button labeled 'Search' to disappear when it shouldn't. The problem stems from NavBar.css, which contains a media query that unin ...

Having trouble incorporating custom CSS into my Rails/Bootstrap project

I’m having trouble figuring out what I’m doing wrong. I’ve added custom files and tried to override the existing ones. application.css.scss @import 'bootstrap-sprockets'; @import 'bootstrap'; /* * This manifest file will be co ...

The LINK CSS within the HTML code serves no purpose on the internet? Everything is working perfectly

Everything works fine in the development environment, but not online. The website URL is: The CSS URL: Both URLs can be accessed. However, the CSS file seems to have no effect. Any idea why? Thank you in advance! Additional Info: I am using nginx as a ...

The outline none property on the Material UI IconButton is malfunctioning

https://i.sstatic.net/S5zWD.png Attempting to style with CSS as shown in the following example: <CustomColorIconButton> <DeleteForeverIcon /> </CustomColorIconButton> const CustomColorIconButton = withStyles({ root: { c ...