current position:Home>CSS realizes the square of adaptive screen width
CSS realizes the square of adaptive screen width
2022-04-29 08:11:49【A programmer who can only write bugs】
Ideas , Square , The length and width are the same , You need to find a standard value and then set the box model , It can be used padding,margin, width/height,
Begin with topic
1. Use padding, reason , The percentage is based on the width of the parent element , So if it's based on the percentage of the parent box , You can use this method
The specific code is as follows
<div class="square"></div>
.square {
display: inline-block;
padding: 0 20% 20% 0;
background: red;
}
- padding+flex, Suitable for making multiple squares , Using the same padding Open the box model , Make the height the same as the width
<div class="square-wrapper">
<div class="square"></div>
<div class="square"></div>
</div>
.square-wrapper {
display: flex;
}
.square {
flex: 1;
}
.square::after {
content: "";
display: block;
padding-bottom: 100%;
background: #000;
}
- The same principle can also be used to add... To internal elements margin To finish opening the box
.square-wrapper {
display: flex;
}
.square {
flex: 1;
background: #000;
}
.square::after {
content: "";
display: block;
margin-bottom: 100%;
}
- rem / em It's all the same value ,rem What you get is html Labeled font-size,em It's the parent element font-size, It is also fixed
- Use vw, Indicates that the width of the screen is cut into 100 Share , Then you can perfectly adapt to all kinds of screens ( The screen here refers to including this document Object's container , If it opens in the browser , Then it is the width that can be displayed inside the browser ; If in iframe Open in , Namely iframe Width )
.square {
width: 20vw;
background: #000;
}
.square::after {
content: "";
display: block;
padding-bottom: 100%;
// margin-bottom: 100%; // It's fine too
}
For the moment, I think of so much . If you have a better one , You can leave a message and tell me ~
copyright notice
author[A programmer who can only write bugs],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290558476195.html
The sidebar is recommended
- How does HTML5 display the value obtained from the database in the specified area
- Problems related to nginx rewriting interface
- What happens when you open a CSS file in eclipse without responding
- React download local template can be downloaded locally, but the deployment online download is blank
- @Babel / traverse official example running error: typeerror: traverse is not a function
- The click event of jQuery has no effect
- How to learn from non professional background?
- Usage of API documented as @since 1.8+ less... (Ctrl+F1) Inspection info: This inspection finds all
- Configuration Vue of webpack
- Introduction to nginx (learning notes)
guess what you like
Is the financial management class of qiniu school true? Can you learn how to manage money in free lessons
How does Java randomly get elements from a list
Use of Vue on in Vue
Use of Vue router
Vue basic syntax
Use of webpack
Vue diff algorithm
CSS -- Text gradient from top to bottom
Routing: Vue router
Leetcode 658. Find K closest elements
Random recommended
- How to configure Vue in Vue project config. JS to solve cross domain problems
- Centos6 makes nginx-1.21.6-rpm package -- the way to build a dream
- [vue2-sgg v] vuex
- [vue2-sgg vi] route Vue router guard
- [vue2-sgg VII] Vue export and deploy to nginx --- UI component library (element UI...)
- Chapter 12 Ajax
- Clion remote debugging ubutun server, blood lessons
- The latest vue-i18n international plug-in realizes language switching (with source code)
- Vue monitors watch usage
- Vue encapsulates Axios to the full version of the calling interface (code source code)
- Watch data monitoring in Vue and detailed explanation of various attributes in watch
- Vue encapsulates Axios to call interface Full Version (code source code) latest recommendation (II)
- Vue encapsulates Axios to the full version of the calling interface (code source code)
- Ajax usage based on JQ
- Vue project optimization
- Vue - form generator form code generation
- Data acquisition in vuex is assigned to the local problem, and when is vuex data assigned to the local problem
- The modal box component is encapsulated in Vue, and the animation effect in Vue
- Swiper, the application of swiper in Vue, and various versions of swiper are applied in Vue projects
- Python——ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org‘, port=443)
- Lesson 3 of ROS quick start - subscriber subscriber of ROS
- A lifeless face
- Mock in Vue JS preliminary simple use
- The Java Web servlet triggers the alert box on the front end
- CSS sets the color of the small vertical bar in front of the title
- Incomplete display of CSS background image
- [front end learning notes] save the front-end related codes
- Precautions for AWS serverless design dynamodb
- AWS serverless design - apigateway
- AWS serverless design lambda
- AWS serverless design - firewall WAF
- AWS serverless design-s3
- Python repeated element determination function program
- Nginx direction agent solves cross domain Problems-2
- The foundation of JavaScript
- DOM based on JavaScript
- Javascript based BOM
- Basic summary of JavaScript advanced
- Object oriented JavaScript
- JavaScript advanced threading mechanism and event mechanism