How does the vertical-align property work?

后端 未结 2 615
北荒
北荒 2020-11-27 08:48

I do not understand when vertical-align will and won\'t work.

Every time I run into a use case for vertical-align it seems to be a coin tos

2条回答
  •  一整个雨季
    2020-11-27 09:01

    Simply said: vertical-align is only active/valid when the element it is applied to has display: inline-block or ìnline, which for example is useful if you want to align a bunch of images at their top border: You define them as inline-blocks and apply vertical-align: top to them

    Here is an example:

    .wrapper {
      height: 250px;
      border: 1px solid green;
    }
    
    .wrapper>img {
      display: inline-block;
      vertical-align: top;
    }

    In your fiddle, the elements are nested into each other, not next to each other, i.e. they are not siblings - there is only one child element each, so there is no alignment of siblings like in the example above.

提交回复
热议问题