为什么 position: relative 使用 top 向下移动和 bottom 向上移动?
Why does position: relative use top to shift down and bottom to shift up?
为什么CSSposition: relative;
用bottom
上移,top
下移,left
右移,[=14] =]向左移动?
Fiddle: click me
我是不是用错了position: relative;
,或者这是我不知道的某种术语?
元素相对于其正常位置定位,因此 "left:20" 向元素的 LEFT 位置添加 20 个像素
find out more about the position property here (w3schools)
此外,您也可以使用负数,以便将元素向左移动 20px,您可以使用:
left:-20px
有点"terminology I was not aware of",用你自己的话来说。当你指定其中一个值时,你就是在指定你应该将它从那一侧远离移动多远。因此,例如,当您指定 top:10px
时,您说的是 "move it 10px away from the top"。我认为您只是误会了您认为它向那一边移动了,但实际上并非如此。这不仅适用于 position:relative
,它也适用于 absolute
、fixed
以及任何其他位置值
它工作正常。请阅读这篇文章 http://www.webdevdoor.com/html-css/css-position-child-div-parent 但请尝试更改位置值 ex 20,30,40 instead of 10
要理解这一点,首先让我们看一下position: relative
property/value。
直接取自w3schools:
An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.
一种理解方式是,当你设置一个属性比如left
到一个定位为relative
的元素时,你设置的值就是有多远离开它的正常位置。因此,将 left
的值设置为 20px
会将其从正常的 left
位置移动 20 像素 。正整数会将其移至右,负数将移至左。 Fiddle
或者,w3schools 说得更好:
For relatively positioned elements, the left property sets the left edge of an element to a unit to the left/right to its normal position.
我上面的描述可能不是白话正确的,但它帮助我在开始时理解它。
简单地说,它定位元素 x 指定方向的像素数量。
为什么CSSposition: relative;
用bottom
上移,top
下移,left
右移,[=14] =]向左移动?
Fiddle: click me
我是不是用错了position: relative;
,或者这是我不知道的某种术语?
元素相对于其正常位置定位,因此 "left:20" 向元素的 LEFT 位置添加 20 个像素 find out more about the position property here (w3schools)
此外,您也可以使用负数,以便将元素向左移动 20px,您可以使用:
left:-20px
有点"terminology I was not aware of",用你自己的话来说。当你指定其中一个值时,你就是在指定你应该将它从那一侧远离移动多远。因此,例如,当您指定 top:10px
时,您说的是 "move it 10px away from the top"。我认为您只是误会了您认为它向那一边移动了,但实际上并非如此。这不仅适用于 position:relative
,它也适用于 absolute
、fixed
以及任何其他位置值
它工作正常。请阅读这篇文章 http://www.webdevdoor.com/html-css/css-position-child-div-parent 但请尝试更改位置值 ex 20,30,40 instead of 10
要理解这一点,首先让我们看一下position: relative
property/value。
直接取自w3schools:
An element with position: relative; is positioned relative to its normal position.
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.
一种理解方式是,当你设置一个属性比如left
到一个定位为relative
的元素时,你设置的值就是有多远离开它的正常位置。因此,将 left
的值设置为 20px
会将其从正常的 left
位置移动 20 像素 。正整数会将其移至右,负数将移至左。 Fiddle
或者,w3schools 说得更好:
For relatively positioned elements, the left property sets the left edge of an element to a unit to the left/right to its normal position.
我上面的描述可能不是白话正确的,但它帮助我在开始时理解它。
简单地说,它定位元素 x 指定方向的像素数量。