【发布时间】:2016-09-01 15:21:39
【问题描述】:
我想要四个 div,一个在屏幕两侧的中心。因此,一个 div 元素在屏幕顶部水平居中,一个在底部水平居中,还有两个,一个在屏幕左侧,一个在屏幕右侧。两者都垂直居中。我该怎么做?
我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.boxes {
position: absolute;
width: 10px;
height: 5px;
}
#top {
top: 0;
background-color: yellow;
}
#left {
left: 0;
background-color: green;
}
#right {
right: 0;
background-color: red;
}
#bottomMenu {
bottom: 0;
background-color: blue;
}
</style>
</head>
<body>
<main>
<div id="top" class="boxes"></div>
<div id="left" class="boxes"></div>
<div id="right" class="boxes"></div>
<div id="bottom" class="boxes"></div>
</main>
</body>
</html>
就像现在一样,#top 和 #left 在左上角,#right 在右上角,#bottom 在左下角。 谢谢!
【问题讨论】: