In CSS, you can use the position attribute to set absolute positioning to achieve div floating. You only need to add "{position:absolute;top: distance from the top of the page; left: distance from the left side of the page;} to the div element. "Style is enough.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
How to set div suspension in css
1. Create a new html file and name it test.html to explain how to make it work in CSS div is suspended. In the test.html file, use the div tag to create a div, and set its class attribute to con, which is mainly used to set the style through the class name below.
#2. In the test.html file, use the p tag in the div to create a display of test text. In the test.html file, within the div, use the div tag to create a div with a class name of ff, which is used as a suspended div.
3. In the test.html file, in the css tag, use "*" to initialize the element style and set the outer margin and inner margin to 0. At the same time, set the style of the div with the class name con, set its background color to gray, center alignment, width to 640px, and height to 1000px.
In the css tag, set the style with the class name ff, set its height and width to 100px, and the background color to red. Use the position positioning attribute to set the absolute position of the div on the page, 20px from the top of the page. , the distance from the left side of the page is 0px, so that the div can be suspended in the page.
4. Open the test.html file in the browser to check the effect.
#In addition to setting position to position, position can also be set to fixed to achieve div suspension.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of How to set div to be suspended using css. For more information, please follow other related articles on the PHP Chinese website!