Get the App
SLTechnology News&Howtos  ›  Development  › 

How css uses line-height and text-align:center to center pictures horizontally and vertically

Shulou Source: shulou.com Published: 2022-06-01 03:10:13 10月03日 Update

This article mainly introduces how css uses line-height and text-align:center to achieve the horizontal and vertical center of the picture, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.

Line-height and text-align:center realize the horizontal and vertical center of the picture

Setting the value of line-height to be equal to height can achieve vertical centering and text-align:center can achieve horizontal centering. The CSS code is as follows:

Div {text-align:center; width:400px; height:200px; line-height:200px; border:greensolid1px;} img {vertical-align:middle;}

Html Code:

Thank you for reading this article carefully. I hope the article "how css uses line-height and text-align:center to center pictures horizontally and vertically" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Level articles pictures code value interest at the same time more friends knowledge editing industry information information channels channels reference learning help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple Microsoft Shulou Technology Shulou Information