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 have <div>'s on the same row/line HTML

I am trying to make it so one <div> is on the same line/row another <div> by default they just appear below each other. I have found out that this only happens when the text is multiple lines. Here is the code:

h1 {
  text-align: center;
}

h2 {
  text-align: left;
}

.info {
  text-align: left;
  font-size: 20px;
  float: right;
}

.content {
  align-self: auto;
  border: 1px solid black;
  color: gray;
  width: 150px;
  max-width: 150px;
  float: left;
}

.p1 {
  text-align: left;
  margin-left: 10px;
}
<h1>Good Health and Well being</h1>

<div class='info'>
  <h2><b>What do good health and well-being mean?</b></h2>
  <p>TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT</p>

  <h2><b>Why are good health and well-being so important?</b></h2>
  <p>TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT</p>

  <h2><b>How do you keep good health?</b></h2>
  <p>TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT</p>
</div>

<div class='content'>
  <h1>Content</h1>
  <p class='p1'>content</p>
</div>

Here is an image of it.

enter image description here

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

And here is an image when the text doesn’t use multiple lines:

enter image description here

Lastly here is an image of what i want

enter image description here

>Solution :

Reason this is happening is because that having multilines increases the width of your info div. It keeps on adjusting till it becomes (100%-150px) 150 being the width of your content div. Adding width to info will solve the issue , add the width such to give margin in between as I have updated the css.

h1 {
  text-align: center;
}

h2 {
  text-align: left;
}

.info {
  text-align: left;
  font-size: 20px;
  float: right;
  width: calc(100% - 200px) 
}

.content {
  align-self: auto;
  border: 1px solid black;
  color: gray;
  width: 150px;
  max-width: 150px;
  float: left;

}

.p1 {
  text-align: left;
  margin-left: 10px;
}
<h1>Good Health and Well being</h1>

<div class='info'>
  <h2><b>What do good health and well-being mean?</b></h2>
  <p>TEXT TEXT TEXT  TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT  TEXT TEXT TEXT TEXT TEXT </p>

  <h2><b>Why are good health and well-being so important?</b></h2>
  <p>TEXT TEXT TEXT TEXT TEXT  TEXT TEXT TEXT TEXT TEXT  TEXT TEXT TEXT TEXT TEXT  TEXT TEXT TEXT TEX </p>

  <h2><b>How do you keep good health?</b></h2>
  <p>T TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT  TEXT TEXT TEXT TEXT TEXT  </p>
</div>

<div class='content'>
  <h1>Content</h1>
  <p class='p1'>content</p>
</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