Last active
August 11, 2016 20:06
-
-
Save Teraflopst/972968ccc4040adcc33c383ed6f7bd02 to your computer and use it in GitHub Desktop.
CSS 布局方案
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>CSS布局</title> | |
<style type="text/css"> | |
.container { | |
width: 400px; | |
height: 600px; | |
position: absolute; | |
left: 50%; | |
top: 50%; | |
transform: translate(-50%, -50%); | |
background: #FF004E; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h2>transform 实现垂直水平居中</h2> | |
<p>优点:不需要知道宽高,灵活</p> | |
<p>缺点:兼容不好,在Mobile设备上建议使用</p> | |
</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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>CSS布局</title> | |
<style type="text/css"> | |
.container { | |
width: 400px; | |
height: 600px; | |
background: #FF004E; | |
top: 50%; | |
left: 50%; | |
position: absolute; | |
margin-left: -200px; | |
margin-top: -300px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h2>绝对定位实现垂直水平居中</h2> | |
<p>优点:兼容性好</p> | |
<p>缺点:需要知道宽高,不够灵活</p> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment