-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# display、float、position的关系 | ||
|
||
- 如果元素的 display 为 none 直接隐藏 | ||
- 如果元素的 position 为 absolute 或者 fixed 时,float 失效,display 会提升块级元素 | ||
- 如果元素的 position 为 relative, 会在浮动后的元素进行定位,display 会被提升成块级元素 | ||
- 如果是根元素,display 会被提升为块级元素 | ||
- 浮动元素会将 display 提升为块级元素 | ||
|
||
|
||
```html | ||
<!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> | ||
/* 如果 float 置为 none,判断元素是否为根元素,如果是根元素,display 会被提升为块级元素 */ | ||
html { | ||
display: inline; | ||
width: 500px; | ||
height: 500px; | ||
} | ||
#app { | ||
display: inline; | ||
position: relative; | ||
width: 50px; | ||
height: 50px; | ||
background-color: aqua; | ||
float: left; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="app"> | ||
</div> | ||
</body> | ||
|
||
</html> | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# display、visibility、opacity区别 | ||
|
||
- 占据空间 | ||
- opacity、visibility 占据空间,不会引起回流,但是会重绘 | ||
- display 不占据空间,但会引起页面的回流和重绘 | ||
|
||
- 绑定事件 | ||
- display、visibility 不会触发绑定事件 | ||
- opacity 会触发绑定事件 | ||
|
||
|
||
# display: none 和 visibility: hidden 的区别 | ||
|
||
- 从渲染树上看 | ||
- display: none 不存在渲染树中 | ||
- visibility: hidden 的元素存在渲染树中,还会占据空间 | ||
- 从继承上看 | ||
- display 不会被继承 | ||
- visibility 会被继承 | ||
- 从渲染上看 | ||
- display 会影响回流重绘 | ||
- visibility 只会引起重绘 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# 隐藏元素的方法 | ||
|
||
- 1. display: none - 不会显示在渲染树上,不占据空间,无法监听事件 | ||
- 2. visibility: hidden - 占据空间,无法监听事件 | ||
- 3. opacity: 0 - 占据空间,可以监听事件 | ||
- 4. transform: scale(0, 0) | ||
- 5. 绝对定位 | ||
- 6. z-index 为负数 |