html - CSS scroll-snap 是如何指定的,它在 firefox 上不起作用
问题描述
我想在每个部分上进行一些滚动捕捉。根据文档,容器应该启用滚动捕捉类型,
直接孩子将被抢购。
使用以下代码,它怎么不起作用。但是,如果我将它放在身体 {scroll-snap-type: y 强制} 上它可以工作..除了仅在 chrome 和 safari 上.. firefox nightly 似乎有问题。
* {
margin: 0;
}
div {
scroll-snap-type: y mandatory;
}
section {
scroll-snap-align: start;
height: 100vh;
border: 1px solid black;
background-color: green;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div>
<section></section>
<section></section>
<section></section>
</div>
</body>
</html>
解决方案
您需要按照以下代码片段更新 css,developer.mozilla上提供了更多指南。
* {
margin: 0;
}
div {
scroll-snap-type: y mandatory;
overflow: auto;
outline: 1px dashed lightgray;
flex: none;
flex-flow: column nowrap;
height: 100vh;
}
section {
scroll-snap-align: start;
height: 100vh;
border: 1px solid black;
background-color: green;
flex: none;
}
<div>
<section></section>
<section></section>
<section></section>
</div>
推荐阅读
- typescript - 为具有所有可选属性的接口创建类型保护
- java - 使用 Spring 解析和使用 HTTP Range 标头
- macos - Mac 终端说:“无法打开显示...正在中止”
- python - Python 脚本 - 在请求模块中传递字符串参数失败(Curl 命令)
- android - 如何在没有上下文的情况下在应用程序的任何位置显示对话框?
- javascript - React useEffect 警告:超过最大更新深度。有没有解决的办法?
- html - 自定义复选框不正确
- java - 在另一个异步任务中执行异步任务
- android - Andriod Studio Gradle - 无法解析超过 2.24 的任何版本的匕首
- azure-active-directory - Azure AD 域服务域控制器的复制测试失败