Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
颜海镜 committed Jan 16, 2018
0 parents commit 8255368
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
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)
25 changes: 25 additions & 0 deletions absolute1.html
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>
26 changes: 26 additions & 0 deletions absolute2.html
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>
23 changes: 23 additions & 0 deletions absolute3.html
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>
24 changes: 24 additions & 0 deletions absolute4.html
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>
11 changes: 11 additions & 0 deletions common.css
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;
}
23 changes: 23 additions & 0 deletions css-table.html
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>
22 changes: 22 additions & 0 deletions flex.html
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>
19 changes: 19 additions & 0 deletions lineheight.html
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>
28 changes: 28 additions & 0 deletions table.html
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>

0 comments on commit 8255368

Please sign in to comment.