標籤:前端 can div flow com pos abs end off
看到這個,你有什麼想法?
Difference between static and relative positioning
如果你能完全看明白,那幾本上css 元素定位的東西基本都會了。本文也不用往下看了。
自己接觸web這麼多年,雖說前端有接觸過,但還是沒有系統地學習過,和完整的實踐過。很多東西是似懂非懂。其實這裡就是問題的關鍵所在。
似懂非懂,其實本質上是不懂的。但是卻又自以為懂, 這就是自己給自己設定了個障礙,這個障礙看似無形卻比有形的障礙更可怕。因為每個人似乎
總是自以為是的認為自己認定的東西就是對的。因此很難,放空或者說歸零, 來從頭開始系統完整的學習一個新的東西。造成對新事物的理解總是停留
在陳舊的水平,故步自封。否定也許是進步的開始!!
------------------------------------------------------------------------------------------------
Static positioning is the default positioning model for elements. They are displayed in the page where they rendered as part of normal HTML flow. Statically positioned elements don‘t obey left, top, right and bottom rules:
Relative positioning allows you to specify a specific offset (left, top etc) which is relative to the element‘s normal position in HTML flow. So if I have a textbox inside a div I could apply relative positioning on the textbox to have it display at specific place relative to where it would normally be placed within the div:
There is also absolute positioning - whereby you specify the exact location of the element relative to the entire document, or the next relatively positioned element further up the element tree:
And when a position: relative is applied to a parent element in the hierarchy:
Note how our absolutely-position element is bound by the relatively-positioned element.
And lastly there is fixed. Fixed positioning restricts an element to a specific position in the viewport, which stays in place during scroll:
You may also observe the behaviour that fixed-positioned elements do not cause scroll because they are not considered to be bound by the viewport:
Whereas absolutely-positioned elements are still bound by the viewport and will cause scrolling:
..unless of course your parent element uses overflow: ? to determine the behaviour of the scroll (if any).
With absolute positioning and fixed positioning, the elements are taken out of HTML flow.
html 元素定位position-relative, absolute, fixed, static