如何制作动态内容定位?

时间:2011-07-06 14:08:28

标签: html css

您会看到大量网站的内容非常集中,例如dribbble.com。即使调整窗口大小,内容保持居中,当它击中页面的一侧时,停止。

我真的想在我的网站上得到这种行为,但我不确定如何去实现这一点......我知道position属性并使用百分比左/右定位,但似乎并不那么简单。

有人可以帮我弄清楚如何做这样的事吗?

3 个答案:

答案 0 :(得分:3)

  

我知道位置属性并使用左/右定位的百分比,但它似乎并不那么简单。

这更简单。

selector-that-matches-a-container {
    width: <some length>
    margin: auto;
}

答案 1 :(得分:3)

标准做法是设置一个包含中心内容的div,例如......

<div id="container">
   ...everything you want to center
</div>

在CSS中:

#container {
  width: 970px;
  margin: 0 auto; /*first value the margin for top and bottom, auto puts automatic margins in the left and right to center the content*/
}

答案 2 :(得分:2)

也许使用这个CSS:

.content {
  position:absolute;
  left:100px;
  right:100px;
}
相关问题