forked from yanhaijing/vertical-center
-
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
颜海镜
committed
Jan 16, 2018
0 parents
commit 8255368
Showing
10 changed files
with
211 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,10 @@ | ||
# 水平垂直居中 | ||
|
||
- [lineheight](lineheight.html) | ||
- [absolute + 负margin](absolute1.html) | ||
- [absolute + margin auto](absolute2.html) | ||
- [absolute + calc](absolute3.html) | ||
- [absolute + transform](absolute4.html) | ||
- [table](table.html) | ||
- [css-table](css-table.html) | ||
- [flex](flex.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,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>absolute + 负margin</title> | ||
<link rel="stylesheet" href="common.css"> | ||
<style> | ||
.wp { | ||
position: relative; | ||
} | ||
.box { | ||
position: absolute;; | ||
top: 50%; | ||
left: 50%; | ||
margin-left: -50px; | ||
margin-top: -50px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wp"> | ||
<div class="box">123123</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,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>absolute + margin auto</title> | ||
<link rel="stylesheet" href="common.css"> | ||
<style> | ||
.wp { | ||
position: relative; | ||
} | ||
.box { | ||
position: absolute;; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
margin: auto; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wp"> | ||
<div class="box">123123</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,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>absolute + calc</title> | ||
<link rel="stylesheet" href="common.css"> | ||
<style> | ||
.wp { | ||
position: relative; | ||
} | ||
.box { | ||
position: absolute;; | ||
top: calc(50% - 50px); | ||
left: calc(50% - 50px); | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wp"> | ||
<div class="box">123123</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,24 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>absolute + transform</title> | ||
<link rel="stylesheet" href="common.css"> | ||
<style> | ||
.wp { | ||
position: relative; | ||
} | ||
.box { | ||
position: absolute;; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wp"> | ||
<div class="box">123123</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,11 @@ | ||
.wp { | ||
border: 1px solid red; | ||
width: 300px; | ||
height: 300px; | ||
} | ||
|
||
.box { | ||
width: 100px; | ||
height: 100px; | ||
background: green; | ||
} |
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,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>css-table</title> | ||
<link rel="stylesheet" href="common.css"> | ||
<style> | ||
.wp { | ||
display: table-cell; | ||
text-align: center; | ||
vertical-align: middle; | ||
} | ||
.box { | ||
display: inline-block; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wp"> | ||
<div class="box">123123</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,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>flex</title> | ||
<link rel="stylesheet" href="common.css"> | ||
<style> | ||
.wp { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
.box { | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wp"> | ||
<div class="box">123123</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,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>lineheight</title> | ||
<link rel="stylesheet" href="common.css"> | ||
<style> | ||
.wp { | ||
line-height: 300px; | ||
text-align: center; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wp"> | ||
<span class="box">文本文本文本</span> | ||
</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,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>table</title> | ||
<link rel="stylesheet" href="common.css"> | ||
<style> | ||
.wp { | ||
text-align: center; | ||
} | ||
.box { | ||
display: inline-block; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<table> | ||
<tbody> | ||
<tr> | ||
<td class="wp"> | ||
<div class="box">123123</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> | ||
|