chaoguo1234

1). \'left\' 和 \'right\' 的设定值都是 "auto"

如果 \'left\' 和 \'right\' 的值都是 "auto" (它们的初始值),计算后的值( computed value )为 0(例如,框区留在其原来的位置)。

2). \'left\' 或 \'right\' 其一的设定值为 "auto"

如果 left 为 ‘auto’,计算后的值(computed value)为 right 的负值(例如,框区根据 right 值向左移)。 如果 right 被指定为 ‘auto’,其计算后的值(computed value)为 left 值的负值。

示例代码:

<div style="width:20px; height:20px; background-color:red; position:relative; left:100px;"></div>

上述代码中,DIV 元素是相对定位的元素,它的 \'left\' 值是 "100px", \'right\' 没有设置,默认为 "auto",那么,\'right\' 特性计算后的值应该是 -left,即 "right:-100px"。

3). \'left\' 和 \'right\' 设定值都不是 "auto"

如果 \'left\' 和 \'right\' 都不是 "auto",那么定位就显得很牵强,其中一个不得不被舍弃。如果包含块的 \'direction\' 属性是 "ltr", 那么 \'left\' 将获胜,\'right\' 值变成 -left。如果包含块的 \'direction\' 属性是 ‘rtl’,那么 \'right\' 获胜,\'left\' 值将被忽略。

示例代码:

<div style="width:100px; height:100px; overflow:auto; border:1px solid blue;">
    <div style="width:20px; height:20px; background-color:red; position:relative; left:60px; right:60px;"></div>
</div>

最后,\'left\' 应该比较强悍才对。

\'top\' 和 \'bottom\' 的特性值

\'top\' 和 \'bottom\' 特性将相对定位元素向上或者向下移动,而不改变其大小。\'top\' 把框向下移动,而 \'bottom\' 将其向上移动。 由于 \'top\' 和 \'bottom\' 没有造成框被拆分或者拉伸,计算值总是 top=-bottom,如果两个都是 "auto",其计算值就都是 0,如果其中之一是 auto,它就是另一个的负值。 如果都不是 "auto",\'bottom\' 被忽略,这时,\'bottom\' 的计算值会是 \'top\' 值的负值。

分类:

技术点:

相关文章:

  • 2021-11-15
  • 2021-10-16
  • 2021-08-27
  • 2021-11-24
  • 2021-11-30
  • 2022-01-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-04
  • 2021-12-02
  • 2021-10-07
  • 2021-11-29
相关资源
相似解决方案