Overflow属性

本文详细介绍了CSS中的Overflow属性,包括其可见性控制、隐藏及自动显示滚动条等不同设置的效果。探讨了在不同环境下如何使用该属性来解决内容溢出问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[quote]overflow

Values:
visible | hidden | scroll | auto | inherit

Initial value:
visible

Applies to:
Block-level and replaced elements

Inherited:
No

Computed value:
As specified[/quote]

If scroll is used, the panning mechanisms (e.g., scrollbars) should always be rendered. To quote the specification, "this avoids any problem with scrollbars appearing or disappearing in a dynamic environment." Thus, even if the element has sufficient space to display all of its content, the scrollbars should still appear. In addition, when printing a page or otherwise displaying the document in a print medium, the content may be displayed as though the value of overflow were
declared as visible.

Scroll 意味着滚动条始终被显示,那么就可以避免在动态文本的容器中滚动条显示、出现造成的种种问题。当在打印介质中,Scroll会默认编程visible,即自动溢出。

If overflow is set to hidden, the element's content is clipped at the edges of the element box, but no scrolling interface should be provided to make the content outside the clipping region accessible to the user.

hidden代表隐藏超出高度的部分

Finally, there is overflow: auto. This allows user agents to determine which behavior to use, although they are encouraged to provide a scrolling mechanism when necessary. This is a potentially useful way to use overflow since user agents could interpret it as "provide scrollbars only when needed." (They may not, but they certainly could and probably should.)

auto是让浏览器自动选择是否显示滚动条


来自CSS Definitive Guide
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值