HTML_LearnC04_tryCSS
for Learning book demo use
by Loki Jiang
HTML
<div class="container">
<div class="header">Header</div>
<div class="left">Left</div>
<div class="right">Right</div>
<div class="footer">Footer</div>
</div>
CSS
/*主div垂直至中方式*/
body {
/* ver4: 直接以父容器做內容保持水平垂直至中*/
width: 100vw;
height: 100vh;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
.container {
font-family: "Microsoft JhengHei";
width: 1024px;
height: 768px;
border: 1px solid #000;
color: white;
font-size: 3rem;
text-align: center;
/* ver1: 因為已經有寬高,讓margin去center layout
margin: auto;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
*/
/* ver2: 直接找畫面中心
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
*/
/* ver3: 跟ver2相同,只是改px去調位置
position: fixed;
left: 50%;
top: 50%;
margin-left: -512px;
margin-top: -384px;
*/
}
.header {
width: 1024px;
height: 100px;
background: #000;
line-height: 100px;
}
.left {
width: 200px;
height: 568px;
background: #aaa;
float: left;
line-height: 568px;
}
.right {
width: 824px;
height: 568px;
background: #777;
float: right;
line-height: 568px;
}
.footer {
width: 1024px;
height: 100px;
background: #000;
clear: both;
line-height: 100px;
}