Tips for positioning two distinct line numbers together?

Seeking guidance on aligning two separate lines in CSS, each with different numbers. The current code snippet is as follows:

First line: 1,1,1,1
 Second: 2,2,2,2

The desired alignment is:

First line: 1,1,1,1
 Second:    2,2,2,2

.wrap {
    display: flex; 
}
<div class="wrap">
    <div class="foo">
        <p>First line: 1,1,1,1</p>
        <p>Second: 2,2,2,2</p>
    </div>
</div>

The issue arises when the numbers are not aligned with each other. Adding text-align would not solve the problem if numbers change. How can this alignment be achieved using CSS?

Answer №1

Enclose the text and numbers in spans, then utilize CSS to present them as a table:

.foo {
  display: table
}

.foo p {
  display: table-row;
}

.foo span {
  display: table-cell;
  padding: 0 0.5em;
}
<div class="foo">
  <p>
    <span>First line:</span>
    <span>1,1,1,1</span></p>
  <p>
    <span>Second:</span>
    <span>2,2,2,2</span>
  </p>
</div>

Answer №2

    <p style="display:block; width:130px; background-color:red; "> The initial line is:<span style="float:right">1,1,1,1</span></p>
    <p style="display:block; width:130px; background-color:red;">The second line goes as follows:<span style="float:right">2,2,2,2</span></p>

Arranged to be shown on separate lines using display block and width properties

If you prefer to utilize flex:

 <body style="diplay:flex">
    <p style=" width:130px; background-color:red; "> The first line: <span style="float:right">1,1,1,1</span></p>
    <p style="width:130px; background-color:red;">Second line:<span style="float:right">2,2,2,2</span></p>
</body>

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

How to truncate lengthy text in a table on mobile screens using Bootstrap 4

I am currently working on a responsive table that needs to display correctly on both desktop and mobile devices. However, I have run into an issue where long text in the table gets truncated on mobile devices, compromising the responsiveness of the design. ...

Tips on implementing CSS to the subpar class in Vuejs

I am working on an HTML file that operates with button in Vue.js. The v-bind:class can be utilized for a single tag as shown below. It disappears based on the boolean value of bool data. <h3 v-bind:class="{active: bool}">{{counter.document}}&l ...

What could be the reason for my Bootstrap collapse navigation bar not functioning properly?

<!DOCTYPE html> <html lang="en"> <head> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <!-- Optional theme --> ...

Guide to inserting an icon within an input field

Seeking assistance in placing the checkmark icon inside the input box at the right corner. Additionally, I would like to know if it's feasible to show a 'Field Saved' message alongside the tick icon? Update: If the form contains multipl ...

Ensure that the content inside the centrally aligned div is also aligned at the

Looking for a way to center a box on a website I'm designing? Instead of aligning it based on existing centering, use the following HTML / CSS code to ensure that the white box is perfectly centered on the page. .loading { position: fixed; z-in ...

When I provide three values for grid-auto-rows, will CSS generate three rows accordingly?

Let's consider the following CSS property: div { display: grid grid-auto-rows: 15% 70% 15%; } Does this imply that within the container, there will be three rows where each row occupies a percentage of the parent container's height? ...

Using the <hr> tag in HTML to create a horizontal line is proving to be a challenge for me

.yellow-line{ position: absolute; top: 60px; overflow: auto; border: 10px solid red; } <img class="vox-logo" src="images/vox_logo.JPG" alt="Vox Logo"> <div class="header"> <h5 class="menu-0">EXPLAINERS</h5> ...

Tips for building a guided tour or walkthrough within a Cordova application

I'm looking to develop a guided tour for my Cordova app, but I haven't found the right solution yet. Bootstrap tour didn't quite meet my needs as I'm aiming for a more native Android experience. ...

How can I perfectly align a form in twitter-bootstrap?

Currently in the process of developing a social networking platform for a specific student community and more. In order to improve user experience, I am aiming to center this form on the webpage. If interested, you can view my progress here: http://jsfid ...

Error: Uncaught TypeError - The function indexOf is not defined for e.target.className at the mouseup event in HTMLDocument (translator.js:433) within the angular

Upon clicking on an SVG to edit my data in a modal bootstrap, I encountered the following error: Uncaught TypeError: e.target.className.indexOf is not a function at HTMLDocument.mouseup (translator.js:433) This is my SVG code: <svg data-dismiss ...

What could be causing the malfunction in this positioning and display?

<article id="l1"> <img class="active_pic" id="a1" src="img/load.gif"/> </article> <article id="l2"> <img class="active_pic" id="a2" src="img/load.gif"/> </article> <article id="l3"> <img class="activ ...

Adjusting the spacing between rows in Bootstrap 5

Having trouble with the spacing in my latest markup update. Here's what I have: <div class="row"> <div class="col-md-12"> <div class="form-group"> <label class="control-la ...

Unable to manipulate JQuery lightSlider slides using element index

I've been working on a new page design at this link: The code is still a work in progress, so bear with me as I test out some functions and scripts. At the end of the first section, there are 4 logos that, when clicked, will trigger a modal to pop u ...

Display and conceal DIV Class from separate webpage document

I currently have two PHP files: index.php show.php - index.php <ul> <li><a href="show.php?id=1">Show Div 1</a></li> <li><a href="show.php?id=2">Show Div 2</a></li> <li><a href="show ...

Internal Anchors malfunctioning on a stationary parallel site

Struggling to implement a scroll-down feature upon click <a href="#scrollto" id="scroll"> <div class="arrow-down"><img class="arrow-open" src="assets/img/arrow-sm.png"></div><a/> directing to: <p id="scrollto">MadHous ...

Spacing applied to content within a fresh Vue application

Having been assigned the task of developing a Vue page for my team, I am facing an issue with a persistent white border surrounding the entire page. <script setup lang="ts"> </script> <template> <body> <div>&l ...

Does adding !important to the @font-face rule validate it?

Can anyone help me with a problem I'm facing? I want to ensure that users are forced to use the web font instead of the font installed on their computers because the formatting is slightly different. I've looked into using !important but I'm ...

Jquery Parallax Scrolling - Dynamic Multi-Directional Effect

My client is looking for a multi-directional JQuery parallax page, similar to this example - I have the necessary artwork and discovered various jQuery libraries that support horizontal and vertical scrolling separately. However, I am struggling with comb ...

Guide to implementing multiple CSS files in Django template inheritance

Seeking a solution for incorporating multiple CSS files for different templates using Django template inheritance. Currently, I have extended my base.html template with another app's template. Now, I want to use separate CSS files for each app's ...

Using CSS within the HTML code is effective, however, linking to an external CSS file is not working

I require assistance. This situation is absolutely absurd. Currently, I am utilizing Komodo IDE version 7.1.2 and Firefox version 15.0.1. The HTML5 file that I created looks like this: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" ...