<li id="3wczy"><meter id="3wczy"></meter></li>

Hello world! This is HTML5 Boilerplate.<\/p>

国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Web Front-end HTML Tutorial HTML5 Boilerplate

HTML5 Boilerplate

Jun 24, 2016 am 11:51 AM

Recently I saw the HTML5 Boilerplate template and studied and understood it systematically. Today, with various CSS libraries and JS frameworks emerging one after another, it feels great to see such a good HTML template. Write a blog and recommend it to everyone.

1: What is HTML5 Boilerplate? What problem was solved?

I must have this question when I first heard about this person! I looked online and found that many people think this is the same thing as Bootstrap. This is really wrong.

In fact, HTML5 Boilerplate is just a simple HTML template.

What? HTML template? What is it used for?

Here I have to mention the problems that all front-end development will encounter. How do you do it every time you want to create a new page? The doctype, html, head, body, and meta tags are so annoying to write. Or copy it from a previous project, or copy the template recommended by Bootstrap, etc. But when doing these things, have you ever thought about whether your writing method is the best? Or does the industry have a more unified recommendation on this? Well, the answer is yes.

HTML5 Boilerplate solves such a problem. It provides a very complete HTML template, so perfect that all pages seem to abide by this rule.

It sounds so miraculous, so we still have to see what happens. After downloading it from the official website, the most important thing is an index.html file, which is not big. Let’s take a look at its source code

<!DOCTYPE html><!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--><!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]--><!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]--><!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->    <head>        <meta charset="utf-8">        <meta http-equiv="X-UA-Compatible" content="IE=edge">        <title></title>        <meta name="description" content="">        <meta name="viewport" content="width=device-width, initial-scale=1">        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->        <link rel="stylesheet" href="css/normalize.css">        <link rel="stylesheet" href="css/main.css">        <script src="js/vendor/modernizr-2.6.2.min.js"></script>    </head>    <body>        <!--[if lt IE 7]>            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>        <![endif]-->        <!-- Add your site or application content here -->        <p>Hello world! This is HTML5 Boilerplate.</p>        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script>        <script src="js/plugins.js"></script>        <script src="js/main.js"></script>        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->        <script>            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;            e=o.createElement(i);r=o.getElementsByTagName(i)[0];            e.src='//www.google-analytics.com/analytics.js';            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));            ga('create','UA-XXXXX-X');ga('send','pageview');        </script>    </body></html>

This can be said That’s all for HTML5 Boilerplate. If you take a quick look, you will definitely find that some of them are written in the same way as you have done before, and some of them are written in ways that you have never seen before, or you may say that you also write in this way but have never thought about why. Next, let’s “dissect” this HTML file first.

2: Brief analysis of index.html

First of all, the document type uses HTML5 document declaration, compared to HTML4 Of the long list, this one is obviously simple and clear. Moreover, it is compatible with all browsers. Because when designing IE, it will also enter the standards mode for this writing method. Therefore, future document declarations will be written like this to save worry.

Then, there is such a large section

<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--><!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]--><!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]--><!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->

This code is very classic.

First, let’s look at these conditional judgments, which mean lower than IE7, equal to IE7, equal to IE8, and higher than IE8.

Then there are corresponding class names in the conditional comments. For example, in lt IE 7, there will be three classes lt-ie9 lt-ie8 lt-ie7 on the html tag, which means below ie7, 8, 9. What's the use? In fact, the biggest problem is when writing CSS HACK, because if you write like this, you don't need CSS HACK. For example, if it is ie6, then there will be the lt-ie7 class on the html tag, and you can directly use CSS priority to overwrite the previous settings. That’s it.

Then the special part should be in the last sentence. The last sentence means that all browsers larger than ie8 and non-ie browsers use This html header. If you look closely, you will find that there are several incomplete annotation tags added inside. What's the use? For IE browsers larger than IE8, these tags are completely ignored. For non-ie browsers. Since [if gt IE 8] is not recognized, then together with the following comments, you will find that the entire part is commented. In this way, the most perfect browser identification is achieved.

Then there is a no-js class. This is mainly used together with modernizr.js later. Because modernizr will replace no-js with js when js is enabled in the browser. Simply put, this class can be used to determine whether the browser has enabled js.

Then, there is

<meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title></title><meta name="description" content=""><meta name="viewport" content="width=device-width, initial-scale=1">

