这篇翻译不完整。请帮忙从英语翻译这篇文章。
简介
bottom属性用来指定被定位元素的位置。
对于绝对定位的元素,即 position
属性设置为absolute或者fixed的元素,bottom属性指定元素底边距边缘和包含该元素的容器的底边缘的距离。
对于相对定位的元素,即position
属性设置为relative的元素,bottom属性指定元素的下边界离开其正常位置的距离。
当 top
和bottom同时出现,并且 height
没定义或者为auto或100%的时候,top
和bottom都会生效,在其他情况下,如果 height
被限制,则top
属性会优先设置bottom属性会被忽略。
初始值 | auto |
---|---|
适用元素 | positioned elements |
是否是继承属性 | 否 |
Percentages | refer to the height of the containing block |
适用媒体 | visual |
计算值 | if specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, auto |
是否适用于 CSS 动画 | yes, as a length, percentage or calc(); when both values are lengths, they are interpolated as lengths; when both values are percentages, they are interpolated as percentages; otherwise, both values are converted into a calc() function that is the sum of a length and a percentage (each possibly zero), and these calc() functions have each half interpolated as real numbers. |
正规顺序 | the unique non-ambiguous order defined by the formal grammar |
Syntax
/* <length> values */ bottom: 3px; bottom: 2.4em; /* <percentages> of the height of the containing block */ bottom: 10%; /* keyword values */ bottom: auto; bottom: inherit;
值
- 对于绝对定位的元素,是与包含该元素的容器的底部边界的距离。
- 对于相对定位的元素,是距离其未定位之前在正常流时位置的偏移量
<length>
- 一个负值、空值或正值:
<percentage>
- 包含块高度的百分比
<percentage>
,像在简介中描述的一样使用。 auto
- Specifies that:
- for absolutely positioned elements, the position of the element is based on the
top
property, andheight: auto
is treated as a height based on the content. - for relatively positioned elements, the offset the element from its original position is based on the
top
property, or iftop
is alsoauto
, the element is not moved vertically at all.
- for absolutely positioned elements, the position of the element is based on the
inherit
- Indicates that the value is the same as the computed value from its parent element (which may not be its containing block). This computed value is then handled as if it were a
<length>
,<percentage>
, or theauto
keyword.
Formal syntax
<length> | <percentage> | auto
Examples
element { position: absolute; bottom: 20px; height: 200px; border: 1px solid #000; }
The following sample demonstrates the difference in behavior of the bottom
property when position
is absolute
versus fixed
. When the regular text becomes taller than the viewable portion of the page (that is, the browser window's viewport), blocks positioned with position:absolute
scroll with the page, while blocks positioned with position:fixed
don't.
<!DOCTYPE html> <html> <head> <title>Position at bottom, absolute or fixed</title> <style type="text/css"> p {font-size:30px; line-height:3em;} div.pos {width:49%; text-align:center; border:2px solid #00f;} div#abs {position:absolute; bottom:0; left:0;} div#fix {position:fixed; bottom:0; right:0;} </style> </head> <body> <p>This<br>is<br>some<br>tall,<br>tall, <br>tall,<br>tall,<br>tall<br>content.</p> <div id="fix" class="pos"><p>Fixed</p></div> <div id="abs" class="pos"><p>Absolute</p></div> </body> </html>
Specifications
Specification | Status | Comment |
---|---|---|
CSS Level 2 (Revision 1) bottom |
Recommendation | Initial definition |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 1.0 | 1.0 (1.7 or earlier) | 5[1] | 6 | 1.0 (85) |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 1.0 (1.9.2) | ? | ? | ? |
[1] In Internet Explorer versions before 7.0, when both top
and bottom
are specified, the element position is over-constrained and the top
property has precedence. In that case the computed value of bottom
is set to -top
, while its specified value is ignored.