国产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è)置文檔編碼,記住這個(gè)放最前面(特別注意別放title后面),以免后面代碼出現(xiàn)亂碼。

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

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

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

之后,引入了normalize、main兩個(gè)css。modernizr這個(gè)js。關(guān)于這3個(gè)文件,后面再詳細(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]-->

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

然后呢,便是這一段腳本

<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對(duì)象是否存在。因?yàn)镃DN有可能掛了。如果jQuery對(duì)象不存在,那么我們就可以用自己服務(wù)器的jquery把。

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

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

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

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

三:靜態(tài)文件

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

首先 css目錄下有main和normalize

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

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

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

js提供了個(gè)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)試的時(shí)候IE報(bào)錯(cuò)。這個(gè)問題我想大家都遇見過,調(diào)試代碼忘記刪除,線上IE報(bào)錯(cuò),導(dǎo)致js無法繼續(xù)執(zhí)行。加了這個(gè),就可以避免掉這問題了。

?

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

?

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

?

?

?

至此,HTML5 Boilerplate算是全部理完了,很簡單的一個(gè)項(xiàng)目,但是很實(shí)用,也很漂亮??梢宰鳛殚_發(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)

Hot Topics

PHP Tutorial
1502
276
Implementing Clickable Buttons Using the HTML button Element Implementing Clickable Buttons Using the HTML button Element Jul 07, 2025 am 02:31 AM

To use HTML button elements to achieve clickable buttons, you must first master its basic usage and common precautions. 1. Create buttons with tags and define behaviors through type attributes (such as button, submit, reset), which is submitted by default; 2. Add interactive functions through JavaScript, which can be written inline or bind event listeners through ID to improve maintenance; 3. Use CSS to customize styles, including background color, border, rounded corners and hover/active status effects to enhance user experience; 4. Pay attention to common problems: make sure that the disabled attribute is not enabled, JS events are correctly bound, layout occlusion, and use the help of developer tools to troubleshoot exceptions. Master this

Configuring Document Metadata Within the HTML head Element Configuring Document Metadata Within the HTML head Element Jul 09, 2025 am 02:30 AM

Metadata in HTMLhead is crucial for SEO, social sharing, and browser behavior. 1. Set the page title and description, use and keep it concise and unique; 2. Add OpenGraph and Twitter card information to optimize social sharing effects, pay attention to the image size and use debugging tools to test; 3. Define the character set and viewport settings to ensure multi-language support is adapted to the mobile terminal; 4. Optional tags such as author copyright, robots control and canonical prevent duplicate content should also be configured reasonably.

Best HTML tutorial for beginners in 2025 Best HTML tutorial for beginners in 2025 Jul 08, 2025 am 12:25 AM

TolearnHTMLin2025,chooseatutorialthatbalanceshands-onpracticewithmodernstandardsandintegratesCSSandJavaScriptbasics.1.Prioritizehands-onlearningwithstep-by-stepprojectslikebuildingapersonalprofileorbloglayout.2.EnsureitcoversmodernHTMLelementssuchas,

HTML for email templates tutorial HTML for email templates tutorial Jul 10, 2025 pm 02:01 PM

How to make HTML mail templates with good compatibility? First, you need to build a structure with tables to avoid using div flex or grid layout; secondly, all styles must be inlined and cannot rely on external CSS; then the picture should be added with alt description and use a public URL, and the buttons should be simulated with a table or td with background color; finally, you must test and adjust the details on multiple clients.

How to associate captions with images or media using the html figure and figcaption elements? How to associate captions with images or media using the html figure and figcaption elements? Jul 07, 2025 am 02:30 AM

Using HTML sums allows for intuitive and semantic clarity to add caption text to images or media. 1. Used to wrap independent media content, such as pictures, videos or code blocks; 2. It is placed as its explanatory text, and can be located above or below the media; 3. They not only improve the clarity of the page structure, but also enhance accessibility and SEO effect; 4. When using it, you should pay attention to avoid abuse, and apply to content that needs to be emphasized and accompanied by description, rather than ordinary decorative pictures; 5. The alt attribute that cannot be ignored, which is different from figcaption; 6. The figcaption is flexible and can be placed at the top or bottom of the figure as needed. Using these two tags correctly helps to build semantic and easy to understand web content.

What are the most commonly used global attributes in html? What are the most commonly used global attributes in html? Jul 10, 2025 am 10:58 AM

class, id, style, data-, and title are the most commonly used global attributes in HTML. class is used to specify one or more class names to facilitate style setting and JavaScript operations; id provides unique identifiers for elements, suitable for anchor jumps and JavaScript control; style allows for inline styles to be added, suitable for temporary debugging but not recommended for large-scale use; data-properties are used to store custom data, which is convenient for front-end and back-end interaction; title is used to add mouseover prompts, but its style and behavior are limited by the browser. Reasonable selection of these attributes can improve development efficiency and user experience.

How to handle forms submission in HTML without a server? How to handle forms submission in HTML without a server? Jul 09, 2025 am 01:14 AM

When there is no backend server, HTML form submission can still be processed through front-end technology or third-party services. Specific methods include: 1. Use JavaScript to intercept form submissions to achieve input verification and user feedback, but the data will not be persisted; 2. Use third-party serverless form services such as Formspree to collect data and provide email notification and redirection functions; 3. Use localStorage to store temporary client data, which is suitable for saving user preferences or managing single-page application status, but is not suitable for long-term storage of sensitive information.

Implementing Native Lazy Loading for Images in HTML Implementing Native Lazy Loading for Images in HTML Jul 12, 2025 am 12:48 AM

Native lazy loading is a built-in browser function that enables lazy loading of pictures by adding loading="lazy" attribute to the tag. 1. It does not require JavaScript or third-party libraries, and is used directly in HTML; 2. It is suitable for pictures that are not displayed on the first screen below the page, picture gallery scrolling add-ons and large picture resources; 3. It is not suitable for pictures with first screen or display:none; 4. When using it, a suitable placeholder should be set to avoid layout jitter; 5. It should optimize responsive image loading in combination with srcset and sizes attributes; 6. Compatibility issues need to be considered. Some old browsers do not support it. They can be used through feature detection and combined with JavaScript solutions.

See all articles