当前位置:网站首页>37 元素模式(行内元素,块元素,行内块元素)
37 元素模式(行内元素,块元素,行内块元素)
2022-07-25 14:40:00 【hello_sunny123】
CSS的元素显示模式
了解元素的显示模式可以更好的让我们布局页面.
1.什么是元素的显示模式
作用:网页的标签非常多,在不同地方会用到不同类型的标签,了解他们的特点可以更好的布局我们的网页。
元素显示模式就是元素(标签)以什么方式进行显示,比如<div>自己占一行,比如一行可以放多个<span>.
HTML元素一般分为块元素和行内元素两种类型。
2.元素显示模式的分类
一.块元素
常见的块元素有<hl>~<h6>、<p>、<div>、<ul>, <ol>、<li>等,其中 <div> 标签是最典型的块元素。
块级元素的特点:
(1)比较霸道,自己独占一行。
(2)高度,宽度、外边距以及内边距都可以控制。
(3)宽度默认是容器(父级宽度)的100%
(4)是一个容器及盒子,里面可以放行内或者块级元素。
注意:
文字类的元素内不能使用块级元素
<p>标签主要用于存放文字,因此<p>里面不能放块级元素,特别是不能放<div>
同理, <hl>~<h6>等都是文字类块级标签,里面也不能放其他块级元素
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>块级元素</title>
<style> div {
width: 200px; height: 200px; background-color: pink; } </style>
</head>
<body>
<div>比较霸道,自己独占一行</div>瑟瑟发抖
<!-- <p> <div>这里有问题</div> </p> -->
</body>
</html>
运行结果

错误示范代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>块级元素</title>
<style> div {
/* width: 200px; */ height: 200px; background-color: pink; } </style>
</head>
<body>
<div>比较霸道,自己独占一行</div>瑟瑟发抖
/* `<p>`标签主要用于存放文字,因此`<p>`里面不能放块级元素,特别是不能放`<div>`*/
<p>
<div>这里有问题</div>
</p>
</body>
</html>
运行结果

二.行内元素
常见的行内元素有<a>、<strong>、<b>、<em>、<i>、<del>、<s>、<ins>、<u>、<span>等,其中<span>标签是最典型的行内元素。
有的地方也将行内元素称为内联元素。
行内元素的特点:
(1)相邻行内元素在一行上,一行可以显示多个。
(2)高、完直接设置是无效的。
(3)默认完度就是它本身内容的完度。
(4)行内元素只能容纳文本或其他行内元素。
注意:
链接里面不能再放链接
特殊情况链接 里面可以放块级元素,但是给 转换一下块级模式最安全
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>行内元素</title>
<style> span {
width: 100px; height: 100px; background-color: hotpink; } </style>
</head>
<body>
<span>pink老师你怎么穿着品如的衣服</span> <strong>品如的衣服</strong>
<span>pink老师</span> <strong>品如的衣服</strong>
</body>
</html>
运行结果

三.行内块元素
行内块元素
在行内元素中有几个特殊的标签<td>、<input/>、<img/> ,它们同时具有块元素和行内元素的特点。
有些资料称它们为行内块元素。
行内块元素的特点:
(1)和相邻行内元素(行内块)在一行上,但是他们之间会有空白缝隙。一行可以显示多个(行内元素特点)。
(2)默认宽度就是它本身内容的宽度(行内元素特点)。
(3)高度,行高、外边距以及内边距都可以控制(块级元素特点)。
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>行内块元素</title>
<style> input {
width: 249px; height: 25px; } </style>
</head>
<body>
<input type="text">
<input type="text">
</body>
</html>
运行结果

总结

3.元素显示模式的转换
边栏推荐
- Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]
- Awk from getting started to digging in (21) awk script debugging
- PS making and loading GIF pictures tutorial
- 【cartographer_ros】八: 官方Demo参数配置和效果
- 51 single chip microcomputer learning notes (2)
- 冈萨雷斯 数字图像处理 第一章绪论
- Throwing OutOfMemoryError “Could not allocate JNI Env“
- MySQL 45 talks about | 06 global locks and table locks: Why are there so many obstacles to adding a field to a table?
- 51单片机学习笔记(1)
- Awk from entry to earth (24) extract the IP of the instruction network card
猜你喜欢

Development of uni app offline ID card identification plug-in based on paddleocr

Deng Qinglin, a technical expert of Alibaba cloud: Best Practices for disaster recovery and remote multi activity across availability zones on cloud

51 single chip microcomputer learning notes (1)

Gameframework making games (II) making UI interface

GameFramework制作游戏(一)

Niuke multi school E G J L

The security market has entered a trillion era, and the security B2B online mall platform has been accurately connected to deepen the enterprise development path

Doris learning notes integration with other systems

苹果官网产品打折 买iPhone 13 Pro Max 可省600元

基于PaddleOCR开发uni-app离线身份证识别插件
随机推荐
微信公众号正式环境上线部署,第三方公众平台接入
006 operator introduction
Vs2017 large factory ERP management system source code factory general ERP source code
kibana操作es
GameFramework制作游戏(一)
[MySQL must know and know] trigger | permission management
Polymorphism and interface
Spark parameter adjustment and tuning
[eloquence] negotiation persuasion skills and Strategies
That day, I installed a database for my sister... Just help her sort out another shortcut
Gson and fastjson
基于浏览器的分屏阅读
C language and SQL Server database technology
PT100 temperature measurement circuit diagram (AD590 typical temperature measurement circuit)
Number of high-quality number pairs [bit operation characteristics + abstract ability evaluation + grouping fast statistics]
Awk from getting started to digging in (23) awk built-in variables argc, argc -- command line parameter transfer
pytorch训练代码编写技巧、DataLoader、爱因斯坦标示
Gameframework making games (I)
各种平台dpkg包下载地址(包括arm64)
冈萨雷斯 数字图像处理 第一章绪论