简体   繁体   English

向绝对的初学者解释相对和绝对定位?

[英]explain relative and absolute positioning to an absolute beginner?

Can you please relative and absolute positioning to me,I don't understand what they mean by both terms. 你能取悦我的亲戚和绝对定位吗,我不明白这两个词的意思。 I just want to get an alternative explanation and the run it through my own understanding to see if I am right. 我只是想得到另一种解释,并通过我自己的理解来运行它,看看我是否正确。

Just watch this video: 观看此视频:

http://www.cssreset.com/understanding-css-relative-and-absolute-positioning-explained/ http://www.cssreset.com/understanding-css-relative-and-absolute-positioning-explained/

Should solve the issue once and for all. 应该一劳永逸地解决问题。

You can try this tutorial: 你可以试试这个教程:

http://www.barelyfitz.com/screencast/html-training/css/positioning/ http://www.barelyfitz.com/screencast/html-training/css/positioning/

It is clearly explained what is relative and absolute positioning in small steps one at a time. 它清楚地解释了一次一个小步骤的相对和绝对定位。

  • Let's start with position: static; 让我们从position:static开始; Static is the default, so if nothing is specified, the element is static. 静态是默认值,因此如果未指定任何内容,则该元素是静态的。 It is the normal flow of elements on the page. 它是页面上正常的元素流。 For example when the element does not fit on the line, it goes to the next line. 例如,当元素不适合该行时,它将转到下一行。

  • Then we have position: relative; 然后我们有位置:亲戚; Think of this as relative to its own position. 可以认为这与其自身的立场相关。 Now we can use left, right, top and bottom to shift the element from its original position. 现在我们可以使用left,right,top和bottom将元素从其原始位置移开。

  • Also, when setting an element's position to relative, the origin of any absolute child elements, is reset. 此外,当将元素的位置设置为relative时,将重置任何绝对子元素的原点。 In other words, position (0,0) of an absolute child element is the same as the relative parent. 换句话说,绝对子元素的位置(0,0)与相对父元素的位置相同。

  • The next one is position: absolute; 下一个是位置:绝对; The element is now outside the normal flow of elements on the page. 该元素现在位于页面上正常的元素流之外。 The position is measured from the origin of the first relative parent found. 该位置是从找到的第一个相对父母的原点开始测量的。 If no such parent is found, its position will be relative the the browser window, which is the same as position: fixed; 如果没有找到这样的父级,它的位置将相对于浏览器窗口,这与position:fixed相同;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM