Get the App
SLTechnology News&Howtos  ›  Development  › 

An example of vertical centering of elements in a css line

Shulou Source: shulou.com Published: 2022-06-03 17:32:31 10月03日 Update

This article introduces the relevant knowledge of "the vertical center of elements in the css line". In the operation of the actual case, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. If the element in a single line is centered, you only need to make the row height of the child element equal to the height.

# container {height: 400px; background: pink;} # inner {display: inline-block; height: 200px; line-height: 200px;}

2, multi-line elements, the most is the use of table-cell. The representation of child elements is similar to that of inline elements, and child elements cannot occupy a single row.

.container {width: 200px; height: 400px; background: pink; position: absolute; display: table; vertical-align:middle;} .inner {display: table-cell; vertical-align:middle } this is the end of the introduction to "an example of vertical centering of elements in the css line". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Elements examples content more knowledge practicality achievement and then one line dilemma reality form situation article way case editing website industry process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology NVidia Apple OPPO Reno Huawei