Vertical Align Methods

后端 未结 5 1562
长发绾君心
长发绾君心 2020-12-21 04:52

What are the best methods to vertically-align something relative to it\'s elements dimensions. As of right now, I\'m only aware of vertical-align:middle;<

5条回答
  •  半阙折子戏
    2020-12-21 05:14

    A great place for you to start is this article by CSS Tricks. It goes over every value that vertical-align can have and the different uses of each in a clear concise way.

    Here are the options:

    vertical-align: baseline     /* keyword values */
    vertical-align: sub
    vertical-align: super
    vertical-align: text-top
    vertical-align: text-bottom
    vertical-align: middle
    vertical-align: top
    vertical-align: bottom
    

    And here are the valid options for table cells:

    baseline (and sub, super, text-top, text-bottom, , and )
    Align the baseline of the cell with the baseline of all other cells in the row that are baseline-aligned.
    top
    Align the top padding edge of the cell with the top of the row.
    middle
    Center the padding box of the cell within the row.
    bottom
    Align the bottom padding edge of the cell with the bottom of the row.
    

    Additionally, you may want to try some other tricks like setting the line-height equal to the parent container's height.

提交回复
热议问题