Home > Web Front-end > HTML Tutorial > How to set the fixed position of div in html

How to set the fixed position of div in html

WBOY
Release: 2021-11-25 11:41:54
Original
14691 people have browsed it

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 "

".

How to set the fixed position of div in html

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>
Copy after login

Output result:

How to set the fixed position of div in html

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template