分类
块级标签
特点
- 标签独占一行
- 可指定宽、高。
- margin和padding的上下左右均对其有效
- 多个块状元素标签写在一起,默认排列方式为从上至下
- 可以使用margin:0 auto居中对齐
- 可以自动换行
常见块级标签
<div>、<p>、<h1>...<h6>、<ol>、<ul>、<dl>、<table>、<address>、<blockquote>、<form>
行级标签(内联标签)
特点
- 与其他标签在一行内
- 无法设置宽高,宽度与高度由内容决定,只有在内容超过HTML的宽度时,才会换行。
- margin上下无效,只有左右有效果,padding都有效果,会撑大空间;
- 不会自动换行
常见行级标签
<a>、<span>、<i>、<em>、<strong>、<label>、<q>、<var>、<cite>、<code>
内联块状标签
特点
- 同时具备内联元素、块状元素的特点,代码display:inline-block就是将元素设置为内联块状元素。
- 能够设置宽高
- 默认排列方式为从左到右
- margin:0 auto无效,但可以使用text-align:center使内容相对于父盒子水平居中对齐
- 水平排列,但所有元素默认会有1个空格的间隙,因为元素之间在html中书写有回车换行,浏览器解析会将其解析成一个空格。
- 不会自动换行
常见内敛块状标签
<img>、<input>
标签类型转换
- display:inline;转换为行内元素
- display:linline-block;转换为行内块元素
- display:block;转换为块级元素
演示
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<meta name="keywords" content="前端"/>
<meta name="description" content="学习"/>
</head>
<body>
<div id="tips">提示部分</div>
<h1>h1标题标签</h1>
<h6>h6标题标签</h6>
-你好<br>哈喽
<p>段落标签,单独占一行</p>哈喽
<hr >
<b>粗体</b>
<i>斜体</i>
<small>小字体</small>
<strong>等价于粗体</strong>
<del>删除线</del>
<hr >
<a href="https://www.baidu.com" target="_blank">跳转到百度</a>
<a href="https://www.baidu.com" target="_self">跳转到百度</a>
<br>
<a href="#tips">跳到提示部分</a>
<br>
<img src="img/1.jpg" title="光标消息显示" width="600px" height="300px">
<img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnimg.ws.126.net%2F%3Furl%3Dhttp%253A%252F%252Fdingyue.ws.126.net%252F2021%252F0818%252Fcf2865b0j00qy1ii8001bc000hs00mmg.jpg%26thumbnail%3D650x2147483647%26quality%3D80%26type%3Djpg&refer=http%3A%2F%2Fnimg.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1644564130&t=6b4787a7ba7a72b2433b6892f0050c9a"
width="300px" height="400px"
>
<ul>
<li>第一个</li>
<li>第二个</li>
<li>第三个</li>
</ul>
<ol>
<li>第一个</li>
<li>第二个</li>
<li>第三个</li>
</ol>
<table border="10" cellspacing="0" cellpadding="">
<tr>
<td rowspan="2">单元格1</td>
<td colspan="2" align="center">单元格2</td>
</tr>
<tr>
<td>单元格5</td>
<td>单元格6</td>
</tr>
<tr>
<td>单元格7</td>
<td colspan="2">单元格8</td>
</tr>
</table>
<br>
<form action="" method="post">
<input type="text" placeholder="明文文本框" value=""/>
<br>
<input type="password" placeholder="暗文密码" name="" id="" value="" />
<br>
<input type="radio" name="gender" title="单选框" value="1" />男
<input type="radio" name="gender" title="单选框" value="0" />女
<br>
<input type="checkbox" name="cb1" id="" value="" />北京
<input type="checkbox" name="cb1" id="" value="" />上海
<br>
<select name="">
<option value="">计算机</option>
<option value="" selected="selected">电科</option>
<option value="">通信</option>
</select>
<br>
<textarea maxlength="5" rows="" cols=""></textarea>
<br>
<input type="button" name="" id="" value="普通按钮" onclick="alert('123');"/>
<input type="submit" name="" id="" value="提交按钮" />
<input type="reset" name="" id="" value="重置按钮" />
<input type="hidden" name="" id="" value="隐藏框" />
</form>
</body>
</html>