第五讲_css元素显示模式

css元素显示模式

  • [1. 元素的显示模式](#1. 元素的显示模式)
    • [1.1 块元素](#1.1 块元素)
    • [1.2 行内元素](#1.2 行内元素)
    • [1.3 行内块元素](#1.3 行内块元素)
  • [2. 元素根据显示模式分类](#2. 元素根据显示模式分类)
  • [3. 修改元素的显示模式](#3. 修改元素的显示模式)

1. 元素的显示模式

1.1 块元素

块元素的特性:

  • 在页面中独占一行,从上到下排列。
  • 默认宽度,撑满父元素。
  • 默认高度,由内容撑开。
  • 可以通过 css 设置宽高。
html 复制代码
<style>
	.first {
        width: 100px;
        height: 100px;
        background-color: blue;
	}

    .second {
        height: 100px;
        background-color: green;
    }
    .third {
        background-color: red;
    }
</style>

<div class="first">第一个块元素</div>
<div class="second">第二个块元素</div>
<div class="third">第三个块元素</div>

1.2 行内元素

行内元素的特性:

  • 在页面中不独占一行,从左到右排列。
  • 默认宽度,由内容撑开。
  • 默认高度,由内容撑开。
  • 无法通过 css 设置宽高。
html 复制代码
<style>
	.first {
        background-color: blue;
	}
    .second {
        background-color: green;
    }
    .third {
        background-color: red;
    }
</style>

<span class="first">第一个行内元素</span>
<span class="second">第二个行内元素</span>
<span class="third">第三个行内元素</span>

1.3 行内块元素

行内块元素的特性:

  • 在页面中不独占一行,从左到右排列。
  • 默认宽度,由内容撑开。
  • 默认高度,由内容撑开。
  • 可以通过 css 设置宽高。
html 复制代码
<style>
	.first {
        background-color: blue;
	}
    .second {
        height: 100px;
        width: 100px;
        background-color: green;
    }
    .third {
        background-color: red;
    }
</style>

<input class="first" placeholder="第一个行内块元素"/>
<input class="second" placeholder="第二个行内块元素"/>
<input class="third" placeholder="第三个行内块元素"/>

2. 元素根据显示模式分类

  • 块元素

<html><body><h1>-<h6><hr><p><pre><div>
<ul><ol><li><dl><dt><dd>
<table><tbody><thead><tfoot><tr><caption>
<form><option>

  • 行内元素

<br><em><strong><sup><sub><del><ins><a><label>

  • 行内块元素

<img><td><th><input><textarea><select><button><iframe>

3. 修改元素的显示模式

css 复制代码
/* block:设置为块元素 */
/* inline:设置为行内元素 */
/* inline-block:设置为行内块元素 */
/* none:隐藏元素 */
选择器 {
  display: block;
}
相关推荐
玩电脑的辣条哥2 小时前
Python如何播放本地音乐并在web页面播放
开发语言·前端·python
ew452182 小时前
ElementUI表格表头自定义添加checkbox,点击选中样式不生效
前端·javascript·elementui
suibian52352 小时前
AI时代:前端开发的职业发展路径拓宽
前端·人工智能
Moon.92 小时前
el-table的hasChildren不生效?子级没数据还显示箭头号?树形数据无法展开和收缩
前端·vue.js·html
垚垚 Securify 前沿站2 小时前
深入了解 AppScan 工具的使用:筑牢 Web 应用安全防线
运维·前端·网络·安全·web安全·系统安全
工业甲酰苯胺5 小时前
Vue3 基础概念与环境搭建
前端·javascript·vue.js
mosquito_lover17 小时前
怎么把pyqt界面做的像web一样漂亮
前端·python·pyqt
柴柴的小记9 小时前
前端vue引入特殊字体不生效
前端·javascript·vue.js
柠檬豆腐脑9 小时前
从前端到全栈:新闻管理系统及多个应用端展示
前端·全栈
bin915310 小时前
DeepSeek 助力 Vue 开发:打造丝滑的颜色选择器(Color Picker)
前端·javascript·vue.js·ecmascript·deepseek