Words not within the span, away from the span border

I’m currently in the process of creating a dedicated section on my website called "Voices of the Nation,” which draws inspiration from the foundations laid out in the U.S. Constitution. The objective is to highlight individuals who have shown their support for this initiative by acting as digital “signers.” One challenge I am facing involves displaying these names with varying font sizes in an aesthetically pleasing manner on the webpage. It seems that there is some inconsistency regarding the alignment of the text within the spans containing the names. Here are a couple of visuals illustrating the issue:

Upon closer inspection, you can observe that certain names overlap each other, which is something I would like to rectify. An interesting observation is that the text appears to be positioned outside the outlines of the span elements:

A similar discrepancy can be spotted across all the listed names. Below is a snippet of the HTML code I am using:

<div id="names">   
    <span class="order ten CalifornyaA-Bold" id="o3">Eric So</span> &nbsp;
    <span class="order twenty-five CalifornyaB-Bold" id="o5">Sierra Hansen</span> &nbsp;
    <span class="order ten CalifornyaB-Bold" id="o6">Eleanor Collier</span> &nbsp;
    ...
    <span class="order twenty-five CalifornyaC-Bold" id="o69">Maeve McCarty</span> &nbsp;
</div>

... along with the corresponding CSS styling:

#names {
  text-align: center;
  padding-bottom: 10%;
}
.hancock, .five-hundred, .two-hundred, .one-hundred, .fifty, .twenty-five, .ten {
  line-height: 1.5em;
  white-space: nowrap;
}
.hancock {
  font-size: 5.5em;
}
.five-hundred {
  font-size: 4em;
}
.two-hundred {
  font-size: 3.4em;
}
.one-hundred {
  font-size: 2.8em;
}
.fifty {
  font-size: 2.2em;
}
.twenty-five {
  font-size: 1.6em;
}
.ten {
  font-size: 1em;
}

If anyone could offer assistance or guidance on resolving this issue, I would be extremely grateful!

Answer №1

Consider adjusting the line-height property for these inline elements instead of block elements:

.hancock, .five-hundred, .two-hundred, .one-hundred, .fifty, .twenty-five, .ten {
      line-height: 110%;//percent would be good
      white-space: nowrap;
    }

You can also set individual CSS rules for each element rather than setting all to 1.5em
Edit:
Make sure to specify a font-size for the parent element when using em units. Take a look at how I wrapped text and added a font-size in em on this page without any overlapping:

Answer №2

utilize the following code snippet:

span {line-height: 1.2;}

Answer №3

Using display: inline-block along with adjusting the margin-top seems to do the trick quite effectively. While it may be considered a workaround, it does the job adequately.

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

Tips for styling React Material-UI list items with fontAwesome icons and Tailwind.css

I would like to align the text of my list items to the left. Additionally, I want all the icons to be the same size as the envelope icon used in Gmail list item. Currently, my code looks like this: https://i.stack.imgur.com/9LNOs.png How can I achieve th ...

Tips for adjusting content that is 900px wide to fit properly on a mobile screen while maintaining its original width

https://i.stack.imgur.com/JELN5.png Despite trying various meta tag variations, I am struggling to get this image properly scaled and displayed in React.js. Any suggestions on how to resolve this issue would be greatly appreciated. ...

Controlling the Flow of Events in JavaScript Documents

Explore the integration of two interconnected Javascript files and delve into managing event propagation between them effectively. 1st js file var red = [0, 100, 63]; var orange = [40, 100, 60]; var green = [75, 100, 40]; var blue = [196, 77, 55]; var ...

Clarification: Javascript to Toggle Visibility of Divs

There was a similar question that partially solved my issue, but I'm wondering if using class or id NAMES instead of ul li - such as .menu, #menu, etc. would work in this scenario. CSS: div { display:none; background:red; width:200px; height:200px; } ...

Prevent border duplication in CSS and retain border visibility

