The troublesome problem with CSS is vertical centering. There are several ways to achieve vertical centering, but each method has certain limitations, so vertical centering can be used according to actual business scenarios.
1. The content in the container is only one line of text
测试
2. The container is natural Height
The simplest vertical centering method in CSS is to give the container equal top and bottom padding, allowing the container and content to determine their own height. See the example below, which vertically centers the content in the parent container by settingpadding-top
andpadding-bottom
to equal values.
测试
3. Use FlexBox
测试
Recommended: "2021 CSS Interview Questions Summary (Latest)》
The above is the detailed content of CSS element vertically centered. For more information, please follow other related articles on the PHP Chinese website!