- 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
推薦閱讀
- Java程序設(shè)計與開發(fā)
- Python for Secret Agents:Volume II
- Mastering Concurrency in Go
- Python金融數(shù)據(jù)分析
- C語言程序設(shè)計
- 基于Struts、Hibernate、Spring架構(gòu)的Web應(yīng)用開發(fā)
- AIRIOT物聯(lián)網(wǎng)平臺開發(fā)框架應(yīng)用與實戰(zhàn)
- C專家編程
- Building Serverless Architectures
- 運維前線:一線運維專家的運維方法、技巧與實踐
- 遠方:兩位持續(xù)創(chuàng)業(yè)者的點滴思考
- RESTful Web API Design with Node.js(Second Edition)
- Slick2D Game Development
- 微信公眾平臺服務(wù)號開發(fā):揭秘九大高級接口
- Mastering Assembly Programming