"."/> ".">
Home > Article > Web Front-end > How to set the fixed position of div in html
In HTML, you can add the "position:fixed;" style to the div element and set it to fixed positioning, so that the div position can be fixed unchanged. The syntax is "
".The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.
htmlHow to set the fixed position of div to remain unchanged
In html, you can use the style attribute to set the position to specify the positioning type of the element. You only need to Its value is set to fixed, which means that absolutely positioned elements are generated and positioned relative to the browser window. That is, the fixed position remains unchanged.
Let’s take an example to see how to fix the position of a div. The example is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div style="width:100%; height:100px; background:red; position:fixed; bottom:0;">这是一个固定在底部的div</div> </body> </html>Output result:
In the above example, the div is fixed at the bottom, just add the position:fixed style to the div element through the style attribute.
Recommended tutorial: "html video tutorial"
The above is the detailed content of How to set the fixed position of div in html. For more information, please follow other related articles on the PHP Chinese website!