1

I wrote CSS with vertical-align applied to one of these boxes.

Then, vertical-align, which is specified for only one side, is applied to the other element.

.a {
  height: 75px;
  width: 75px;
  background-color: red;
}

.a,
.b {
  display: inline-block;
}

.a {
  vertical-align: middle; /* vertical-align applied to .a also affects .b */
}
<div class="a"></div>
<div class="b">
  <p>texttttt</p>
</div>

Why does setting the vertical-align on one side affect the other side?

1 Answers1

0

vertical align for inline elements works for aligning inline elements based on each other as your example says a will be centered in the middle with the element b not based to their parents height.

if you want to align b vertically based on a position you have to add a vertical align property to b

.b{
  vertical-align: top;

}

for a side note to see a proper results and understand it better you should reset the default margins on the p tag

p{
  margin:0;
}
Ahmd Rmdan
  • 26
  • 3