Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to align one digit number to be on the middle of the below two digit numbers with html and css

Having the following code snippet:

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<div><p class='mb-2'>This is the title!</p>
<div>
  <p><span>5</span> <i class='fa fa-sort-down'></i><span> = this is some text</span></p>
  <p><span>24</span> <i class='fa fa-sort-down'></i><span>  = this is another text over here</span></p>
  <p><span>31</span> <i class='fa fa-sort-down'></i><span> = the same</span></p>
</div>
</div>

As it can be seen in the code, 5 is exactly above 2. It must be above 24, like in the middle, between them.

I’ve tried to add display flex to the span and then aling-items or aling-self and set it to center but didn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any suggestions

>Solution :

What about making all spans the same width and then centering the text inside those spans (you’ll need to set display: inline-block; to set the span width):

.number{
  display: inline-block;
  width:18px;
  text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<div><p class='mb-2'>This is the title!</p>
<div>
  <p><span class="number">5</span> <i class='fa fa-sort-down'></i><span> = this is some text</span></p>
  <p><span class="number">24</span> <i class='fa fa-sort-down'></i><span>  = this is another text over here</span></p>
  <p><span class="number">31</span> <i class='fa fa-sort-down'></i><span> = the same</span></p>
</div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading