前端基础 HTML
Table of Contents
一、前端开发准备
- 必备软件安装:ide、浏览器等
- 项目组织方式
- An aside on casing and spacing : it is best to get into the habit of writing your folder and file names lowercase with no spaces and with words separated by hyphens. 这也是一般的项目文件组织方式
- website project structure
index.html
images
folderstyles
folderscripts
folder
二、Getting started with HTML
basics of HTML: elements, attributes …
1. html 元素
- The opening tag
- The content
- The closing tag
HTML 标签是一个闭合标签
1.1. 嵌套元素
|
|
1.2. 元素分类
- Block-level: For example, a block-level element might represent headings, paragraphs, lists, navigation menus, or footers. A block-level element wouldn’t be nested inside an inline element, but it might be nested inside another block-level element.
- Inline: It is typically used with text, for example an
<a>
element creates a hyperlink, and elements such as<em>
or<strong>
create emphasis.
1.3. 空元素
2. html 属性
Attributes contain extra information about the element that won’t appear in the content.
example
|
|
class
href
title
target
1.1. Boolean attributes
disabled
属性
|
|
1.2. 属性引号
在属性值上加引号
3. html 文档
|
|
<!DOCTYPE html>
: The doctype. 指明文档类型,历史原因<html></html>
<head></head>
: that isn’t the content the page will show to viewers<meta charset="utf-8">
: metadata<title></title>
<body></body>
三、What’s in the head? Metadata in HTML
To learn about the HTML head, its purpose, the most important items it can contain, and what effect it can have on the HTML document.
1. title 与 h1
2. meta
|
|
设置编码格式,对于一些浏览器可能会自动设置
|
|
3. link, script
-
ico for “favorites” and “bookmarks”
1
<link rel="icon" href="favicon.ico" type="image/x-icon">
-
CSS and JavaScript
1 2 3
<link rel="stylesheet" href="my-css-file.css"> <script src="my-js-file.js" defer></script>
四、HTML text fundamentals
Learn how to mark up a basic page of text to give it structure and meaning—including paragraphs, headings, lists, emphasis, and quotations.
1. The basics: headings and paragraphs
In HTML, each paragraph has to be wrapped in a <p>
like so:
|
|
Each heading has to be wrapped in a heading element:
|
|
a example:
|
|
On the other hand, you could make any element look like a top level heading. Consider the following:
|
|
2. List
2.1 Unordered
Every unordered list starts off with a <ul>
element–this wraps around all the list items:
|
|
The last step is to wrap each list item in a <li>
(list item) element:
|
|
2.2 Ordered
The markup structure is the same as for unordered lists, except that you have to wrap the list items in an <ol>
element, rather than ul
:
|
|
2.3 Emphasis and importance
-
Emphasis
1
<p>I am <em>glad</em> you weren't <em>late</em>.</p>
-
Strong importance
1 2 3
<p>This liquid is <strong>highly toxic</strong>.</p> <p>I am counting on you. <strong>Do not</strong> be late!</p>
-
Italic, bold, underline…
Here’s the best rule of thumb: It’s likely appropriate to use
<b>
,<i>
, or<u>
to convey a meaning traditionally conveyed with bold, italics, or underline, provided there is no more suitable element.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<p> The Ruby-throated Hummingbird (<i>Archilochus colubris</i>) is the most common hummingbird in Eastern North America. </p> <p> The menu was a sea of exotic words like <i>vatrushka</i>, <i>nasi goreng</i> and <i>soupe à l'oignon</i>. </p> <ol> <li> <b>Slice</b> two pieces of bread off the loaf. </li> <li> <b>Insert</b> a tomato slice and a leaf of lettuce between the slices of bread. </li> </ol>
五、Creating hyperlinks
1. link 刨析
基本链接由文本及其他内容构建,利用<a>
element and using the href
attribute
|
|
1.1 Adding supporting information with the title attribute
Another attribute you may want to add to your links is title
. The title contains additional information about the link, such as which kind of information the page contains, or things to be aware of on the web site.
|
|
1.2 Block level links
As mentioned before, almost any content can be made into a link, even block-level elements. If you have an image you want to make into a link, use the <a>
element and reference the image file with the<img>
element.
|
|
1.3 Document fragments
It’s possible to link to a specific part of an HTML document, known as a document fragment, rather than just to the top of the document. To do this you first have to assign an id
attribute to the element you want to link to.
|
|
Then to link to that specific id
, you’d include it at the end of the URL, preceded by a hash/pound symbol (#
), for example:
|
|
You can even use the document fragment reference on its own to link to another part of the current document:
|
|
2. Link best practices
2.1 Use clear link wording
Good link text:
|
|
Bad link text:
|
|
2.2 Linking to non-HTML resources — leave clear signposts
|
|
2.3 Use the download attribute when linking to a download
|
|
3. E-mail links
It’s possible to create links or buttons that, when clicked, open a new outgoing email message rather than linking to a resource or page. This is done using the <a>
element and the mailto
: URL scheme.
In its most basic and commonly used form, a mailto:
link indicates the email address of the intended recipient. For example:
|
|
六、Advanced text formatting
1. Description lists
The purpose of these lists is to mark up a set of items and their associated descriptions, such as terms and definitions, or questions and answers.
Description lists use a different wrapper than the other list types —<dl>
; in addition each term is wrapped in a<dt>
(description term) element, and each description is wrapped in a <dd>
(description definition) element.
|
|
……
七、Document and website structure
1. HTML for structuring content
- header:
<header>
- navigation bar:
<nav>
- main content:
main
, with various content subsections represented by<article>
,section
and<div>
elements. - sidebar:
<aside>
;often placed inside<main>
- footer:
<footer>
Non-semantic wrappers
<div>
, <span>
Line breaks and horizontal rules
<br>
, <hr>
|
|
|
|