How to set div to be suspended using css

WBOY
Release: 2021-11-15 10:43:57
Original
11807 people have browsed it

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.

How to set div to be suspended using css

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.

How to set div to be suspended using css

#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.

How to set div to be suspended using css

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.

How to set div to be suspended using css

4. Open the test.html file in the browser to check the effect.

How to set div to be suspended using css

#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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!