为什么Float比位置更好:相对的和绝对的,而我们可以使布局快速与位置? [英] Why Float is better than position:relative and absolute while we can make layout quickly with position?

查看:137
本文介绍了为什么Float比位置更好:相对的和绝对的,而我们可以使布局快速与位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Float比位置更好:相对和绝对,而我们可以使用位置快速布局?在这个衰退时间,时间是非常重要的。



当我们做2-col,3-col或多重布局,然后在布局div中放置其他元素。



在Float大部分的世界青睐。为什么Float比 position:relative 位置:absolute < body> 和其他嵌套元素?



如果使用position:布局页面/设计,我们可以创建一个容器div,设置为position:relative,允许header,content和nav divs 在容器div内设置为position:relative,允许这些 divs 相对于容器div定位。



和定位我们可以保持maincontent第一和leftsidebar


解决方案

float 不会打破文档流程 - 它可以适应容器宽度 - 说我有一个800px宽度的容器中的5 x 200px divs,最后的5将在新行下面的其他人 - 使用 position:relative 将使你需要计算什么时候需要打破自己,并且它不会正确断开,因为显示将会是 block 并转到整个宽度,或者 inline-block inline 这将不会为divs以相同的方式为 block 将会和将会很麻烦的文档流&布局。



这取决于你想做什么: position:relative 用于移动元素除了它的自然位置,而 float 将使它弹出到父元素中最左边或最右边的位置。 position:absolute 将允许您相对于整个html文档定位。


Why Float is better than position:relative and absolute while we can make layout quickly with position? and in this recession time, time is very important.

when we make 2-col, 3-col or multi-col layout and then position other elements in layout divs.

Most of the world favor in Float . Why Float is better than position:relative and position:absolute to give position any element in <body> and other nested elements?

If using position: to layout a page/design, we can create a container div which is set to position:relative, allowing header, content and nav divs inside the container div to be set to position:relative, allowing these divs to be positioned relative to the container div.

and with positioning we can keep "maincontent" first and "leftsidebar" second in source order which is good for SEO.

please explain things with example demo page.

解决方案

float will not break the document flow -- also, it will position any element it uses the best it can fit in the container width -- say I have 5 x 200px divs in a 800px width container, the last 5th will go in a "new line" below the other ones -- using position:relative will make you need to calculate when it needs to break yourself, and it won't break correctly since the display will either be block and go over the whole width or it will be inline-block or inline which won't render the same way for divs as block would and would pretty much mess up the document flow & layout.

It depends on what you want to do: position:relative is used to move the element a bit aside from it's natural location, whereas float will make it pop to the left-most or right-most position in the parent element. position:absolute will let you position it relatively to the whole html document.

这篇关于为什么Float比位置更好:相对的和绝对的,而我们可以使布局快速与位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