-
Notifications
You must be signed in to change notification settings - Fork 3
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
249 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
### HTML & CSS 相关知识总结 | ||
|
||
##### CSS 实现三列布局的方案(左右两列宽度固定,中间自适应): | ||
|
||
> 圣杯布局 | ||
主要是对负边距的利用。使用负边距,将左右两边的盒子移动到中间盒子的两边。 | ||
|
||
```html | ||
<div class="container"> | ||
<div class="middle"></div> | ||
<div class="left"></div> | ||
<div class="right"></div> | ||
</div> | ||
``` | ||
|
||
```css | ||
.container { | ||
padding: 0 200px; | ||
} | ||
|
||
.container > div { | ||
height: 200px; | ||
float: left; | ||
} | ||
|
||
.middle { | ||
width: 100%; | ||
background: blue; | ||
} | ||
|
||
.left { | ||
margin-left: -100%; | ||
position: relative; | ||
left: -200px; | ||
width: 200px; | ||
background: red; | ||
} | ||
|
||
.right { | ||
margin-left: -200px; | ||
position: relative; | ||
right: -200px; | ||
width: 200px; | ||
background: yellow; | ||
} | ||
``` | ||
|
||
[一篇关于圣杯布局的文章](https://alistapart.com/article/holygrail) | ||
|
||
> 双飞翼布局 | ||
这个是淘宝出来的布局。也是利用了负边距,相对于圣杯布局,这里的样式写法好理解点。 | ||
|
||
```html | ||
<div class="container"> | ||
<div class="middle"> | ||
<div class="middle-container"></div> | ||
</div> | ||
<div class="left"></div> | ||
<div class="right"></div> | ||
</div> | ||
``` | ||
|
||
```css | ||
.container > div { | ||
float: left; | ||
height: 200px; | ||
} | ||
|
||
.middle { | ||
width: 100%; | ||
background: red; | ||
} | ||
|
||
.middle-container { | ||
height: 200px; | ||
margin: 0 200px; | ||
background: darkred; | ||
} | ||
|
||
.left { | ||
width: 200px; | ||
margin-left: -100%; | ||
background: blue; | ||
} | ||
|
||
.right { | ||
width: 200px; | ||
margin-left: -200px; | ||
background: yellow; | ||
} | ||
``` | ||
|
||
> Flex 布局 | ||
Flex 是 CSS3 中的提供的属性。 | ||
|
||
```html | ||
<div class="container"> | ||
<div class="col-1"></div> | ||
<div class="col-2"></div> | ||
<div class="col-3"></div> | ||
</div> | ||
``` | ||
|
||
```css | ||
.container { | ||
display: flex; | ||
width: 100%; | ||
} | ||
|
||
.container > div { | ||
height: 200px; | ||
flex: 1; | ||
border: 1px solid red; | ||
} | ||
``` |
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,50 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>圣杯布局</title> | ||
<style> | ||
.container { | ||
padding: 0 200px; | ||
} | ||
|
||
.container>div { | ||
height: 200px; | ||
float: left; | ||
} | ||
|
||
.middle { | ||
width: 100%; | ||
background: blue; | ||
} | ||
|
||
.left { | ||
margin-left: -100%; | ||
position: relative; | ||
left: -200px; | ||
width: 200px; | ||
background: red; | ||
} | ||
|
||
.right { | ||
margin-left: -200px; | ||
position: relative; | ||
right: -200px; | ||
width: 200px; | ||
background: yellow; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<div class="middle"></div> | ||
<div class="left"></div> | ||
<div class="right"></div> | ||
</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,50 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>双飞翼布局</title> | ||
<style> | ||
.container>div { | ||
float: left; | ||
height: 200px; | ||
} | ||
|
||
.middle { | ||
width: 100%; | ||
background: red; | ||
} | ||
|
||
.middle-container { | ||
height: 200px; | ||
margin: 0 200px; | ||
background: darkred; | ||
} | ||
|
||
.left { | ||
width: 200px; | ||
margin-left: -100%; | ||
background: blue; | ||
} | ||
|
||
.right { | ||
width: 200px; | ||
margin-left: -200px; | ||
background: yellow; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<div class="middle"> | ||
<div class="middle-container"></div> | ||
</div> | ||
<div class="left"></div> | ||
<div class="right"></div> | ||
</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,31 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Flex布局</title> | ||
<style> | ||
.container { | ||
display: flex; | ||
width: 100%; | ||
} | ||
|
||
.container>div { | ||
height: 200px; | ||
flex: 1; | ||
border: 1px solid red; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<div class="col-1"></div> | ||
<div class="col-2"></div> | ||
<div class="col-3"></div> | ||
</div> | ||
</body> | ||
|
||
</html> |