首先,先設(shè)置文檔編碼,記住這個放最前面(特別注意別放title后面),以免后面代碼出現(xiàn)亂碼。

接下來便是設(shè)置IE使用最新版本來渲染

然后是描述,便于SEO。viewport指定移動端不對網(wǎng)頁進(jìn)行縮放。

這些個元標(biāo)簽基本都是一個網(wǎng)頁必須要有的,所以大家可以檢查下自己的網(wǎng)站是否漏了什么。

之后,引入了normalize、main兩個css。modernizr這個js。關(guān)于這3個文件,后面再詳細(xì)說明。

進(jìn)入主體部分。

首先,看到這么一段

<!--[if lt IE 7]>      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p><![endif]-->

對于使用低于IE7版本的用戶,給出升級提示,當(dāng)然,我們可以選擇刪除這一段或者換成一個中文提示

然后呢,便是這一段腳本

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script><script src="js/plugins.js"></script><script src="js/main.js"></script>

首先,通過CDN引入jquery。這里用的是谷歌的CDN。如果這段照抄,那么,,嘿嘿,網(wǎng)站肯定杯具了。所以這里換成國內(nèi)的jqueryCDN把,比如七牛的。

然后,判斷jQuery對象是否存在。因為CDN有可能掛了。如果jQuery對象不存在,那么我們就可以用自己服務(wù)器的jquery把。

然后引入了plugins.js還有main.js。main.js是空的,plugins.js后面詳細(xì)說明。

最后一段代碼就是引入google統(tǒng)計了。這里,根據(jù)自己的需要換成百度統(tǒng)計或者是別的把。就不詳細(xì)說了。

至此,HTML5 Boilerplate的最關(guān)鍵的模版HTML算是講完了。以后要新弄一個頁面,就照著這個copy把。

不過,HTML5 Boilerplate提供的還不止這些,下面講講單個文件的作用把。

三:靜態(tài)文件

打開項目代碼,可以看到有挺多的文件的,有些是說明文件,比如doc/路徑下的,就不講了,有些是值得講講的,比如css/ js/下的部分文件。挑幾個有趣的說說把。

首先 css目錄下有main和normalize

normalize也許大家都聽過,就是一個瀏覽器重置,里面的每一條css都是進(jìn)過千千萬萬的人精挑細(xì)選的,基本上這個重置屬于公認(rèn)的了。

里面的具體每條規(guī)則就不細(xì)講了,可以百度查看這個項目的文檔,或者直接看注釋也ok。

main就是改項目對normalize的補(bǔ)充,可以看到提供了一些基礎(chǔ)類名方便大家,比如圖片置換,清除浮動等等。

js提供了個plugins.js

代碼如下

// Avoid `console` errors in browsers that lack a console.(function() {    var method;    var noop = function () {};    var methods = [        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',        'timeStamp', 'trace', 'warn'    ];    var length = methods.length;    var console = (window.console = window.console || {});    while (length--) {        method = methods[length];        // Only stub undefined methods.        if (!console[method]) {            console[method] = noop;        }    }}());

比較簡單,就不說明了。解決的主要問題就是用console調(diào)試的時候IE報錯。這個問題我想大家都遇見過,調(diào)試代碼忘記刪除,線上IE報錯,導(dǎo)致js無法繼續(xù)執(zhí)行。加了這個,就可以避免掉這問題了。

?

還有就是modernizr了,這是個強(qiáng)大的瀏覽器功能檢查js,具體使用可以在官網(wǎng)上看看教程,這里就不說了。

?

然后,還提供了一些個文件,比如apache的配置htaccess、 404頁面、flash跨域需要的文件crossdomain.xml、爬蟲過濾文件robots.txt等,大家按需使用。

?

?

?

至此,HTML5 Boilerplate算是全部理完了,很簡單的一個項目,但是很實用,也很漂亮。可以作為開發(fā)標(biāo)配。

?

?

?

轉(zhuǎn)載本站文章請注明作者和出處??,請勿用于任何商業(yè)用途

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I stay up-to-date with the latest HTML standards and best practices? How do I stay up-to-date with the latest HTML standards and best practices? Jun 20, 2025 am 08:33 AM

