官术网_书友最值得收藏!

Going from HTML to AMP-HTML

Assuming that you have a basic familiarity with HTML, we'll use a simple HTML5 news page as our jump-in point, and we'll convert it to AMP-HTML. Unless you are building a canonical AMP page, that is, a standalone AMP page that doesn't have a desktop counterpart, then a common task you may find yourself doing is converting a full HTML page to AMP-HTML. That's what we're going to do now.

Below is a screenshot of the page we'll be working with. It's a simplified version of a typical news article page. It includes some key items that we'll convert to AMP-HTML in this chapter. These are the header, logo, nav menu, article title, feature image, article content, and footer. In subsequent chapters we'll refine and improve the AMP page as we go along.

Our first AMP page!

The HTML behind this page is listed below, and can also be found at /ch2/news.html. There's nothing difficult here, but if you don't understand this markup, now would be a good time to brush up on your HTML and CSS skills before proceeding further:

<!doctype html>
<html lang="en">
<head>
<title>The AMP Book News Daily</title>
<link href="style.css" rel="stylesheet" />
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<header>
<div class="logo">theampbook</div>
<nav>
<ul class="primary-nav">
<li>news</li>
<li>sports</li>
<li>arts</li>
</ul>
</nav>
</header>
<article>
<h1>Breaking: AMP is fast</h1>
<img class="feature-img" src="lightning.jpg" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam egestas tortor sapien, non tristique ligula accumsan eu.</p>
</article>
<footer>
privacy policy
</footer>
</body>
</html>

It also includes a CSS file (/ch2/style.css) that contains the following CSS rules:

html, body, ul {
margin:0;
padding:0;
}

header {
background-color: #005689;
padding:0.5rem;
}

.logo {
text-align: right;
font-size:2.5rem;
color:#fff;
font-weight:bold;
}

header li {
display: inline-block;
color: #fff;
font-size: 1.5rem;
line-height: 2.625rem;
padding-right: 10px;
}

h1 {
background-color: #eee;
color: #005689;
margin: 0;
padding:1rem 0.5rem;
}

img.feature-img {
width: 100%;
}
p {
padding:0.5rem;
}

footer {
color: #dcdcdc;
background: #484848;
padding:0.5rem;
}

Since we'll be converting this HTML file to AMP-HTML, we'll save it as news.amp.html and make our changes in this file.

主站蜘蛛池模板: 黄浦区| 新邵县| 永顺县| 鄂伦春自治旗| 布拖县| 通州区| 汉阴县| 普安县| 庆云县| 新建县| 庄浪县| 井冈山市| 五峰| 怀化市| 霍州市| 仙桃市| 普兰店市| 临西县| 凤凰县| 图木舒克市| 富民县| 海南省| 桃园县| 德庆县| 吉木乃县| 沁源县| 桦甸市| 巴彦县| 新建县| 泰宁县| 虹口区| 讷河市| 奈曼旗| 抚宁县| 湾仔区| 曲水县| 洪泽县| 南漳县| 七台河市| 徐水县| 庆城县|