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
Table of contents Optimizing sorting queries Avoi...
This article example shares the specific code for...
In HTML and CSS, we want to set the color of a bu...
Data Type: The basic rules that define what data ...
In the past, I used to directly order by rand() t...
1: Differences in speed and loading methods The di...
In HTML, the Chinese phrase “學好好學” can be express...
What is MIME TYPE? 1. First, we need to understan...
Docker Compose Docker Compose is a tool for defin...
Table of contents 1. One-way value transfer betwe...
This article mainly introduces the method of CSS ...
Table of contents Docker deployment Always on clu...
Table of contents 1. Basics of audio playback in ...
The img tag in XHTML is so-called self-closing, w...
Table of contents background What is tablespace f...