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

Set text on the same y-aligment line

I’m sorry for the question but I am new to React JS. I’ve been stuck on this problem for hours.

This is my Header.js

  <div className="navbar-inner">
      <h2>Text1</h2>
      <h3>Text2</h3>
  </div>

This is my Header.css file:

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

.navbar-inner {
   margin: 0 auto;
   color: #fff;
   display: flex;
   width: 87vw;
   background-color: red;
   justify-content: space-between;
   vertical-align: sub;
}

This is what is shown:

enter image description here

I would like Text1 and Text2 to be aligned on the same y-line:
enter image description here

>Solution :

align-items is what you need for vertically aligning text when using flex box.

I also removed the margin from the h2 and h3 elements (it is there by default).

.navbar-inner {
   margin: 0 auto;
   color: #fff;
   display: flex;
   width: 87vw;
   background-color: red;
   justify-content: space-between;

   /* New styles */
   align-items: flex-end;
   padding: 5px;
}

h2, h3 {
  margin: 0;
}

You will probably need to adjust the padding to align it how you actually want it in terms of how close the text should be to the edges.

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