2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Core idea: semantics
【面试题】如何理解 HTML 语义化 ?
Identify the type of content by just looking at the tags, especially distinguishing between headings, paragraphs, images, and tables
The basic structure of an html file
The file extension of the html file is .html
, such as index.html
Input English in vscode !
Quick input
<!-- HTML5的文档类型声明【必要】 -->
<!doctype html>
<!-- 整个页面,语言为英文【必要】 -->
<html lang="en">
<!-- 页面的头部【必要】 -->
<head>
<!-- 页面的元信息-- 文档的字符编码为 UTF-8 -->
<meta charset="UTF-8" />
<!-- 页面的元信息-- 设备上显示页面的区域 viewport 的配置 -- width 为 device-width ,即采用设备宽度;intial-scale 为 1 ,即按原比例显示(无缩放)-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- 页面的标题【必要】 -->
<title>Document</title>
<!-- 页面中的样式 -->
<style>
html,
body {
height: 100%;
}
</style>
</head>
<!-- 页面的身体【必要】 -->
<body>
<!-- 页面的内容 -->
<div></div>
<!-- 页面的脚本 —— JS 代码 -->
<script></script>
</body>
</html>
【面试题】为什么<style></style> 标签要写在<head></head> 中 ?
The browser parses the HTML document from top to bottom. <style></style>
Labels should be written on<head></head>
You can load the style first and then load the elements.
If you will <style></style>
Tags written on<body></body>
Below, the elements are loaded first, and then the styles are loaded, resulting in the user seeing a page structure without styles.
【面试题】为什么<script></script> 标签要写在 <body></body> 内的底部 ?
The browser parses the HTML document from top to bottom. <style></style>
If not placed<body></body>
At the bottom of the JS, JS will be loaded and parsed first, and then the elements will be rendered, which will extend the page rendering time. If DOM operations are involved in JS, it will also block the page rendering.
Classification of html tags
According to the default display style value of the tag, it is divided into two categories
【面试题】HTML有哪些内联元素和块状元素 ?
Width is determined by content
display :inline
If it is not a replaced element, the width and height cannot be setimg,span , a , b 等
display :inline-block
You can set the width and heightinput, button 等
The width is determined by the container (the width will fill the entire container), and the width and height can be set
display: block
div,h1-h6,p,ul, ol ,form , hr 等
display: table
table
display: list-item
li
Replaced Elements in HTML
Elements whose rendered content can be replaced by modifying a certain attribute value (mostly the src attribute) are called "replaced elements".
The following tags are all replaced elements:
img、video、iframe、canvas、textarea、input、select、object
Replace element characteristics
Replace the size of an element
The final size of the replaced element is determined by the following three methods: Priority from high to low Followed by:
New tags in HTML5
【面试题】HTML5 新增了哪些标签 ? (回答几个常用的即可)
Structural Tags
<header>: 定义文档或节的头部。
<nav>: 定义导航链接。
<section>: 定义文档中的独立节。
<article>: 定义文档、页面、应用或网站中独立的内容区域。
<aside>: 定义页面的侧边栏内容。
<footer>: 定义文档或节的页脚。
<main>: 定义文档的主体内容。
Multimedia Tags
<video>: 定义视频或电影。
<audio>: 定义音频内容。
<source>: 为<video>和<audio>元素定义媒体资源。
<track>: 为<video>和<audio>元素定义文本轨道。
<embed>: 定义嵌入的内容,比如插件。
<canvas>: 用于在网页上绘制图形。
Form Tags
<datalist>: 定义选项列表,与<input>元素配合使用,以提供“自动完成”功能。
<output>: 定义不同类型的输出,比如脚本的输出。
Tags
<time>: 定义日期或时间。
<mark>: 定义高亮显示的文本。
<progress>: 定义任何类型的任务的进度。
<meter>: 定义已知范围或分数值内的标量测量。
<details>: 定义用户可见的或者隐藏的额外的细节。
<summary>: 定义<details>元素的可见标题。
<figure>: 规定独立的流内容(图像、图表、照片、代码等等)。
<figcaption>: 定义<figure>元素的标题(caption)。
Key points of common HTML tags
Only used in the head tag, it can define the relationship between the document and external resources, such as the external link CSS style, the small icon before the external link page title, etc.
<!-- 外链--样式 -->
<link rel="stylesheet" type="text/css" href="style.css" />
<!-- 外链--页面标题前的小图标 -->
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
The four major functions of the hyperlink a tag (page jump, page scrolling [anchor], page refresh, file download)
https://blog.csdn.net/weixin_41192489/article/details/140217094
Add a hyperlink to a paragraph
Wrap a with p, not p with a
<p><a href="">段落</a></p>
It is only applicable to line breaks within p tags. To break lines between paragraphs or adjust the spacing between elements, please use styles such as padding and margin.
<p>广东省<br/>广州市<br/>黄埔大道西601号</p>
Used to wrap part of the text within a line to add special styles.
<p><span style="color: red">要点:</span> 不能长时间睡觉。</p>
<p>m<sup>2</sup></p>
<p>m<sub>2</sub></p>
Block elements display: block
It can retain all whitespace characters (spaces, newlines) and output the results intact. It is often used to display computer source code.
<pre>
你好:
我昨天给你打了个电话。
</pre>
Inline elements display: inline
Used to represent computer source code or other machine-readable text content. To preserve the indentation format of the code, it is usually used with the pre tag.
The text inside the code tag will be displayed in a fixed-width, teletype-style font (Courier).
<pre>
<code>
let a = 1;
</code>
</pre>
<ul>
<li>咖啡</li>
<li>茶</li>
<li>牛奶</li>
</ul>
<ol>
<li>咖啡</li>
<li>茶</li>
<li>牛奶</li>
</ol>
<ol type="a">
<li>嘿嘿</li>
<li>嘿嘿</li>
<li>呵呵</li>
</ol>
<ol type="1" start="4">
<li>哈哈</li>
<li>哈哈</li>
<li>哈哈</li>
</ol>
li is a container-level tag that can hold anything, including ul.
<ul>
<li>
<b>北京市</b>
<ul>
<li>海淀区</li>
<li>朝阳区</li>
<li>东城区</li>
</ul>
</li>
<li>
<b>广州市</b>
<ul>
<li>天河区</li>
<li>越秀区</li>
</ul>
</li>
</ul>
https://blog.csdn.net/weixin_41192489/article/details/140217983
The i tag was originally used to indicate italic text, and the font has a tilted effect by default, but now italics are uniformly implemented through CSS. Because i is the first letter of icons, it is customary to use the i tag to display icons, so you need to add the style font-style:normal to cancel the default tilt.
<i style="font-style:normal">☎</i>
display :inline
Inline elements
Supported image formats: jpg (jpeg), gif, png, bmp, other formats are not supported, such as psd, ai
<img src="./ecLogo.jpg" alt="EC编程俱乐部的logo" />
src【Required】: URL of the image
alt【Important】: When the image cannot be displayed, the content displayed instead of the image, the search engine will crawl this attribute. alt comes from the word alternate, which means to replace the resource. (Some browsers do not support)
To keep the aspect ratio of the image, usually only set one of width and height.
[Practical skills] Responsive images
https://blog.csdn.net/weixin_41192489/article/details/126038175
[Practical skills] Image lazy loading (handwritten)
https://blog.csdn.net/weixin_41192489/article/details/126263221
display :inline
Inline elements
<audio controls>
<source src="./test.mp3" type="audio/mp3" />
您的浏览器不支持 audio 标签。
</audio>
Below is a simple music player implemented using vue3. For details on related properties and methods, see the comments.
<script setup>
let bgMusic_ref = ref(null)
function printInfo() {
let musicInfo = {
//currentTime 当前播放进度(单位秒s)
currentTime: bgMusic_ref.value.currentTime,
//duration 音频总时长(单位秒s)
duration: bgMusic_ref.value.duration
}
console.log(musicInfo)
}
function play() {
// 播放音频
bgMusic_ref.value.play()
}
function pause() {
// 暂停播放音频
bgMusic_ref.value.pause()
}
// 重新播放音频(从头开始播放)
function rePlay() {
// 先将当前播放进度重置为 0
bgMusic_ref.value.currentTime = 0
// 再播放音频
bgMusic_ref.value.play()
}
</script>
<template>
<audio ref="bgMusic_ref" controls autoplay>
<source src="./test.mp3" type="audio/mp3" />
您的浏览器不支持 audio 标签。
</audio>
<button @click="play">播放</button>
<button @click="pause">暂停</button>
<button @click="rePlay">重新播放</button>
<button @click="printInfo">打印音频信息</button>
</template>
display :inline
Inline elements
Only supports MP4, WebM, Ogg formats, and does not support other formats such as flv, mkv, etc.
<video controls>
<source src="./test.mp4" type="video/mp4" />
</video>
src【Required】: URL of the video
controls displays the video player
autoplay
loop
preload preload (this property will be invalid when autoplay is set)
[Practical Tips] Download videos to your local computer - CSDN Blog
https://blog.csdn.net/weixin_41192489/article/details/140223996
display :inline
Inline elements
Embed a web page within a page
<iframe src="https://www.w3school.com.cn/index.html"></iframe>
display :inline-block
Inline elements
<button onclick="alert('你好!')">点击我!</button>
HTML rendering special characters
character | describe | Code |
---|---|---|
Space | non-breaking spacing | |
< | less than | < |
> | greater than | > |
© | copyright | © |
& | And | & |
For more special characters, refer to "Summary of HTML, JS, and CSS Writing Methods for HTML Special Characters"
https://www.cnblogs.com/starof/p/4718550.html
HTML Common Tags Practical Examples
vue3 [Actual] Semantic Homepage Layout - CSDN Blog
https://blog.csdn.net/weixin_41192489/article/details/140215515
CSS [Actual Combat] "Siheyuan" Layout-CSDN Blog
https://blog.csdn.net/weixin_41192489/article/details/139243680