- AMP:Building Accelerated Mobile Pages
- Ruadhan O'Donoghue
- 315字
- 2021-07-08 10:04:06
Adding a related articles section with thumbnail images
Our article page is still a fairly bare-bones experience at the moment. Let's try to improve it. A common design pattern is to include a related or recommended content section at the end of an article. Let's add this to the bottom of our page. It will consist of a list of three or four articles, with thumbnails and text. Building this will help to improve our understanding of AMP's layout system.
For the list of items, we'll use an unordered list ul. Each item in the list will have an HTML5 figure element, which in turn will have a thumbnail image, amp-img, and associated text figcaption.
We'll use layout="fixed" for the thumbnail images so that they will all be a fixed size; we'll explore other options shortly (full code at /ch3/related-float.html):
<figure class="related-thumb">
<amp-img src="img/penguin.jpg" width="125" height="75" layout="fixed">
</amp-img>
<figcaption>
If a penguin can find a soul mate, I'm sure I can too
<span class="author">Rebekah Crane</span>
</figcaption>
</figure>
We'll add a touch of styling for the caption and author text:
figcaption {
font-family: Georgia;
font-weight: bold;
}
.author {
color: #bbb;
display:block;
}
If you look at this in a browser, the text caption displays underneath the image. Ideally, we'd like this to be to the right of the thumbnail. We can achieve this with a little CSS. The old school way to achieve this might be to use the CSS float property like this:
.related-thumb amp-img {
margin-right:5px;
float:left;
}

Now the text flows around the image. However, since we are building a list of three or four items, if we use the float property like this, we'll need to clear the float before the next item or the list items will keep floating to the side of the previous one and it will be a mess. Perhaps there's a better way to achieve this layout.
- Python Game Programming By Example
- Java深入解析:透析Java本質(zhì)的36個(gè)話題
- 鋒利的SQL(第2版)
- Python機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- JavaScript動(dòng)態(tài)網(wǎng)頁(yè)開(kāi)發(fā)詳解
- SQL Server與JSP動(dòng)態(tài)網(wǎng)站開(kāi)發(fā)
- Service Mesh實(shí)戰(zhàn):基于Linkerd和Kubernetes的微服務(wù)實(shí)踐
- Python3.5從零開(kāi)始學(xué)
- HTML5開(kāi)發(fā)精要與實(shí)例詳解
- Arduino計(jì)算機(jī)視覺(jué)編程
- Android Game Programming by Example
- 石墨烯改性塑料
- Oracle Database XE 11gR2 Jump Start Guide
- Clojure Web Development Essentials
- Monitoring Docker