網站首頁 編程語言 正文
方法一 display:none
<!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>Document</title>
<style>
div{
width: 200px;
height: 200px;
background-color: pink;
display: none;
}
</style>
</head>
<body>
<div>我是一個div</div>
</body>
</html>
我們打開瀏覽器,鼠標右鍵點擊檢查,選中div標簽之后,我們可以看到瀏覽器窗口上什么也沒有,說明通過display:none設置元素隱藏,不會占據屏幕空間。
方法二 visibility: hidden
<!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>Document</title>
<style>
div{
width: 200px;
height: 200px;
background-color: pink;
visibility: hidden;
}
</style>
</head>
<body>
<div>我是一個div</div>
</body>
</html>
我們打開瀏覽器,鼠標右鍵點擊檢查,選中div標簽之后,我們可以看到瀏覽器窗口上顯示了div 200 x 200,說明通過visibility: hidden設置元素隱藏,會占據屏幕空間。
方法三 opacity: 0
opacity 指的是透明度,取值為 0-1,0表示透明,1表示不透明。
<!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>Document</title>
<style>
div{
width: 200px;
height: 200px;
background-color: pink;
opacity: 0;
}
</style>
</head>
<body>
<div>我是一個div</div>
</body>
</html>
同樣,使用 opacity: 0;隱藏元素也會占據屏幕空間。
方法四 overflow:hidden
使用overflow:hidden;主要是對超出父元素的內容隱藏
<!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>Document</title>
<style>
.div1{
width: 200px;
height: 200px;
background-color: pink;
overflow: hidden;
}
</style>
</head>
<body>
<div class="div1">
<div>第1個div標簽</div>
<div>第2個div標簽</div>
<div>第3個div標簽</div>
<div>第4個div標簽</div>
<div>第5個div標簽</div>
<div>第6個div標簽</div>
<div>第7個div標簽</div>
<div>第8個div標簽</div>
<div>第9個div標簽</div>
<div>第10個div標簽</div>
<div>第11個div標簽</div>
<div>第12個div標簽</div>
<div>第13個div標簽</div>
<div>第14個div標簽</div>
<div>第15個div標簽</div>
<div>第16個div標簽</div>
<div>第17個div標簽</div>
<div>第18個div標簽</div>
<div>第19個div標簽</div>
<div>第20個div標簽</div>
</div>
</body>
</html>
沒有使用overflow:hidden之前:
使用overflow:hidden之后:
此外,我們可以設置超出部分以滾動條形式顯示:
overflow: scroll;
自適應:
超出內容自動生成滾動條
overflow: auto;
這里水平方向內容沒有超出,所以沒有生成水平滾動條:
原文鏈接:https://blog.csdn.net/lq313131/article/details/125918591
相關推薦
- 2022-10-13 Python?YAML文件的讀寫操作詳解_python
- 2022-12-01 Go初學者踩坑之go?mod?init與自定義包的使用_Golang
- 2022-05-09 Python?matplotlib繪制實時數據動畫_python
- 2022-07-12 C語言中常見字符串API詳解
- 2023-04-26 Python?Flask的request對象使用詳解_python
- 2023-07-08 windows編譯libevent報錯
- 2022-11-05 go?module化?import?調用本地模塊?tidy的方法_Golang
- 2023-03-29 Pytorch損失函數torch.nn.NLLLoss()的使用_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支