html - amp-base-carousel 使用 layout=fill 脱离父级
问题描述
我正在尝试使用 flex 布局来显示一个元素并允许剩余元素根据可用空间增长。
我正在使用以下标记和样式来实现这一点。
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>My AMP Page</title>
<link rel="canonical" href="self.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-base-carousel" src="https://cdn.ampproject.org/v0/amp-base-carousel-0.1.js"></script>
<style amp-custom>
.bodywrapper {
display: flex;
flex-direction: column;
background-color: lightseagreen;
height: 100vh;
}
h1 {
flex: 0 1 auto;
background-color: green;
}
div.wrapper {
background-color: lightcoral;
flex: 1 0 auto;
}
.scrollable {
overflow-y: auto;
}
</style>
</head>
<body>
<div class="bodywrapper">
<h1>Hello AMPHTML World!</h1>
<div class="wrapper">
<amp-base-carousel [slide]="selectedSlide" on="slideChange:AMP.setState({selectedSlide:event.index})" id="imageSlides" mixed-length="true" layout="fill">
<div class="scrollable">
Exercitation excepteur culpa nostrud consequat consectetur in deserunt.
</div>
<div class="scrollable">
Contrary to popular belief, Lorem Ipsum is not simply random text.
</div>
</amp-base-carousel>
</div>
</div>
</body>
</html>
(请忽略此示例中未实现 amp-state。)
然而,amp-base-carousel
内容脱离父容器(“.wrapper”)并显示在h1
.
解决方案
这与基本轮播无关,而是与 AMP 的fill
布局有关,这需要容器设置position: relative
.
推荐阅读
- django - 如何在 Django Rest Framework (DRF) 中控制版本控制
- python - RNN在不同batch_size下的训练会导致不同的性能?
- python - Putting a string into a box of stars
- java - 如何根据逗号分隔值之一对文本文件中的行进行排序?
- php - DateIntervalType:缺少“反转”标签
- docker - 如何避免 haproxy docker 中的“sendmsg()/writev() failed in logger”错误
- google-cloud-platform - 谷歌云:无法禁用 notebooks.googleapis.com
- scheduled-tasks - 雪花任务返回必须授予所有者角色的使用错误
- go - 将 Go 与 BigQuery 结合使用时取消上下文
- python - 使用使用时尚 mnist 数据集训练的模型从谷歌图像(包)预测图像的类别