我只是偶然发现了overflow: hidden
在html
上的这种用法,这对我来说似乎不合逻辑:
* {
all: unset;
display: revert;
}
html {
height: 100vh;
overflow: hidden;
background: black;
}
body {
height: 50vh;
font-size: 5rem;
background: white;
scroll-snap-type: y mandatory;
scroll-behavior: smooth;
overflow-y: scroll;
}
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
这是关于将滚动框从html
移动到body
,但是我不明白为什么这个例子只适用于overflow: hidden
?body
的高度已经只有50vh
了,所以html
元素不应该发生溢出吗?
1条答案
按热度按时间jgzswidk1#
根据质量标准:
但是,当根元素是[HTML] html元素时(包括HTML的XML语法)**其溢出值可见 (在两个轴上),并且该元素具有显示值也不是"无“的主体元素作为子元素,用户代理必须改为将第一个这样的子元素的overflow- 值应用于视口。然后,从中传播值的元素必须具有visible的已用溢出值。
在
html
上设置溢出将禁用传播,并将溢出保留在body元素上