第五讲_css元素显示模式

1. 元素的显示模式

1.1 块元素

块元素的特性:

  • 在页面中独占一行,从上到下排列。
  • 默认宽度,撑满父元素。
  • 默认高度,由内容撑开。
  • 可以通过 css 设置宽高。
<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 设置宽高。
<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 设置宽高。
<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. 修改元素的显示模式

/* block:设置为块元素 */
/* inline:设置为行内元素 */
/* inline-block:设置为行内块元素 */
/* none:隐藏元素 */
选择器 {
   
  display: block;
}

相关推荐

  1. _css元素显示模式

    2024-01-09 14:38:05       37 阅读
  2. CSS-常见元素显示模式总结

    2024-01-09 14:38:05       40 阅读
  3. 元素显示模式

    2024-01-09 14:38:05       29 阅读
  4. CSS-显示模式

    2024-01-09 14:38:05       11 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-09 14:38:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-09 14:38:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-09 14:38:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-09 14:38:05       20 阅读

热门阅读

  1. 2024.1.5力扣每日一题——队列中可以看到的人数

    2024-01-09 14:38:05       39 阅读
  2. 基于51单片机的智能水表电路设计

    2024-01-09 14:38:05       33 阅读
  3. Android 8.1 默认赋予应用权限

    2024-01-09 14:38:05       41 阅读
  4. Android将自定义View保存为Bitmap图片

    2024-01-09 14:38:05       30 阅读
  5. 消耗服务器带宽的因素有哪些

    2024-01-09 14:38:05       44 阅读
  6. 英语面试-BUAA

    2024-01-09 14:38:05       38 阅读