シェア
//Absolute, Relative, Fixed Positioning: How Do They Differ?

Absolute, Relative, Fixed Positioning: How Do They Differ?

Short answer: Yes, there is one more, “static”, which is the default. Yes, they majorly differ. Each of them is incredibily useful and which you should use of course depends on the desired result. Also, don’t forget about float, which is an important part of positioning.

Medium answer: I’m not going to do a “long answer” because there is no need to rewrite what has been written many times before, but I will do a “medium answer” here were we can quickly run through each type. I also sometime refer people to this10 step tutorial, which does a pretty good job of explaining it.

An important concept to understand first is that every single element on a web page is a block. Literally a rectangle of pixels. This is easy to understand when when you set the element to display: block; or if that element is by default display: block; This means you can set a width and a height and that element will respect that. But elements that are display: inline, like a span by default, are also rectangles, they just flow onto the page different, lining up horizontally as they can.

Now that you are picturing every single page element as a block of pixels, we can talk about how positioning is used to get the blocks of pixels exactly where you want them to go. We’re going to leave off any discussion of the box model, but that factors into this as well…

  • Static. This is the default for every single page element. Different elements don’t have different default values for positioning, they all start out as static. Static doesn’t mean much, it just means that the element will flow into the page as it normally would. The only reason you would ever set an element to position: static is to forcefully-remove some positioning that got applied to an element outside of your control. This is fairly rare, as positioning doesn’t cascade.
  • Relative. This type of positioning is probably the most confusing and misused. What it really means is “relative to itself”. If you set position: relative; on an element but no other positioning attributes (top, left, bottom or right), it will no effect on it’s positioning at all, it will be exactly as it would be if you left it as position: static; But if you DO give it some other positioning attribute, say, top: 10px;, it will shift it’s position 10 pixels DOWN from where it would NORMALLY be. I’m sure you can imagine, the ability to shift an element around based on it’s regular position is pretty useful. I find myself using this to line up form elements many times that have a tendency to not want to line up how I want them to.There are two other things that happen when you set position: relative; on an element that you should be aware of. One is that it introduces the ability to use z-index on that element, which doesn’t really work with statically positioned elements. Even if you don’t set a z-index value, this element will now appear on top of any other statically positioned element. You can’t fight it by setting a higher z-index value on a statically positioned element. The other thing that happens is it limits the scope of absolutely positioned child elements. Any element that is a child of the relatively positioned element can be absolutely positioned within that block. This brings up some powerful opportunities which I talk about here.
  • Absolute. This is a very powerful type of positioning that allows you to literally place any page element exactly where you want it. You use the positioning attributes top, left bottom and right to set the location. Remember that these values will be relative to the next parent element with relative (or absolute) positioning. If there is no such parent, it will default all the way back up to the <html> element itself meaning it will be placed relatively to the page itself.The trade-off, and most important thing to remember, about absolute positioning is that these elements are removed from the flow of elements on the page. An element with this type of positioning is not affected by other elements and it doesn’t affect other elements. This is a serious thing to consider every time you use absolute positioning. It’s overuse or improper use can limit the flexibility of your site.
  • Fixed. This type of positioning is fairly rare but certainly has its uses. A fixed position element is positioned relative to the viewport, or the browser window itself. The viewport doesn’t change when the window is scrolled, so a fixed positioned element will stay right where it is when the page is scrolled, creating an effect a bit like the old school “frames” days. Take a look at this site (update: dead link, sorry), where the left sidebar is fixed. This site is a perfect example for since it exhibits both good and bad traits of fixed positioning. The good is that it keeps the navigation present at all times on the page and it creates and interested effect on the page. The bad is that there are some usability concerns. On my smallish laptop, the content in the sidebar is cut off and there is no way from me to scroll down to see the rest of that content. Also if I scroll all the way down to the footer, it overlaps the footer content not allowing me to see all of that. Cool effect, can be useful, but needs to be thoroughly tested.

Credit: https://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/


今すぐ応募







    福利厚生

    給料・ボーナス制度

    社員の感情・願望を理解しているので、リバークレーンベトナムは特に年2回の定期昇給制度を設けています。毎年6月と12月に評価を行い、毎年1月と7月に給与が変更されます。また、社員は月次と年次の優秀な個人には定期的な業績賞与が別で支給されます。

    日本研修制度

    世界中の新しい技術分野に触れるために、社員を日本にオンサイトさせる方針があります。さらに、技術分野か管理分野かのキャリアパスは社員の決定次第です。

    毎年社員旅行

    リバークレイン・ベトナムは、スタッフに挑戦の機会を提供するだけでなく、年に一度の魅力的な旅行で彼らを楽しませています。エキサイティングなガラディナーやチームビルディングゲームは、リバークレインのメンバー同士の絆をさらに深める手助けをします。

    リバークレイン イベント

    チームビルディング・ファミリーデー・お夏休み・中秋節などのイベントはチーム内のメンバーが接続出来るしお互いに自分のことを共有出来る機会です。ご家族員に連携する際にはそれも誇りに言われています。

    社会保険制度

    リバークレーンベトナムは従業員に社会保険、医療保険、失業手当などの社会保険制度があります。当社は、これらの保険に関するあらゆる手続きをスタッフに必ずサポートしています。さらに、他の保険契約も考慮され、検討されています。

    他福利

    社員向けの活動をサポートすることもあります。 ・文化・芸術・スポーツクラブの運営費用 ・技術研究の教科書を購入する金額 ・エンジニア試験・言語能力試験を受験料 ・ソフトスキルのセミナー・コースの参加費 ・等 また会社政策通り、他のベネフィットもあります。

    © 2012 RiverCrane Vietnam. All rights reserved.

    Close