How to set a certain block to be fixed in css

藏色散人
Release: 2023-01-03 09:31:03
Original
2314 people have browsed it

How to set a certain div to be fixed in css: first create an HTML sample file; then define a div in the body; finally set the div to be fixed through attributes such as "position: fixed;".

How to set a certain block to be fixed in css

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, DELL G3 computer

css controls a certain div to be fixed

The most common way to fix it is to position it.

But you need to pay attention when positioning:

① If you want to fix it somewhere on the screen, then make sure the parent element of the fixed element is body;

② is Fixed elements set width and height.

For example, add the following code to your footer class:

<style type="text/css">
    .shopping_cart {
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 60px;
        background: #eee;
        z-index: 10;
    }
</style>
Copy after login

If the top is fixed

<style type="text/css">
  .editFrom {  ----div的选择器
    position: fixed; ----position样式
    left: 0; 
    top: 0; 
    width: 100%;
    height: 30%;  ---div占用位置的高度
    background: #eee;
    z-index: 10;--折叠级别
  }
</style>
Copy after login

[Recommended learning: css video tutorial]

The above is the detailed content of How to set a certain block to be fixed in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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