简体   繁体   English

CSS 固定位置中的 right:0 是什么意思?

[英]What does right:0 in CSS fixed position mean?

I don't understand why the div.class moves to the right bottom.我不明白为什么div.class移动到右下角。 I really want to know the meaning of '0' precisely in fixed position.我真的很想知道'0'在固定位置的含义。

Why does the border never stretch to the right side if I change ( bottom: 0; right: 0; ) into ( top: 0; right: 0; bottom: 0; left: 0; )?如果我将 ( bottom: 0; right: 0; ) 更改为 ( top: 0; right: 0; bottom: 0; left: 0; ),为什么边框永远不会延伸到右侧?

 div.fixed { position: fixed; width: 300px; bottom: 0; right: 0; border: 3px solid #73ad21; }
 <h2>position: fixed;</h2> <p>An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled:</p> <div class="fixed"> This div element has position: fixed; </div>

I don't understand why the div.class moves to the right bottom.我不明白为什么div.class移动到右下角。

That's what the bottom and right CSS properties are for.这就是bottomright CSS 属性的用途。 They position the bottom and right side of the element, counting from the bottom and right side -- in this case from the viewport, since position is fixed .它们定位元素的底部和右侧,从底部和右侧开始计数——在本例中是从视口开始,因为 position 是fixed的。

I really want to know the meaning of '0' precisely in fixed position.我真的很想知道'0'在固定位置的含义。

0 is a number of units. 0 是单位数。 It could have been specified as 0px or 0pt or with another unit, but since it doesn't matter which unit is used, as it is 0 anyway, it is specified without unit.它可以被指定为0px0pt或其他单位,但由于使用哪个单位并不重要,因为它无论如何都是 0,所以它被指定为没有单位。 It represents the distance from the bounding box of the viewport.它表示与视口边界框的距离。

Why does the border never stretch to the right side if I change ( bottom: 0; right: 0; ) into ( top: 0; right: 0; bottom: 0; left: 0; )?如果我将 ( bottom: 0; right: 0; ) 更改为 ( top: 0; right: 0; bottom: 0; left: 0; ),为什么边框永远不会延伸到右侧?

Because the width: 300px specification stipulates what the width of the element should be, and so the rendering has to give up on right: 0 , as otherwise the width would be different.因为width: 300px规范规定了元素的宽度应该是多少,所以渲染必须放弃right: 0 ,否则宽度会不同。 However, if you drop the width specification, the element will take the whole space of the viewport:但是,如果您放弃width规范,该元素将占据视口的整个空间:

 div.fixed { position: fixed; _width: 300px; top: 0; left: 0; bottom: 0; right: 0; border: 3px solid #73AD21; }
 <h2>position: fixed;</h2> <p>An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled:</p> <div class="fixed"> This div element has position: fixed; </div>

The number represents the distance from the bottom/right.数字表示距底部/右侧的距离。 So, going bottom: 10px would place it 10px from the bottom of the window.所以,去bottom: 10px将把它放在距离窗口底部 10px 处。 It's basically a way of positioning it.这基本上是一种定位方式。 Hope this helps!希望这可以帮助!

@Gerald when you set the position fixed, the element is stand by fixed position in the screen. @Gerald 当您将位置设置为固定时,该元素在屏幕中处于固定位置。 You can change the position of element with top, left, right, bottom of css properties.您可以使用 CSS 属性的顶部、左侧、右侧、底部来更改元素的位置。 For now if you set bottom:0, right: 0, the element is set in the bottom and right corner of the screen.现在如果你设置bottom:0, right: 0,元素被设置在屏幕的右下角。 If you want it set left bottom corner, set left:0, bottom:0, and remove right:0.如果要设置左下角,请设置 left:0, bottom:0,并删除 right:0。 Also you can set px, em, vw, vh or % for example, left: 10px, there would be 10px space between element and left.您也可以设置 px、em、vw、vh 或 %,例如 left: 10px,元素和 left 之间会有 10px 的空间。 If you want bottom center, set bottom:0, left 50%, transform: translateX(-50%) Hope it is helpful to you~如果要底部居中,设置bottom:0,left 50%,transform: translateX(-50%) 希望对你有帮助~

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

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