Top and bottom borders embraced by text: the ultimate header design

I'm looking to create a screen-wide headline with a simple text-logo. The challenge is to make it touch the container's top and bottom borders like this example, including its half-height variations.

Upon inspecting the HTML, I noticed that there was some built-in top and bottom margin for fonts that prevented the text from touching the container borders. To address this, I utilized the line-height property (after guessing the proper value).

You can see my solution here: https://jsfiddle.net/2ukfc8e7/8/

Is there a more effective solution available?

Answer №1

It turns out that the solution I originally came up with is still the best option.

Each line of text within a tag has specific horizontal and vertical spacing that should not be mistaken for the margin/padding property. This space can be defined using the line-height property. By decreasing its value, we bring the top and bottom borders closer to each other and to the text line itself.

I've created a snippet (below) showcasing this approach with a transition on the line-height property to illustrate the concept in visual slow motion.

Answer №2

Recent Update:

body {
  padding: 0;
  margin: 0;
}
div {
  font-family: 'Open Sans', sans-serif;
  font-size: 48px;
  background-color: gray;
  color: white;
  border: 0;
  padding: 0;
  margin: 0;
  height: 34px;
  line-height: 30px;
}
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>

<div>
  <b>ABOF</b>
</div>

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

Displaying a list of text elements in a React component

Can someone help me figure out why my React app is not rendering a flat array of strings with the following code? {array.length > 0 ? ( <div> <h5>Email list</h5> <div style={{ paddingLeft: "50px", ...

What are the steps for printing a webpage in landscape orientation using Firefox and IE11?

@page { size: 11in 8.5in; } This code snippet did not achieve the desired result in Internet Explorer or Firefox. The transform: rotate(270deg); property only worked for the first page. ...

Organize a series of <span> elements into rows and columns through the use of CSS, JavaScript, or jQuery

Task: Your challenge is to display a list of span elements in both vertical and horizontal layouts without altering the HTML structure. Input: an unknown number of span elements within a parent span like the example below: <span id="parent"> <sp ...

Aligning an SVG icon at the center of a button

I have elements that are currently being used as buttons, but I want to switch them out for actual button tags. This would improve accessibility and allow keyboard navigation using the tab key to focus on my buttons. Each button contains a centered SVG ima ...

The battle between Typography and HTML formatting elements

When it comes to choosing between the <Typography/> tag and normal HTML tags like <p>, I find myself in a state of ambiguity. <Box className={someClassName}> <Typography>{someVariableName}</Typography> </Box> or <p ...

Ways to refresh a select element using jQuery

Can someone help me with this? <select id="apple"> <option>choose something</option> <option value="1">something 1</option> <option value=2">something 2</option> </select> If you know jQuery, could you shar ...

div that adjusts its max-width to always perfectly match the width of its contents

Check out this jsfiddle for more information: http://jsfiddle.net/tN6QE/2/ The CSS code we are using is as follows: div { display: inline-block; border: solid 1px black; padding: 10px; max-width: 200px; } We are dealing with two scenarios here. ...

``How can I lock the top row of an HTML table containing input fields in place while

Below is the table structure: <table> <tr> <th>row1</th> <th><input type="text"></th> <th><input type="text"></th> <th><input type="text"></th& ...

Instructions for inserting a hyperlink into a column of a table with the *ngFor directive in Angular2

I currently have a table with 4 columns: Name, ID, Department, and City. I am fetching both the row data and column data as an array from a TypeScript file and iterating through them using *ngFor. Below is a snippet of my code: <tbody> <tr *ng ...

The JQuery .replaceWith method exclusively offers unprocessed HTML content

I'm experiencing a minor issue with my ajax response where it returns raw html and does not execute any scripts, resulting in the jquery ui scripts not being executed. Here are some details: I am currently working with ASP.NET MVC and I need to comm ...

The initial menu option stands out due to its unique appearance, created using the :first-child

I am currently designing a website menu and I would like the .current-menu-item - current item, to have a different appearance. However, I want the first item in this menu to have rounded corners (top left, bottom left). How can I achieve this using the :f ...

Is there a way for me to edit the HTML file in Shopify?

I'm currently navigating my way through Shopify and finding it to be a bit perplexing. Although I understand what changes need to be made and how to make them, I am struggling to locate the HTML file that requires editing. Despite clicking on Online S ...

I am having trouble getting the color, metalness, lights, and shaders to work properly in Three JS on my

I attempted to create a simple code using Three.js for a red colored torus with a point light and a textured surface, but unfortunately, all I achieved was a black torus that rotates. It seems like the elements in this code are not functioning as expecte ...

What might be causing the overflow of my page width by my navbar?

I am currently working on creating a product landing page for freecodecamp, and I'm facing some issues with my navbar - the first element I need to get right. Could you help me identify what's wrong with my code? Additionally, I would like to ad ...

Cascading Style Sheets variable and Sassy CSS mixin

I'm facing a challenge involving the use of CSS variables in conjunction with my VueJs app. The goal is to make a hover effect (changing background-color) customizable by the application, while having a default value set in a nested SCSS map using the ...

Transmit information using $broadcast when a button is clicked, and retrieve that information using $scope.$on

I am trying to create a function that will broadcast data from the server upon button click, and then navigate to a new route using $state.go('new-route'). In the controller of this new state, I want to retrieve the transmitted data. However, whe ...

Embrace the power of React using curly brackets!

Today, I made the decision to dive into learning React. Typically, I use Brackets for my coding environment. The first step I took was adding the necessary sources to my HTML code. <html> <head> <link rel="stylesheet" href="styl ...

Setting an error state on the parent div of a checkbox

I am facing an issue with styling a standard HTML checkbox when it is in an error state. Since it's not possible to style the checkbox directly, I am attempting to apply the styling to its parent div instead. Consider this example: <div class="fo ...

Save hyperlinks provided by users within the text

Users have the ability to create a post and leave a comment. I am aiming to give my users the option to include a hyperlink in their comment, such as: "This is a comment where aboutme is a hyperlink." I am unsure of how to store this hyperlink. Currently, ...

Formula for full width skew in three adjacent divs using SkewX() function

.container { height: 500px; width: 500px; position: relative; background: black; } .box { transform: skewX(20deg); width: 33%; height: 100%; position: absolute; } .first-box { background: purple; left: 0; } .second-box { background ...