CSS element vertically centered

autoload
Release: 2021-04-15 13:59:41
Original
1508 people have browsed it

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

    
测试
Copy after login

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.

    
测试
Copy after login

3. Use FlexBox

    
测试
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!