The impact of CSS3 transform on HTML document flow
html It's always so surprising
Comes from "Hardware Acceleration"
A note from the beginning of the year, compiled in my spare time.
Many online articles suggest turning on the hardware acceleration of the browser, so that the page rendering speed and animation fluency will be improved. This has almost become a standard configuration for many people's page production, regardless of whether it is actually useful or not:
html,body { transform: translate3d(0,0,0); }
But in many cases it will cause "abnormalities" in the html-level document flow.
The W3C spec has the following description:
In the HTML namespace, any value other than none for the transform results in the creation of both a stacking context and a containing block.
The object acts as a containing block for fixed positioned descendants.
means:
In HTML, there is no comparison to a DOM that is both a stacked object and a container blocktransform
Transformation is even more meaningless.
This type of object also plays the role of positioned
(mainly absolute/fixed) descendant element container.
. . . My translation ability is limited, and those who don’t understand it may be even more confused after reading this sentence. Details below.
Standard document flow
The DOM elements in the page are arranged from top to bottom and from left to right according to the order of their tag positions in HTML
I believe everyone is already familiar with this basic definition. But how does this translate into practice?
If you place a lot of display: inline-block
elements on the page, they will behave very nicely Up-> Bottom Left- > Right is arranged neatly. This is the basic embodiment of Standard Document Flow
.
When you use position
, float
and other attributes to separate it from the document flow, another concept of page level
will be generated. (I’m going too far...)
transform changes the default positioning attribute
The example code is as follows:
<header>header</header> <p></p> <footer>footer</footer>
Click to view the example
Default positioning of the dom element The attribute is position: static;
This is also the standard positioning method of the standard document flow.
In the example, no matter how p scrolls up and down, the header and footer will always be placed at the top and bottom of the screen.
But as originally mentioned, add a transform: translate3d(0,0,0);
to body
or html
, you If you try again, you will find that the two elements originally position: fixed;
are no longer obedient and will scroll with the screen.
Actually, the reference object of position: fixed;
is not what everyone calls the screen, but a viewport
html object, generally a page (document.documentElement
) will generate a viewport.
You can use document.documentElement.clientHeight
to see the actual height of the viewport, in which fixed
elements are positioned using this as the container. After adding the
attribute to body (or html), the entire
body
DOM will undergo corresponding transformations, but the "whole" at this time only refers to the body Under the standard document flow elements, for those position: absolute;
/ position: fixed;
elements, because they have been separated from the document flow to which the body belongs, they cannot rely on the transformation of the body to make themselves Naturally achieve the corresponding transformation effect.
At this time, in order to make corresponding changes to this type of DOM, the browser will generate a new viewport. This viewport exists as a container for positioning elements and will respond to the transform
transformation effect of the body. , so that those positioned
elements that are out of the document flow can also be transformed.
This viewport will seriously affect the positioning of position: fixed;
. When it scrolls synchronously with the "self" dom, it will roll with the fixed
element. , a strange effect similar to absolute
will be produced: the
fixed
element seems to become absolute
, existing between a and document.documentElement
In an "invisible" container of the same size.
Extended Situation
On some mobile devices (or APPs), the playback of the <video></video>
tag is enabled by default and hard decoding will also occur at this time. Due to the above phenomenon, the video will "float" on the page and will not scroll normally with the page elements.
A similar situation will also occur on some low-version mobile browsers. You can try to solve it according to this idea.
Summary
In fact, the above situation will not only happen to body
, any dom will produce a viewport-like viewport after adding transform
If you are interested, you can try it.
Quote:
http://www.php.cn/
html Always so amazing
From "Hardware Acceleration"
A note from the beginning of the year, compiled in my spare time.
Many online articles suggest turning on the hardware acceleration of the browser, so that the page rendering speed and animation fluency will be improved. This has almost become a standard configuration for many people's page production, regardless of whether it is actually useful or not:
html,body { transform: translate3d(0,0,0); }
But in many cases it will cause "abnormalities" in the html-level document flow.
The W3C spec has the following description:
In the HTML namespace, any value other than none for the transform results in the creation of both a stacking context and a containing block.
The object acts as a containing block for fixed positioned descendants.
means:
In HTML, there is no comparison to a DOM that is both a stacked object and a container blocktransform
Transformation is even more meaningless.
This type of object also plays the role of positioned
(mainly absolute/fixed) descendant element container.
. . . My translation ability is limited, and those who don’t understand it may be even more confused after reading this sentence. Details below.
Standard document flow
The DOM elements in the page are arranged from top to bottom and from left to right according to the order of their tag positions in HTML
I believe everyone is already familiar with this basic definition. But how does this translate into practice?
If you place a lot of display: inline-block
elements on the page, they will behave very nicely Up-> Bottom Left- > Right is arranged neatly. This is the basic embodiment of Standard Document Flow
.
When you use position
, float
and other attributes to separate it from the document flow, another concept of page level
will be generated. (I’m going too far...)
transform changes the default positioning attribute
The example code is as follows:
<header>header</header> <p></p> <footer>footer</footer>
Click to view the example
Default positioning of the dom element The attribute is position: static;
This is also the standard positioning method of the standard document flow.
In the example, no matter how p scrolls up and down, the header and footer will always be placed at the top and bottom of the screen.
But as originally mentioned, add a transform: translate3d(0,0,0);
to body
or html
, you If you try again, you will find that the two elements originally position: fixed;
are no longer obedient and will scroll with the screen.
Actually, the reference object of position: fixed;
is not what everyone calls the screen, but a viewport
html object, generally a page (document.documentElement
) will generate a viewport.
You can use document.documentElement.clientHeight
to see the actual height of the viewport, in which fixed
elements are positioned using this as the container. After adding the
attribute to body (or html), the entire
body
DOM will undergo corresponding transformations, but the "whole" at this time only refers to the body Under the standard document flow elements, for those position: absolute;
/ position: fixed;
elements, because they have been separated from the document flow to which the body belongs, they cannot rely on the transformation of the body to make themselves Naturally achieve the corresponding transformation effect.
At this time, in order to make corresponding changes to this type of DOM, the browser will generate a new viewport. This viewport exists as a container for positioning elements and will respond to the transform
transformation effect of the body. , so that those positioned
elements that are out of the document flow can also be transformed.
This viewport will seriously affect the positioning of position: fixed;
. When it scrolls synchronously with the "self" dom, it will roll with the fixed
element. , a strange effect similar to absolute
will be produced: the
fixed
element seems to become absolute
, existing between a and document.documentElement
In an "invisible" container of the same size.
Extended Situation
On some mobile devices (or APPs), the playback of the <video></video>
tag is enabled by default and hard decoding will also occur at this time. Due to the above phenomenon, the video will "float" on the page and will not scroll normally with the page elements.
A similar situation will also occur on some low-version mobile browsers. You can try to solve it according to this idea.
Summary
In fact, the above situation will not only happen to body
, any dom will produce a viewport-like viewport after adding transform
If you are interested, you can try it.
For more related articles on the impact of CSS3 transform on HTML document flow, please pay attention to the PHP Chinese website!

I recently found a solution to dynamically update the color of any product image. So with just one of a product, we can colorize it in different ways to show

In this week's roundup, Lighthouse sheds light on third-party scripts, insecure resources will get blocked on secure sites, and many country connection speeds

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used

The document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its

What's happening when you see some JavaScript that calls super()?.In a child class, you use super() to call its parent’s constructor and super. to access its

JavaScript has a variety of built-in popup APIs that display special UI for user interaction. Famously:

I was chatting with some front-end folks the other day about why so many companies struggle at making accessible websites. Why are accessible websites so hard

There is an HTML attribute that does exactly what you think it should do:


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.