【发布时间】:2014-02-20 23:20:05
【问题描述】:
我有 2 个盒子应该并排显示。我想要一个垂直固定的位置。 因此,当我向上或向下滚动时,框保持在相同的高度。
但我不希望它是水平固定的,因为我希望 2 个框始终位于中心。即使您使浏览器变大或变小。为此,我使用 margin: 20px auto;
有什么办法我可以如何保持边距并获得 2 个框,其中 1 个具有垂直固定位置。
发帖时就像这个网站一样。有一个带有问题的主页和一个带有类似问题的边框,始终停留在屏幕上。
到目前为止我的代码:
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/png" href="/favicon.ico">
<style>
html,
body {
background-color: #026642;
}
#container {
width: 800px;
margin: 20px auto;
position: relative;
}
#sidebox {
background-color: white;
padding: 5px;
margin: 5px;
border-radius: 5px;
width: 180px;
position: absolute;
}
#indexcontainer {
padding: 10px;
background-color: #FFD302;
border-radius: 20px;
width: 580px;
position: absolute;
}
#header {
text-align: center;
}
#content {
background-color: white;
padding: 5px;
margin: 5px;
border-radius: 5px;
}
#content i {
font-size: 14px;
}
#footer {
clear: both;
padding: 0 5px;
font-size: 11px;
clear: both;
}
a:link {
text-decoration: none;
color: black;
}
a:visited {
text-decoration: none;
color: black;
}
a:hover {
text-decoration: underline;
color: black;
}
a:active {
text-decoration: underline;
color: black;
}
</style>
</head>
<body>
<div id="container">
<div id="sidebox">
Sidebox
</div>
<div id="indexcontainer">
<div id="header">
<img src="images/emte.jpg" alt="logo" width="200" height="100">
</a>
</div>
<div id='content'>
Main text box
</div>
<div id="footer"></div>
</div>
</div>
</body>
</html>
它需要如何工作:
【问题讨论】:
标签: css position margin floating