amp-base-carousel 使用 layout=fill 脱离父级
amp-base-carousel breaks out of parent with layout=fill
我正在尝试使用 flex 布局来显示一个元素,并允许剩余元素根据可用 space.
我正在使用以下标记和样式来实现此目的。
<!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
。
我正在尝试使用 flex 布局来显示一个元素,并允许剩余元素根据可用 space.
我正在使用以下标记和样式来实现此目的。
<!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
。