Home  >  Article  >  Web Front-end  >  How to make div fixed with css

How to make div fixed with css

WBOY
WBOYOriginal
2021-12-02 15:16:254629browse

In CSS, you can use the position positioning attribute to make the div fixed. This attribute is used to specify the positioning type of the element. When the value of the attribute is "fixed", a fixed positioning element is generated. The position of the element is fixed relative to the browser. No change, the syntax is "div{position:fixed;}".

How to make div fixed with css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

How to fix the div in css

In css, you can use the position positioning attribute to fix the position of the div on the page. The following example explains how to fix the position of div with css.

The example is as follows:

<html>
<head>
<style type="text/css">
div{
position:fixed;
left:5px;
top:5px;
width:50px;
height:50px;
background-color:red;
}
</style>
</head>
<body>
    <div></div>
<br/>
<br/><br/><br/><br/><br/><br/><br/><br/><bbr/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><brr/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>sergsergsgs<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></><br/><br/>
</body>
</html>

Output result:

How to make div fixed with css

(Learning video sharing: css video tutorial)

The above is the detailed content of How to make div fixed with css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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