- AMP:Building Accelerated Mobile Pages
- Ruadhan O'Donoghue
- 163字
- 2021-07-08 10:04:01
Using CSS in AMP pages
We're not finished converting our page to AMP just yet; let's deal with the validation error that mentions the style sheet next:
The attribute 'href' in tag 'link rel=stylesheet for fonts' is set to the invalid value 'style.css'.
One of the ways that AMP achieves its speed is by forbidding linked external style sheets. This means that all CSS must be inlined in the <head> of your AMP page. Open up the style sheet, and copy-paste all of the CSS rules you find into the AMP document. You'll need to wrap this CSS in a <style amp-custom> tag like this:
<style amp-custom>
html, body, ul {
margin:0;
padding:0;
}
...
</style>
You can only have one <style> tag in your AMP document, and it must include the amp-custom attribute.
Inlined CSS is limited to 50 KB per page, which is considered enough to style a single page
Inlined CSS is limited to 50 KB per page, which is considered enough to style a single page
If you reload the page now, you should see that the CSS validation error message is now resolved.
推薦閱讀
- 大學計算機基礎(第二版)
- Learning Scala Programming
- Android應用程序開發與典型案例
- 工程軟件開發技術基礎
- Machine Learning with R Cookbook(Second Edition)
- 前端架構:從入門到微前端
- Windows Presentation Foundation Development Cookbook
- 微信小程序開發解析
- Swift Playgrounds少兒趣編程
- Procedural Content Generation for C++ Game Development
- Raspberry Pi Robotic Blueprints
- Java程序設計與項目案例教程
- RocketMQ實戰與原理解析
- Java程序設計實用教程(第2版)
- CryENGINE Game Programming with C++,C#,and Lua