bottom
Baseline 广泛可用 *
试一试
bottom: 0;
bottom: 4em;
bottom: 10%;
bottom: 20px;
<section id="default-example">
<div class="example-container">
<div id="example-element">I am absolutely positioned.</div>
<p>
As much mud in the streets as if the waters had but newly retired from the
face of the earth, and it would not be wonderful to meet a Megalosaurus,
forty feet long or so, waddling like an elephantine lizard up Holborn
Hill.
</p>
</div>
</section>
.example-container {
border: 0.75em solid;
padding: 0.75em;
text-align: left;
position: relative;
width: 100%;
min-height: 200px;
}
#example-element {
background-color: #264653;
border: 4px solid #ffb500;
color: white;
position: absolute;
width: 140px;
height: 60px;
}
bottom 的效果取决于元素的定位方式(即 position 属性的值)。
- 当
position设置为absolute或fixed时,bottom属性指定了元素底部外边距的外边缘与包含块底部内边距的外边缘之间的距离。如果是在锚点定位元素中,并且在值中使用了anchor()函数,那么它是相对于指定<anchor-side>边缘的位置。bottom属性与top、bottom、start、end、self-start、self-end、center和<percentage>值是兼容的。 - 当
position设置为relative时,bottom属性指定了元素底部边缘相对于其正常位置向上移动的距离。 - 当
position设置为sticky时,bottom属性用于计算粘性约束矩形。 - 当
position设置为static时,bottom属性没有效果。
当同时指定了 top 和 bottom,并且 position 设置为 absolute 或 fixed,并且 height 未指定(即 auto 或 100%)时,top 和 bottom 的距离都将被遵守。在所有其他情况下,如果 height 以任何方式受到约束,或者 position 设置为 relative,则 top 属性优先,bottom 属性将被忽略。
语法
css
/* <length> values */
bottom: 3px;
bottom: 2.4em;
bottom: calc(anchor(--my-anchor 50%) + 5px);
bottom: anchor-size(width);
/* <percentage>s of the height of the containing block */
bottom: 10%;
/* Keyword value */
bottom: auto;
/* Global values */
bottom: inherit;
bottom: initial;
bottom: revert;
bottom: revert-layer;
bottom: unset;
值
<length>-
负值、零值或正值
<length>- 对于绝对定位元素,它表示到包含块底部边缘的距离。
- 对于相对定位元素,它表示元素相对于其正常位置向上移动的距离。
- 对于锚点定位元素,
anchor()函数解析为一个<length>值,该值相对于关联的锚点元素的顶部或底部边缘的位置(参见将嵌入属性与anchor()函数值一起使用),而anchor-size()函数解析为一个<length>值,该值相对于关联的锚点元素的宽度或高度(参见根据锚点大小设置元素位置)。
<percentage>-
包含块高度的
<percentage>。 auto-
指定
正式定义
正式语法
bottom =
auto |
<length-percentage> |
<anchor()> |
<anchor-size()>
<length-percentage> =
<length> |
<percentage>
<anchor()> =
anchor( <anchor-name>? &&
<anchor-side> , <length-percentage>? )
<anchor-size()> =
anchor-size( [ <anchor-name> || <anchor-size> ]? , <length-percentage>? )
<anchor-name> =
<dashed-ident>
<anchor-side> =
inside |
outside |
top |
left |
right |
bottom |
start |
end |
self-start |
self-end |
<percentage> |
center
<anchor-size> =
width |
height |
block |
inline |
self-block |
self-inline
示例
绝对定位和固定定位
此示例演示了当 position 为 absolute 与 fixed 时,bottom 属性行为上的差异。
HTML
html
<p>
This<br />is<br />some<br />tall,<br />tall,<br />tall,<br />tall,<br />tall<br />content.
</p>
<div class="fixed"><p>Fixed</p></div>
<div class="absolute"><p>Absolute</p></div>
CSS
css
p {
font-size: 30px;
line-height: 2em;
}
div {
width: 48%;
text-align: center;
background: rgb(55 55 55 / 20%);
border: 1px solid blue;
}
.absolute {
position: absolute;
bottom: 0;
left: 0;
}
.fixed {
position: fixed;
bottom: 0;
right: 0;
}
结果
规范
| 规范 |
|---|
| CSS 定位布局模块第 3 级 # 内嵌 |
浏览器兼容性
加载中…