Home > Web Front-end > HTML Tutorial > Why is absolute positioning rarely used in DIV CSS layout? _html/css_WEB-ITnose

Why is absolute positioning rarely used in DIV CSS layout? _html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:12:58
Original
1318 people have browsed it

例如下边的 绝对定位不是很好用吗?干嘛非得用 #id{float:left;}这样的浮动?可能是我觉得浮动不太好控制吧,当然 用绝对定位不是不可以的这我知道。可是为什么大都是用浮动的呢?<html> <title>无标题文档</title> <style type="text/css"> <!-- #apDiv1 {     position:absolute;     left:484px;     top:104px;     width:151px;     height:81px;     z-index:1; } --> </style> </head>  <body> <div id="apDiv1"></div> </body> </html>
Copy after login


Reply to discussion (solution)

Who said absolute positioning is rarely used?
In addition, the code you show is not compatible with all browsers.
You must add position:relative;
to the body, html{position:relative;}, which is the parent of absolute positioning; otherwise, according to your needs, you have to change position:absolute; to position:fixed;

Lan Rani? ? The poster looks like a newbie at first glance, right? ? Floating is easy to control? ? You go ask those veterans whether the float is easy to control. Maybe you have been searching for potential problems for a week and still haven’t found out where the problem lies.

It’s not that there are very few. Specific problems will be analyzed in detail. , see which one is simpler to use and easier to solve compatibility
position:absolute; It is best to set position:relative for the label of its relative position

I don’t think there are very few

Learned

It doesn’t matter what you use for layout, what’s important is that it should be easy to use.
It also depends on your team’s habits or other needs.


The poster can download several foreign xhtml css templates, many of which use position for layout.

Browsers are different

Use absolute positioning. If you change the screen resolution, the position of things in the web page will be offset

I have always used absolute positioning without floating, but Absolute positioning will break away from the document flow and is not conducive to the layout of the entire page. If you want the page to automatically stretch according to the content, you cannot use absolute positioning

Depending on the actual situation, fixed will occasionally change the shape, and floating control More difficult.

After studying positioning thoroughly, I can apply it freely. static (default) relative absolute fixed is very useful.

I basically use floating, and only the pop-up layer uses positioning

The biggest disadvantage of absolute positioning is that a lot of code needs to be rewritten when the browser resizes. Relatively speaking, absolute position compatibility is better.

Floating things are not easy to use, go and see for yourself. .

It is recommended that you take a look at the <> Advanced Web Standard Solution, which explains the various methods of position. Absolute positioning is easy to control, but once you change the layout, it may cover other elements, making maintenance more cumbersome. If you want to write a good page, fluid layout is recommended.

Floating layout is easier to maintain later

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