When designing H5 layout, you will usually encounter banners. For example, if you want to display it as 2:1, of course the picture returned by the backend should be 2:1, but things are often not so satisfactory, so what should we do? It always feels inappropriate to write the width and height in a fixed way Default width: 100%; let the height be adaptive and the image will slowly expand (the product manager will say that this is a bad user experience, but I am a user and I think it is good) The method is here .banner-wrapper { position: relative; width: 100%; padding-top: 50%; } .banner { position: absolute; left: 0; top: 0; width: 100%; height: 100%; } <div class="banner-wrapper"> <img class="banner" src="./img/portfolio/cabin.png" alt=""> </div> Let me explain padding-top: 50%; is the key. Using percentages to write padding is relative to its width (don’t ask me why this is the case). So width: 100%; padding-top: 50%; will perfectly present a 2:1 box Finally, put the entire img on Don’t you think it’s very simple to use after finishing the work? The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: Installation and deployment of MySQL Router
>>: Use personalized search engines to find the personalized information you need
I have written such an article before, but I used...
We simply need to open any text editor, copy the f...
When we make a gradient background color, we will...
<br />It has been no more than two years sin...
The Document Object Model (DOM) is a platform, a ...
Preface This article mainly introduces the releva...
There is a table student in the mysql database, i...
When using Flex layout, you will find that when a...
Scenario A recent requirement is an h5 page for m...
When playing music, the lyrics will gradually fil...
Table of contents 1. df command 2. du command 3. ...
The principle of uploading pictures on the front ...
Preface To solve the single point of failure, we ...
To search for RocketMQ images, you can search on ...
Need to export the fields and properties of the t...