Border appears when the line-height is less than the font size

When working with elements such as <p> or <h1>, I have encountered a situation where the line-height property is smaller than the font-size property. This causes the text inside the element to extend beyond its boundaries. Unfortunately, changing this would alter the design of the page.

While this might not be a problem on its own, it becomes problematic when I try to add a border (or an outline) around the element. In this case, the border wraps around the element itself rather than the text, resulting in a visually unappealing outcome.

Manually adjusting each border individually is an option, but this would be tedious and time-consuming, especially considering that I need to implement this on multiple areas of the website.

An alternative solution I considered is using display: inline. Although this approach does wrap the border directly around the text, it behaves unpredictably on elements with multiple lines of text.

You can see an example here.

Are there any other methods to ensure that the border aligns perfectly with the height of the text? I am open to suggestions involving both CSS and JavaScript solutions.

Answer №1

Consider incorporating the following code into your CSS: margin-offset: 20px; the specific value may need to be adjusted based on your design requirements.

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

Recursive array generation

Given an array 'featureList', the goal is to create a new array 'newArray' based on a specific ID. For example, for ID 5, the newArray would be ['MotherBoard','Antenna','Receiver'], where Receiver correspon ...

Tips for transforming JSON data from a specified URL, which requires authorization, into an HTML table or list using PHP

I am attempting to retrieve JSON data from this source: They have provided a 'how to' guide here: I have successfully connected with Authorization and received the raw JSON, but I am unable to format it into a table. This is the code I have wr ...

Is the table scrollable within the tbody tag?

Is it possible to create a table with a scrollbar on the right side using only CSS and without any plugins like jQuery? Additionally, I want the table header to remain fixed in place. What steps do I need to take to achieve this functionality? ...

Personalized Facebook Share Dialog - unique title and description

I need to send a link using the FB Send Dialog with custom name and description. FB.ui({ method: 'send', name: 'Custom name', display: 'popup', link: 'http://link.com', to: facebookUserId, description: 'Custom ...

The website image does not display at its full size when viewed on a phone

I'm new to working with html and css, and I've encountered an issue with my website regarding image display on both phones and PCs. When viewing the site on a phone, I notice that the full size of the picture is not visible, most likely due to th ...

Tips for aligning Bootstrap 4 cards when the first card header breaks at a word and the second card header does not

Currently, I am working on a personal project using bootstrap 4. However, I've encountered an issue with the class "card" in my gallery section. One card header has 'white-space' set which breaks the word, while the other does not have any & ...

CSS: Creating a block that stretches the entire width of its parent block

I've been facing the same issue multiple times. Whenever I use the float property to display one block, the next block ends up overlapping with the first one. For example: Consider the following block of code: .row_item{ width: 30%; display: block; ...

What is the best way to select an HTML tag element using the :v-deep() selector?

When I utilize the following: ::v-deep img { ... } it functions but triggers a deprecation warning: [@vue/compiler-sfc] ::v-deep usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead. How can I achieve the same effect using ...

Fresh Regular Expression created from a readable string

I can't figure out why rg = new RegExp(`/${a}.*${b}/`) isn't functioning properly here, while rg = /\(.*\)/ is working fine. let a = '\('; let b = '\)'; let rg; //rg = new RegExp(`/${a}.*${b}/`); // doesn&a ...

What is the best way to incorporate multiple connections in a single GQL mutation?

In my Prisma datamodel, I have defined a relationship between games and characters, where characters can appear in multiple games. Additionally, when querying games alone, the characters associated with them should also be listed: type Game { id: ID! @u ...

What is the best way to use CSS/jquery to make a default toggle show as open

I need help with modifying a code that collapses/expands an HTML area when clicked. The default setting is currently closed. How can I change it to either open or closed by default? http://jsfiddle.net/8ZCXU/5/ ...

Combine TypeScript files in a specific sequence following compilation

I am hoping to utilize gulp for the following tasks: Compiling TypeScript to JavaScript, which is easily achievable Concatenating JavaScript files in a specific order, proving to be challenging Since I am developing an Angular application, it is crucial ...

Adjusting table column widths in Bootstrap 4

I am completely new to bootstrap and am in the process of enhancing an existing MVC web application that is already utilizing bootstrap 4. My goal is to incorporate a table with form fields, but I am facing difficulties in controlling the column widths of ...

No data received through ajax query

I have been trying to use this ajax function, but I am not getting any response. Even though I have included an alert in the success alert('hi'), it does not seem to be working. However, in the error section, it indicates that alert is undefined. ...

Ways to dynamically add or delete tables within a ReactJS environment

Is there a way for me to dynamically add and remove table rows in ReactJS? I want the ability to add a row by clicking a button, and remove a row by clicking a small red div inside the table. Additionally, I would like to retain the color change option whe ...

Is it possible to modify form variables using echo without affecting the database?

Here is a form I am having trouble with: <div class="col-md-6"> <h4>Update Contact Information</h4> <form action="" method="post" name="contact" id="contact"> <di ...

Discover the technique for combining three different text colors within one span element without resorting to the <font> tag

Is it possible to incorporate three different colors of text (details-red, Enter-blue, here-yellow) within a single span without utilizing the <font> tag? <span>Details Enter Here</span> ...

Issue: [$injector:unpr] The provider "someProvider" is not recognized by the system and is causing an error

When using angularjs I made sure to register a service in the services directory under modules -> module_name angular.module('module_name').factory('service_name', [ function() { // Public API console.log('hell ...

displaying the identical image from various perspectives

I have an arrow image that I need to display in different angles - top, left, bottom, right. I was considering what would be the best approach: 1: Changing the image direction via CSS and loading the main image <img src="a.png"> <img src="a.png" ...

Switching the class from "untoggled" items to the selected item in React

Recently, I developed a toggle component known as Accordion. Within this component, I am iterating through an array of objects and displaying them in the following format: {object.map((o) => ( <Accordion key={o.id} title={o.question} className="i ...