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 width-to-height ratio layout with CSS

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces CSS how to achieve width-to-height ratio layout related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this CSS how to achieve width-to-height ratio layout article, let's take a look.

Width is twice the height (proportional scaling)

Implementation idea: based on the parent element, the child width:100%; (that is, 100% of the parent width) and padding-top:50% (that is, 50% of the parent width. According to the css specification, if padding is expressed as a percentage, padding: 100% is equal to the width of the parent element)

Why not directly `width: 50%; height: 50% investors?

Then the height becomes 50% of the parent's height (undesirable, unless the parent's width and height are equal).

Original title:

The red block element is vertically centered in the center of the screen.

The red block-level elements are 20px away from the left and right edges of the screen.

The content in the red block level element is centered horizontally and vertically.

The height of the red block-level element is always 50% of the width of the red block-level element.

The aspect ratio of the red part is 2:1

Source code:

The aspect ratio is fixed. Overflow: hidden; position: absolute; left: 10px; right: 10px; top: 50%; transform: translateY (- 50%); background-color: # 0c8ac5;} .son {width: 100%; padding-top: 50% Background-color: # c03035;} span {position: absolute; top: 50%; left: 50%; transform: translate (- 50%,-50%); font-size: 20px; color: # D8D8D8;} img {float: left Margin-right: 10px; border: 2px solid # fdf6e3;}

Wang Ye, a disciple of Wudang School (who has now left Wudang), the heir to Feng Hou Qimen, one of the eight wonders, realized the way of Heaven by divination, but made the choice to join the troubled times. The appearance of a warm and good appearance, modest and courteous as warm water, things are often listless, do not seem to wake up. Leisurely and soft-tempered, it often means making concessions with an apologetic smile. He doesn't seem to care about anything, he looks like a leisurely Taoist, but he is unequivocal when it comes to the safety of his family, and has even made an uncool move about it. The strength of a monk who accidentally made an apology by paying homage to his ancestors was even the best among the younger generations. for the time being, there was only one completely unexpected capsizing in the sewer. This is the end of the article on "how to achieve width-to-height ratio layout in CSS". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to achieve breadth and higher level than layout of CSS". If you still want to learn more knowledge, you are 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

Internet Technology

Wechat

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

12
Report