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
This is an article about website usability. The a...
When changing the time zone under Linux, it is al...
This article shares the specific code of uniapp t...
Method 1: INSERT INTO t1(field1,field2) VALUE(v00...
Table of contents From father to son From son to ...
Detailed explanation of the implementation method...
This article will discuss these 4 principles as t...
Table of contents 1. We found that this website m...
Table of contents 1. What is Javascript? 2. What ...
Container auto-start Docker provides a restart po...
Preface An index is a data structure that sorts o...
If you only want to back up a few tables or a sin...
Introduction There is no need to introduce Redis ...
Table of contents 1 Test Cases 2 JS array dedupli...
MySQL 8 Windows version zip installation steps (d...