Home>Article>Web Front-end> CSS element vertically centered

CSS element vertically centered

autoload
autoload Original
2021-04-06 16:04:03 1523browse

CSS element vertically centered

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-topandpadding-bottomto 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does skew mean in css Next article:What does skew mean in css