Earlier we talked about how to make a square with an adaptive width and height of 1:1 https://www.jb51.net/css/753385.html Now let's talk about how to make an adaptive 16:9 rectangle. The first step is to calculate the height. Assuming the width is 100%, the height is h=9/16=56.25% The second step is to use the padding-bottom method mentioned above to realize the rectangle <style> *{ margin: 0px; padding: 0px; } /* .wrap: The div that wraps the rectangle is used to control the size of the rectangle*/ .wrap{ width: 20%; } /* .box rectangular div, the width is 100% of .wrap, this is mainly to facilitate the calculation of height*/ .box{ width: 100%; /*Prevent the rectangle from being stretched to excess height by the content inside*/ height: 0px; /* 16:9 padding-bottom: 56.25%, 4:3 padding-bottom: 75% */ padding-bottom: 56.25%; position: relative; background: pink; } /* For the content inside the rectangle, you need to set position: absolute to set the content height to 100% the same as the rectangle*/ .box p{ width: 100%; height: 100%; position: absolute; color: #666; } </style> <body> <div class="wrap"> <div class="box"> <p> This is a 16:9 rectangle</p> </div> </div> </body> Similar rectangles of different proportions can be achieved in this way This concludes this article about how to use CSS to implement a 16:9 rectangle with adaptive width and height. For more information about CSS adaptive width and height, please search 123WORDPRESS.COM’s previous articles or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future! |
<<: Complete list of CentOS7 firewall operation commands
The complete code is as follows : HTML code: Copy ...
In MySQL database operations, we always hope to a...
【Foreword】 The SMS function of our project is to ...
Lambda Expressions Lambda expressions, also known...
Here is a text scrolling effect implemented with ...
This article records the complete uninstallation ...
When we use TypeScript, we want to use the type s...
1. Introduction Recently, I helped a friend to ma...
Install MySQL 8.0 docker run -p 63306:3306 -e MYS...
Mobile browsers place web pages in a virtual "...
Table of contents 1. Introduction to Harbor 1. Ha...
In fact, we have been hearing a lot about web des...
1. Run the .sh file You can run it directly using...
This article shares with you the graphic tutorial...
Recently, the business side reported that some us...