1. Percentage basis for element width/height/padding/margin When setting the percentage of an element's width/height/padding/margin, do you know what the benchmark is? For example: .parent { width: 200px; height: 100px; } .child { width: 80%; height: 80%; } .childchild { width: 50%; height: 50%; padding: 2%; margin: 5%; } <div class="parent"> <div class="child"> <div class="childchild"></div> </div> </div> In the above code, what is the width of the childchild element? What is height? What is the padding? What is the margin? The height percentage of an element is based on the height of its parent element, and the width, padding, and margin percentages of an element are based on the width of its parent element. From this, I believe everyone has already figured it out. You can try it out~ In interviews, you will often encounter a simple CSS style question, which is to implement an adaptive square. The principle is based on the above knowledge. Just need #box { width: 50%; padding-top: 50%; background: #000; } Because the base values of element width and padding are both the width of the parent element, and the width of the body is the browser window. So this setting will make the square adaptive as the browser window size changes. 2. Use pure CSS to achieve the effect of three-dimensional picture placement Now back to the topic, if you want to achieve the three-dimensional placement effect of the pictures shown in the following figure, you need to apply the knowledge of padding, width, and height. It looks a little familiar. Is it similar to the style of recommended books in novel software? Here, first let's look at its placement. One picture is horizontally centered and in the front, while the other two pictures are aligned left and right and a little further back, presenting a three-dimensional placement. Here I learned a way to achieve this three-dimensional effect by simply relying on CSS. The different heights are supported by padding-top, which is large or small. · The before and after effects are controlled by the z-index folding order. The arrangement is controlled by the nth-of-type pseudo-element + position. Do you have any idea? Let’s not beat around the bush and get straight to the code. <html> <head> <style> * { margin: 0; padding: 0; } .box { width: 300px; height: 200px; position: relative; } .img { width: auto; height: 0; } .box img { width: 100%; display: inline-block; } .box .img:nth-of-type(1) { display: inline-block; position: absolute; left: 50%; top: 50%; padding-bottom: 50%; transform: translate(-50%, -50%); z-index: 6; } .box .img:nth-of-type(2), .box .img:nth-of-type(3) { position: absolute; top: 50%; transform: translateY(-50%); padding-bottom: 63%; z-index: 3; } .box .img:nth-of-type(2) { right: 0; } .box .img:nth-of-type(3) { left: 0; } </style> </head> <body> <div class="box"> <div class="img"> <img src="https://febaidu.com/list/img/3ns.png" /> </div> <div class="img"> <img src="https://febaidu.com/list/img/3ns.png" /> </div> <div class="img"> <img src="https://febaidu.com/list/img/3ns.png" /> </div> </div> </body> </html> 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. |
>>: React internationalization react-i18next detailed explanation
3 ways to implement tab switching in Vue 1. v-sho...
Let me tell you about a recent case. A game log l...
HTML5 and jQuery implement the preview of local i...
CSS scroll bar style modification code .scroll::-...
1. Introduction to MMM: MMM stands for Multi-Mast...
Generally, on national days of mourning, days of ...
1. Basic structure of web page: XML/HTML CodeCopy...
This article shares the specific code of js to ac...
In the horizontal direction, you can set the row ...
Method 1: Please add the following code after <...
Table of contents Overview 1. Compositon API 1. W...
Table of contents Data Brokers and Events Review ...
Install Install ts command globally npm install -...
I knew before that to synchronously obtain the re...
The explain command is the primary way to see how...