Check out this fiddle where I have three divs with a border-width of 2px. Originally, the issue was that each div's border gets duplicated in between, resulting in a total border-width of 4px. To solve this, I applied a margin-top of -2px to each div, ...

Is there a way to ensure that a child mimics the behavior of its parent when adjusting the opacity and visibility properties of both elements?

Apologies for the ambiguous title, as I am struggling to accurately convey the issue I am encountering. To clarify the problem, I have created a jsFiddle. In my current layout, all four divs have opacity: 1 and visibility: visible, while divs a and b both ...

File remains visible after deletion upon refreshing the page, but disappears after using the Ctrl + F5

After deleting a file on the server, I noticed that it still appeared when I refreshed the page. However, when I tried to do a hard refresh by pressing ctrl+F5, it resulted in a 404 error. This behavior is puzzling to me - shouldn't a simple refresh s ...

Trimming Text with JQuery

My goal was to truncate a string and add an ellipsis at the end using jQuery, but my code doesn't seem to be working as intended. Below is the jQuery code I wrote: $(".link-content > h4").each(function(){ var len = $(this).text().length; ...

Deselect the DOM element

Here is a jQuery code snippet: $(document).ready(function () { $(".story-area > h1, .story-area > p, .story-area > div > p").text(function () { return convertString($(this).text()); }); }); Additionally, there is a function de ...

Customize your Bootstrap 4 navbar to align on the right with a button that remains visible on mobile devices

I'm working on setting up a navbar with three elements. I want to have a left-aligned brand, a group of right-aligned links that will collapse on smaller screens, and an additional button that stays visible at all times. To achieve the alignment of t ...

Tips for utilizing the Toggle Slider JS functionality

I'm attempting to change a value using a slider in HTML, here is my approach: html file : <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script scr="./scripts.js" ...

Create a 2x2 HTML table where the first row remains undivided

I am working with an HTML table that is 2x2. Within this table, I am trying to achieve a layout where the first row consists of only one cell that spans the full width of the table, without being divided into two parts. ------- | | ------- | | | -- ...

Expand a div without causing any displacement to surrounding elements

If you have 4 colored divs (red, yellow, green, blue), with 2 per row, and need to expand the second (yellow) without creating a gap under the red, check out this solution. The blue will be positioned underneath the expanded yellow. For a live example, vi ...

Changing date format in Mui DatePicker

I need some assistance with customizing the mui DatePicker. Specifically, I would like to set the date format to display as Day, DD Month. For example: Monday, 10 September Below is the code snippet I am currently working with: <LocalizationProvider d ...

Next.js is refusing to render an array of HTML elements

Consider this scenario where I have a block of code in TypeScript that attempts to create and display a list of elements. Here is a sample implementation: const MenuList = ():ReactElement => { const router = useRouter(), liElements:any = []; con ...

What is the best way to anchor the components to a specific location on the screen in ASP.NET?

Currently I am working on creating a registration page in asp.net. I have been using panels to group the components such as labels, dropdown lists, and text boxes. However, when I run the page, I noticed that the positions of these components keep changing ...

Switch up the animation based on the state in AngularJS

In my AngularJS application, I have implemented CSS animations for transitioning between states. The animations involve sliding content from left to right with specific timings and transforms. .content.ng-enter, .content.ng-leave { -webkit-animation-t ...

Ionic - Landscape Mode Causing Alignment Distortion

I'm currently working on designing a grid-based image display for an Ionic Mobile App. One of the main challenges I'm facing is adjusting the heights of the images based on the screen size. I want to set a maximum height for both portrait and lan ...

Automatically sync textbox width with gridview dimensions

My goal is to dynamically resize a number of textboxes so that they match the width of my gridview's table headers. The gridview will always have the same number of columns, but their widths may vary. However, as shown in the image below, the width va ...

Using React Native's stylesheet to apply multiple values in a CSS statement

Here's a scenario to help clarify my question: Imagine I want to add margin to an element in the following way: const myView = () => <View style={styles.viewStyle}></View> const styles = StyleSheet.create({ viewStyle: { margin: ...