第五讲_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;
}
相关推荐
摸鱼仙人~1 小时前
styled-components:现代React样式解决方案
前端·react.js·前端框架
sasaraku.1 小时前
serviceWorker缓存资源
前端
RadiumAg2 小时前
记一道有趣的面试题
前端·javascript
yangzhi_emo2 小时前
ES6笔记2
开发语言·前端·javascript
yanlele3 小时前
我用爬虫抓取了 25 年 5 月掘金热门面试文章
前端·javascript·面试
中微子4 小时前
React状态管理最佳实践
前端
烛阴4 小时前
void 0 的奥秘:解锁 JavaScript 中 undefined 的正确打开方式
前端·javascript
中微子4 小时前
JavaScript 事件与 React 合成事件完全指南:从入门到精通
前端
Hexene...4 小时前
【前端Vue】如何实现echarts图表根据父元素宽度自适应大小
前端·vue.js·echarts
天天扭码5 小时前
《很全面的前端面试题》——HTML篇
前端·面试·html