網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
CSS-元素隱藏的兩種主要方式
目的
利用CSS樣式隱藏元素
語(yǔ)法
方法一
display: none;
方法二
visibility: hidden;
原始效果
測(cè)試代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style>
div {
width: 100px;
height: 100px;
}
.box1 {
background-color: #f00;
}
.box2 {
background-color: #0f0;
}
</style>
</head>
<body>
<div class="box1">我是box1</div>
<div class="box2">我是box2</div>
</body>
</html>
瀏覽器效果
使用方法一效果
display: none;
測(cè)試代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style>
div {
width: 100px;
height: 100px;
}
.box1 {
background-color: #f00;
/* 使用方法一隱藏元素 */
display: none;
}
.box2 {
background-color: #0f0;
}
</style>
</head>
<body>
<div class="box1">我是box1</div>
<div class="box2">我是box2</div>
</body>
</html>
瀏覽器效果
使用方法二效果
visibility: hidden;
測(cè)試代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style>
div {
width: 100px;
height: 100px;
}
.box1 {
background-color: #f00;
/* 使用方法二隱藏元素 */
visibility: hidden;
}
.box2 {
background-color: #0f0;
}
</style>
</head>
<body>
<div class="box1">我是box1</div>
<div class="box2">我是box2</div>
</body>
</html>
瀏覽器效果
總結(jié)
使用display: none
元素不顯示出來(lái), 并且也不占據(jù)位置, 不占據(jù)任何空間(和不存在一樣);
使用visibility: hidden
雖然元素不可見(jiàn), 但是會(huì)占據(jù)元素應(yīng)該占據(jù)的空間;
參考
coderwhy前端課講義
原文鏈接:https://blog.csdn.net/l_637/article/details/127003215
相關(guān)推薦
- 2022-05-14 詳解react-router-dom?v6版本基本使用介紹_React
- 2022-08-30 Window環(huán)境下配置Mongodb數(shù)據(jù)庫(kù)_MongoDB
- 2022-12-02 淺析Tomcat使用線程池配置高并發(fā)連接_Tomcat
- 2022-04-08 Python?如何實(shí)現(xiàn)變量交換_python
- 2022-04-06 用Python實(shí)現(xiàn)一個(gè)簡(jiǎn)單的用戶系統(tǒng)_python
- 2022-11-17 C++中的函數(shù)返回值問(wèn)題_C 語(yǔ)言
- 2022-06-01 Python學(xué)習(xí)之虛擬環(huán)境原理詳解_python
- 2022-12-29 react如何將字符串轉(zhuǎn)義成html語(yǔ)句_React
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支