The key to keep up with HTML standards and best practices is to do it intentionally rather than follow it blindly. First, follow the summary or update logs of official sources such as WHATWG and W3C, understand new tags (such as) and attributes, and use them as references to solve difficult problems; second, subscribe to trusted web development newsletters and blogs, spend 10-15 minutes a week to browse updates, focus on actual use cases rather than just collecting articles; second, use developer tools and linters such as HTMLHint to optimize the code structure through instant feedback; finally, interact with the developer community, share experiences and learn other people's practical skills, so as to continuously improve HTML skills.

How do I use the  element to represent the main content of a document? How do I use the element to represent the main content of a document? Jun 19, 2025 pm 11:09 PM

The reason for using tags is to improve the semantic structure and accessibility of web pages, make it easier for screen readers and search engines to understand page content, and allow users to quickly jump to core content. Here are the key points: 1. Each page should contain only one element; 2. It should not include content that is repeated across pages (such as sidebars or footers); 3. It can be used in conjunction with ARIA properties to enhance accessibility. Usually located after and before, it is used to wrap unique page content, such as articles, forms or product details, and should be avoided in, or in; to improve accessibility, aria-labeledby or aria-label can be used to clearly identify parts.

How do I minimize the size of HTML files? How do I minimize the size of HTML files? Jun 24, 2025 am 12:53 AM

To reduce the size of HTML files, you need to clean up redundant code, compress content, and optimize structure. 1. Delete unused tags, comments and extra blanks to reduce volume; 2. Move inline CSS and JavaScript to external files and merge multiple scripts or style blocks; 3. Simplify label syntax without affecting parsing, such as omitting optional closed tags or using short attributes; 4. After cleaning, enable server-side compression technologies such as Gzip or Brotli to further reduce the transmission volume. These steps can significantly improve page loading performance without sacrificing functionality.

How do I create a basic HTML document? How do I create a basic HTML document? Jun 19, 2025 pm 11:01 PM

To create a basic HTML document, you first need to understand its basic structure and write code in a standard format. 1. Use the declaration document type at the beginning; 2. Use the tag to wrap the entire content; 3. Include and two main parts in it, which are used to store metadata such as titles, style sheet links, etc., and include user-visible content such as titles, paragraphs, pictures and links; 4. Save the file in .html format and open the viewing effect in the browser; 5. Then you can gradually add more elements to enrich the page content. Follow these steps to quickly build a basic web page.

How do I create checkboxes in HTML using the  element? How do I create checkboxes in HTML using the element? Jun 19, 2025 pm 11:41 PM

To create an HTML checkbox, use the type attribute to set the element of the checkbox. 1. The basic structure includes id, name and label tags to ensure that clicking text can switch options; 2. Multiple related check boxes should use the same name but different values, and wrap them with fieldset to improve accessibility; 3. Hide native controls when customizing styles and use CSS to design alternative elements while maintaining the complete functions; 4. Ensure availability, pair labels, support keyboard navigation, and avoid relying on only visual prompts. The above steps can help developers correctly implement checkbox components that have both functional and aesthetics.

How do I use the  element to represent the footer of a document or section? How do I use the element to represent the footer of a document or section? Jun 25, 2025 am 12:57 AM

It is a semantic tag used in HTML5 to define the bottom of the page or content block, usually including copyright information, contact information or navigation links; it can be placed at the bottom of the page or nested in, etc. tags as the end of the block; when using it, you should pay attention to avoid repeated abuse and irrelevant content.

How has HTML evolved over time, and what are the key milestones in its history? How has HTML evolved over time, and what are the key milestones in its history? Jun 24, 2025 am 12:54 AM

HTMLhasevolvedsignificantlysinceitscreationtomeetthegrowingdemandsofwebdevelopersandusers.Initiallyasimplemarkuplanguageforsharingdocuments,ithasundergonemajorupdates,includingHTML2.0,whichintroducedforms;HTML3.x,whichaddedvisualenhancementsandlayout

How do I use the tabindex attribute to control the tab order of elements? How do I use the tabindex attribute to control the tab order of elements? Jun 24, 2025 am 12:56 AM

ThetabindexattributecontrolshowelementsreceivefocusviatheTabkey,withthreemainvalues:tabindex="0"addsanelementtothenaturaltaborder,tabindex="-1"allowsprogrammaticfocusonly,andtabindex="n"(positivenumber)setsacustomtabbing

See all articles