Home > Article > Web Front-end > How to set a certain block to be fixed in css
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;".
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>
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>
[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!