This article introduces the method of using CSS3 transform to change the fixed positioning of child elements to absolute positioning. I would like to share it with you and also leave a note for myself for easy searching. <!DOCTYPE html> <html> <head> <style> body { background: #f60; // orange} .parent { position: fixed; width: 300px; height: 300px; right: 0; top: 0; background: #02bd00; // green transform: translateX(0); } .child { position: fixed; left: 0; right: 0; top: 0; bottom: 0; background: rgba(0,0,0,0.2); // black transparent: mask} </style> </head> <body> <div class="parent"> <div class="child"></div> </div> </body> </html> It is not easy to find the cause of the problem for students who have never encountered it. Here is a picture to show the effect (only the green part is masked, but we may think that there is nothing wrong with our writing.) In fact, if we want the full-screen effect of the sub-element, we need to set transform: none; The problem is quite typical: Setting a valid transform attribute on the parent element will cause the child element to be fixed as an absolute element, which will cause the child element to be the same size as the parent element. At this time, the offsetTop and offsetLeft of the child element are both 0, which requires attention. This is the end of this article about how to use CSS3 transform to change sub-element fixed positioning to absolute positioning. For more relevant CSS3 transform sub-element fixed content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope that everyone will support 123WORDPRESS.COM in the future! |
<<: Serial and parallel operations in JavaScript
>>: A detailed introduction to seata docker high availability deployment
Table of contents 1. Concurrent access control 2....
Table of contents Proxy forwarding rules The firs...
Table of contents 1. What is syntactic sugar? 2. ...
Nginx's rewrite function supports regular mat...
Table of contents Component Communication Introdu...
This article shares the MySQL 5.7.16 free install...
If you think the system is slow and want to chang...
use <div id="app"> <router-lin...
This article originated from the homework assignm...
In the front-end design draft, you can often see ...
This article shares the specific code for JavaScr...
<br />Tips for making web table frames. ----...
This article records the installation tutorial of...
CSS: Copy code The code is as follows: html,body{ ...
Introduction Binlog logs, that is, binary log fil...