Tips for centering text on the edge of a container

Is there a CSS style that can align the top of the tallest character with the border of its container? I'm not sure if this is easily possible.

HTML

<div><h1>The "T" of this h1 needs to touch the top border</h1></div>

CSS

div {
    background: orange;
}
h1 {
    vertical-align: top; //doesn't seem to work?
}

JS-Fiddle


Currently, it looks like this

But it should look like this

Or like this (line-height = minimum?)


How can I achieve this?

Answer №1

When it comes to adjusting font proportions, the possibilities can vary depending on your specific font. One suggestion to try is setting the line-height like this:

h1 {line-height: .9;}

To fine-tune the result, you can play around with the values of line-height in combination with font-size, such as

line-height: 32px; font-size: 38px;
or
line-height: 0.9em; font-size: 2em;
, and more.

If you find that there isn't enough orange at the bottom, an option could be adding a bottom border like so:

border-bottom: 20px solid orange;

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

Aligning the image at the center within a flex container

I am struggling with aligning an image and a link inside a div using the display: flex property. This is how my code looks: <div style="display: flex;"> <div class="site-title-container"> <img style="border-radius: 7px; width: 34px; h ...

Querying jQuery: How to Retrieve the ID of a Link

I have a set of links, each with their own unique id: <li><a id="about" href="#">About</a></li> <li><a id="call-us" href="#">Contact us</a></li> <li><a id="home" href="#">Head on home</a>&l ...

Can you explain the functionality of .val().trigger('change')?

I could use some clarification on a certain line in my project: The categories-product id belongs to a <select> element, and I've noticed someone wrote this in the project: I'm curious about its meaning. $('#categories-product' ...

Creating a JavaScript function that converts data from JSP to JavaScript using single

I am struggling to pass a string into a JavaScript function successfully. Despite trying multiple approaches, I have not been able to make it work. <a href="javascript:goFac('<%=name%>')"><%=name%></a> The variable "name ...

Blank canvas for exploring SQL and PHP queries

I am currently working on a website that displays personal statistics for users. To achieve this, I am utilizing PHP to retrieve data from an SQL database. Below are the two files I am using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...

Bing Map API Version 7 Doesn't Show up on Screen

I am facing an issue with displaying the Bing map code on a website built using HTML5, CSS3, and jQuery. I am utilizing the SDK AJAX v.7 to generate the code. The problem arises when I attempt to insert the code provided (along with my personal key) and c ...

Is it possible to invoke a Javabean method in HTML using onclick in JSP?

I am currently working on a school project that involves connecting to a database from a JSP page using a Java bean, which I have successfully implemented. However, I am facing an issue where every time I click a certain button, I want to call a method in ...

Clicking the button causes the div to shift from its original position

Issue Whenever the buttons for playoff season or regular are clicked, the divs containing the content players-list and players-regular seem to move out of place as they fade in and out. How can this movement be prevented? I attempted using position fixed ...

Crafting a flawless responsive design with the perfect blend of CSS and

I'm currently working on a website using a Bootstrap template. Check it out here: I'm facing an issue with the paragraphs in the middle overlapping in a weird way. Any suggestions on how to resolve this? Here's a screenshot of the problem. ...

Utilizing JavaScript to effectively incorporate Create and Delete functions

I am having some difficulty with creating and removing a div element using JavaScript. I have successfully created the div, but I am unable to remove it right away. It seems that the script cannot locate the div because the page has not been reloaded. M ...

Bootstrap 4 Alpha Grid does not support aligning two tables side by side

When working with Bootstrap 4, I am aware that the .col-xs classes have been removed. Instead of using .col, I have tested it on Bootstrap 3.5 which is currently being utilized. <div class="col-xs-4"> Table content for left ...

Deleting records in an HTML table using a PHP button

After outputting the results from a MySQL table to an HTML table, I encountered an issue with my delete function not working for specific rows in the last column. Thanks to the helpful comments provided by users, I made adjustments to my code so that it i ...

Incorporate CSS styling from a separate .css file into a material component

Just starting out with material UI. I have a css file that looks like this: .bgItem { font-size: 14px; } My component setup is as follows: <MenuItem key={status.Id} value={status.Value} classes={css.bgItem}> {status.Description} </Men ...

A missing semicolon is encountered while compiling a React application

I am currently working on my app using Create React App and incorporating scss. I have used a vscode plugin to convert the scss to css, but I keep encountering an error when running npm run build. The error message reads as follows: [email protected ...

What are the reasons behind my item not triggering an alert even after I have created it, saved it, and attempted to alert it?

I am currently working on a code that allows users to input information which is then stored in an object. However, despite my efforts, when I attempt to retrieve the saved object by alerting one of its values, it indicates that the object does not exist. ...

What is the method for displaying html files in a POST request?

This is the code snippet I am working with: app.post('/convert', function(req,res){ var auxiliar = "somo Ubuntu command line(this works)"; exec(auxiliar, function(err, stdout, stderr){ if(err){ console.log ...

container div not fully extending to parent's height

I'm attempting to make the container div reach the full height of its parent element. The parent (body) is styled with the color info, while the container div is styled with the color primary. The intention is for the color of the container to stretch ...

Utilize the browser/page scroll bar to navigate through the fixed-position div's content

I have several div elements with the CSS property position:fixed positioned all over the page. One of these divs contains longer content than the others. My goal is to enable scrolling within that specific box using the main browser/page scroll-bar, as op ...

The error message "require is undefined for Electron"

I am developing an application that requires access to the file system (fs) module. Despite having nodeIntegration enabled, the renderer is throwing this error: Uncaught ReferenceError: require is not defined Many similar issues I researched suggested tu ...

Updating image source dynamically with Flask

I am currently developing a face detection application using Flask. I aim to have the detected faces displayed in real-time on the HTML page. For the JavaScript aspect, I am utilizing getUserMedia to live stream camera images from the client to the server ...