Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize horizontal and Vertical centering in css

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces css how to achieve horizontal vertical center, the article introduces in great detail, has a certain reference value, interested friends must read it!

Suppose this scenario is given now:

DEMO

The length of the content in the class='child' div is not certain, and now you need to implement the center of the div.

Horizontal and vertical center

This only needs to be a combination of the first few, there are three common methods.

1 inline-block + table-cell.child {display:inline-block; text-align:left;} .parent {text-align:center; display:table-cell; vertical-align:middle;} / * child element text is inherited and centered, so write on it center to the left * / 2 absolute + transform.parent {position:relative;} .child {position:absolute; left:50%; top:50% / * the reference is the parent container * / transform:translate (- 50% justify-content.parent 50%); / * the reference of the percentage is itself * /} 3 flex + align-items + justify-content.parent {display:flex; justify-content:center; align-items:center;}. These are all the contents of the article "how to achieve horizontal and vertical center in css". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report