-
-
Save feiwen8772/996c9cb536dcf2533b98647423f3e482 to your computer and use it in GitHub Desktop.
不用display:table实现的垂直居中的简单方式
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
<div class="element"> | |
<p>你好</p> | |
<p>你好</p> | |
</div> |
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
/* 基础样式 */ | |
* { margin:0; padding:0;} | |
html, body { height: 100%; } | |
body { | |
width: 100%; | |
height: 100%; | |
} | |
/* 关键样式 */ | |
.element { | |
text-align: center; | |
position: relative; | |
top: 50%; | |
transform: translateY(-50%); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment