- AMP:Building Accelerated Mobile Pages
- Ruadhan O'Donoghue
- 139字
- 2021-07-08 10:04:08
Horizontal flex items
Flex items can be horizontal. In the following CSS, we have given the parent a fixed size, exactly three times as wide as it is high:
.flex-container-row {
display: flex;
flex-direction: row;
width: 450px;
height: 150px;
}
The following markup shows increasing numbers of flex items within the flex parent:
<div class="flex-container-row">
<!-- 1 flex item -->
<amp-img src="img/placeholder.png" layout="flex-item"></amp-img>
</div>
<div class="flex-container-row">
<!-- 2 flex items -->
<amp-img src="img/placeholder.png" layout="flex-item"></amp-img>
<amp-img src="img/placeholder.png" layout="flex-item"></amp-img>
</div>
...
<div class="flex-container-row">
<!-- 7 flex items -->
<amp-img src="img/placeholder.png" layout="flex-item"></amp-img>
<amp-img src="img/placeholder.png" layout="flex-item"></amp-img>
...
<amp-img src="img/placeholder.png" layout="flex-item"></amp-img>
</div>
The following image shows the results of having a number of flex items, ranging from one to seven, in the container. Note how the flex items are stretched depending on how many there are. The only time they aren't stretched is when there are three, because we are using square placeholder images, and the container's width is three times its height:

Horizontal flex items being stretched or squashed to fit a container. From top: 1 item, 2 items, 3 items, 5 items, 7 items
推薦閱讀
- Flask Web全棧開發實戰
- Learning Scala Programming
- Java EE 6 企業級應用開發教程
- Cassandra Data Modeling and Analysis
- Nexus規模化Scrum框架
- C程序設計實踐教程
- Haskell Data Analysis Cookbook
- Python極簡講義:一本書入門數據分析與機器學習
- Learning Modular Java Programming
- Python趣味編程與精彩實例
- 深度學習程序設計實戰
- Kotlin語言實例精解
- H5匠人手冊:霸屏H5實戰解密
- Expert Cube Development with SSAS Multidimensional Models
- Java Web開發系統項目教程