html - CSS divs don't align correctly -


that's simplified code have 1 absolute div 4 relatives divs inside 4 columns. why inside divs don't align top of external div?

p.s.: know there's other ways make real code more complex , that's kind of solution need.

<div style="position: absolute; top: 100px; left: 100px; width: 800px; height: 400px; background-color: red; margin: 0; padding: 0;">    <div style="position: relative; display: inline-block; height: 100%; width: 25%; background-color: blue;">      <p>1</p>      <p>2</p>      <p>3</p>      <p>4</p>    </div><div style="position: relative; display: inline-block; height: 100%; width: 25%; background-color: yellow;">      <p>1</p>      <p>2</p>    </div><div style="position: relative; display: inline-block; height: 100%; width: 25%; background-color: green;">      <p>1</p>      <p>2</p>      <p>3</p>      <p>4</p>      <p>5</p>    </div><div style="position: relative; display: inline-block; height: 100%; width: 25%; background-color: pink;">      <p>1</p>      <p>2</p>    </div>  </div>

because inline elements have vertical alignment set baseline default. change top:

div > div {      vertical-align:top;  }
<div style="position: absolute; top: 100px; left: 100px; width: 800px; height: 400px; background-color: red; margin: 0; padding: 0;">      <div style="position: relative; display: inline-block; height: 100%; width: 25%; background-color: blue;">          <p>1</p>          <p>2</p>          <p>3</p>          <p>4</p>      </div><div style="position: relative; display: inline-block; height: 100%; width: 25%; background-color: yellow;">          <p>1</p>          <p>2</p>      </div><div style="position: relative; display: inline-block; height: 100%; width: 25%; background-color: green;">          <p>1</p>          <p>2</p>          <p>3</p>          <p>4</p>          <p>5</p>      </div><div style="position: relative; display: inline-block; height: 100%; width: 25%; background-color: pink;">          <p>1</p>          <p>2</p>      </div>  </div>

and if want parent container div encompass children divs, add overflow:auto.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -