HTML常用语法
HTML常用语法
标准HTML结构
1 | <html lang="en"> |
<head>
顶部界面,即浏览器标签栏的界面
<title>
标题
<body>
主体界面
定义段落
HTML注释
1 | <!-- This is a comment --> |
标题标签
1 | <h1></h1> |
hello html
hello html
hello html
hello html
hello html
hello html
水平线标签
1 | <hr> |
换行
1 | <p>This is<br />a para<br />graph with line breaks</p> |
This is
a para
graph with line breaks
图片标签
1 | <img src="..." width="..." height="..."> |
src可以写绝对路径和相对路径
./ 表示当前路径,可以省略
../ 表示当前路径的上一个路径
width和height分别可以写
width=”100px” 图片大小为100px
width=”80%” 图片占当前界面80%
标题样式
CSS引入方式
行内样式:写在标签的style属性中
1
<h1 style="xxx: xxx; xxx:xxx;">标题</h1>
内嵌样式:写在style标签中(可以写在页面任何位置上,但是通常写在head标签中)
1
2
3
4
5
6<style>
h1{
xxx: xxx;
xxx: xxx;
}
</style>外联样式:写在一个单独的.ccs文件中(需要通过link标签在网页中引入)
1
<link rel="stylesheet" href="css/news.css">
颜色表示
关键字
1
2
3
4
5
6
7
8<h4>
hello html
</h4>
<style>
h4{
color: red;
}
</style>hello html
rgb表示法
1
2
3
4
5
6
7
8<h4>
hello html
</h4>
<style>
h4{
color: rgb(0,0,0);
}
</style>16进制表示法
1
2
3
4
5
6
7
8<h4>
hello html
</h4>
<style>
h4{
color: #ff0000;
}
</style>
如果想要更改正文的样式,则需要引入<span>
标签,进行正文元素的更改
1 | <span>hello java</span> |
hello java
CSS选择器
选取需要设置样式的元素,分为
元素选择器
id选择器
类选择器
元素选择器
1
2
3
4
5
6
7
8元素名称{
color: red;
}
h1{
color: red;
}
<h1>Hello HTML</h1>id选择器
1
2
3
4
5
6
7
8#id属性值{
color: red;
}
#hid{
color: red;
}
<h1 id="hid">Hello HTML</h1>类选择器
1
2
3
4
5
6
7
8.class属性值{
color: red;
}
.cls{
color: red;
}
<h1 class="cls">Hello HTML</h1>
超链接
1 | <a href="..." target="...">xxx</a> |
属性:
href:指定访问资源的url
target:指定在何处打开资源
_self:默认值,在当前页面打开
_blank:在空白页面打开
CSS属性
text-decoration 规定添加到文本的修饰,none表示定义标准的文本
color: 定义文本的颜色
HTML列表
无序列表
无序列表始于
<ul>
标签。每个列表项始于<li>
1
2
3
4<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>- Coffee
- Milk
有序列表
有序列表始于
<ol>
标签。每个列表项始于<li>
标签1
2
3
4<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>- Coffee
- Milk
定义列表
自定义列表以
<dl>
标签开始。每个自定义列表项以<dt>
开始。每个自定义列表项的定义以开始
1
2
3
4
5
6<dl>
<dt>Coffee</dt>
<dd>Black hot drink</dd>
<dt>Milk</dt>
<dd>White cold drink</dd>
</dl>Coffee
Black hot drink
Milk
White cold drink
HTML块和类
1 |
|
London
London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.
Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the Romans, who named it Londinium.
Paris
Paris is the capital and most populous city of France.
Situated on the Seine River, it is at the heart of the 蝜e-de-France region, also known as the r間ion parisienne.
Within its metropolitan area is one of the largest population centers in Europe, with over 12 million inhabitants.
Tokyo
Tokyo is the capital of Japan, the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.
It is the seat of the Japanese government and the Imperial Palace, and the home of the Japanese Imperial Family.
The Tokyo prefecture is part of the world’s most populous metropolitan area with 38 million people and the world’s largest urban economy.