【问题标题】:Create a fixed div in the centre of a page在页面中心创建一个固定的 div
【发布时间】:2012-09-23 19:20:33
【问题描述】:

尝试在我的页面中心创建一个固定框(例如石灰框)

我无法弄清楚为什么该框不会在页面内居中,因为它的边距为自动,我假设这与它的固定定位有关?

#countdownHolder{
    width:700px;
    height:250px;
    margin: 0 auto;
    position:fixed;
    background-color:#0F0;
    z-index:21;
    text-align:center;
}

现场示例:http://www.rubytuesdaycreative.co.uk/

编辑:只是补充一下,我确实希望将 div 固定在页面中间,我只是希望它居中。

【问题讨论】:

  • 使用固定或绝对定位,您将无法使用“自动边距技术”居中。试试下面 NightHawk 的建议。

标签: html css margin css-position


【解决方案1】:

试试这个:

#countdownHolder {
    background-color: #00FF00;
    text-align: center;
    margin-left: -350px;
    position: fixed;
    left: 50%;
    height: 250px;
    width: 700px;
    z-index: 21;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多