Divs with varying heights that have a position relative along with smaller font sizes

This is a query I had regarding the use of the sub tag:

Using <sub> tag and preserve line-height

To achieve the subscript effect, I tried using position: relative; along with a smaller font size. However, I noticed that this solution is not achieving pixel-perfection. The <div> containing the emulated sub tag appears to have a larger height compared to the one without it, even when the text in both divs is exactly the same. This behavior was observed in Chrome and Firefox, as demonstrated in the following live code example:

http://jsfiddle.net/FRkQ6/

On my Mac's Chrome browser, the output shows:

Height of first div is: 163
Height of first div is: 162

While this live code snippet works as expected on Chrome, on Firefox, the rendering of text in lines differs causing the issue to be similar. I am seeking an explanation for this behavior. Is it a browser bug or intended behavior? Can this be fixed using CSS (by subtracting the top and bottom border height of 2, the height should be divisible by the line-height, which is 20 in the demo, hence preventing a height of 163)?

Answer №1

Despite the span having a position:relative, the browser is still incorrectly factoring in its line height. To correct this, adding a line height of zero resolves the issue...

line-height: 0;

Check out the jsFiddle demo

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

Learn how to join a comma with a space in AngularJS

My sequence of strings is "aby,abraham,issac,rebecca,job,david,daniel" and I want to insert a space after each comma. I am assigning the value using ng-bind and showing the result using ng-show. I cannot use the join function as the data is retrieved as a ...

What causes the checkbox toggle to require two clicks instead of one?

Currently in the process of creating a checkbox along with an attached label. The for attribute is used to connect the click for the checkbox. There is also a jQuery function that triggers a slide toggle for a text input field on clicking the checkbox and ...

When using the `sendFile` method in Node.js Express, you will notice that the HTML content

Hey there, I'm new to nodejs and trying to create a simple website with two pages. I'm facing an issue where the content of the second file is being rendered as the first one, even though the source inspector in the browser indicates that it&apos ...

How come HTML components are able to immediately access the updated value of useState, even though it operates asynchronously?

Why does useState update immediately inside HTML codes but only on the next render in functions? import { useState } from 'react' function uniqueFunction() { const [data, setData] = useState('previous') function submit(e) { <-- ...

Ways to ensure even spacing in a responsive header design

On my homepage, I have a large header image that is responsive in the mobile version. However, I am having trouble managing the spacing between the button and text below it. The spacing varies on different mobile screens and sometimes appears larger than i ...

Page designed for displaying small star ratings in JSP

In the realm of my star.jsp page, the style.css is its trusty companion, faithfully executing its duties. However, a desire has crept into my heart - I yearn for the stars to shrink in size. The Chronicles of My Code star.jsp <!DOCTYPE html> ...

Issue with Wordpress Submenu Items not Displaying

I've included sub menu items in my primary navigation, but they're not visible at all? I've examined the css and haven't found any code that would hide the sub menu. ul.art-hmenu { display: inline-block; vertical-align: midd ...

PHP image retrieval is not functioning correctly and the image is not appearing as it

I'm facing some challenges when it comes to displaying images with PHP. I attempted to use this solution from Stack Overflow, but unfortunately, the image is still not appearing correctly. Within my PHP file that deals with the HTML layout, the code ...

What is the best method for extracting or filtering data from HTML using PHP?

Every day, I receive an email containing an HTML document with statistics from the previous day. The HTML format is difficult for all users to read, so I'm looking to automatically extract information from this table using a PHP script. Below, you&apo ...

Methods for passing JavaScript variables to PHP

I have encountered this problem on Stack Overflow before, but I couldn't find a solution that worked for me. I am using Codeigniter and have a form where users can rate a product. What I need to achieve is to insert the user's rating into the dat ...

What are some effective CSS styles that can be used to illustrate the concept of "loading . . ."?

I've been leveraging the power of blockUI successfully, but now I'm faced with the challenge of dynamically loading a table row. My research indicates that blockUI may not be compatible with HTML table rows. My idea is to use: jquery.AddClass(" ...

Even though I have the image button's ID, I am unable to successfully click on it

I am facing an issue where I can't seem to click on an image button even though I know its ID: driver.findElement(By.id("its Id")).click() Unfortunately, I cannot provide the website link as it is not a public website. However, I have pasted the HTM ...

A demonstration of VueJS Nested Builder functionality

I am currently exploring VueJS and working on a project to create a simple page builder application that allows users to add sections and subsections. I am seeking guidance on how to properly set up the Vue data property for this functionality. Any advice ...

Switch Button Hyperlink in HTML/CSS

I have the following code: document.addEventListener("DOMContentLoaded", function(event) { (function() { requestAnimationFrame(function() { var banner; banner = document.querySelector('.exponea-banner3'); banner.classList ...

The function Event.preventDefault seems ineffective when attempting to block input of CJK (Korean) characters in a v-text-field of type

Currently, I am tackling an issue in a Vue project where I need to fix a small bug. However, the solution seems quite challenging. I have managed to make the v-text-field accept only numerical input, which is functioning well. <v-text-field type=" ...

Create a JavaScript and jQuery script that will conceal specific div elements when a user clicks on them

Within my navigation div, there exists another div called login. Through the use of JavaScript, I have implemented a functionality that reveals additional divs such as login_name_field, login_pw_field, register_btn, do_login_btn, and hide_login upon clicki ...

Can you explain the purpose of ExpiresAbsolute?

In the process of converting an ancient and poorly written ASP page to ASP.NET, I stumbled upon this particular line in the "head" section: <meta http-equiv="ExpiresAbsolute" content="0" /> Despite searching on Google, I couldn't find any mean ...

I'm unsure about the JavaScript toolkit framework's handling of selecting HTML class attributes

I have been exploring the Electron Framework using a JavaScript toolkit known as Xel. In my main.js file, I am working with the following syntax: document.querySelector("menu.selected").className.remove('selected') In my Xel code snippet, I hav ...

Tips for creating rounded corners in an Electron application

const electron = require("electron"); const {app, BrowserWindow, globalShortcut} = electron; const path = require("path"); function createNewWindow(){ newWin = new BrowserWindow({ width: 1000, height: 750, icon: path.join(__d ...

Having difficulty replicating the same effect across all five canvas elements

After following the code provided by j08691 here for canvas, everything worked flawlessly. However, I encountered an error in JavaScript when trying to implement it on multiple canvas elements. As a beginner in JavaScript, I would greatly appreciate any as ...