【问题标题】:CSS Footer Fixed Width, Bottom of screen, and centredCSS 页脚固定宽度、屏幕底部和居中
【发布时间】:2011-10-25 18:18:14
【问题描述】:

我主要是一名 iPhone 开发人员,我对 CSS 有点垃圾,我正在尝试为我的应用制作网页。

我想让我的页脚具有以下属性:

  • 固定宽度为 640 像素
  • 居中
  • 附加到屏幕的底部,而不是页面。所以当用户调整窗口大小时,页脚总是在底部

我可以自己做所有其他样式,只是位置样式我觉得很难。

有人可以向我解释一下如何在 CSS 中做到这一点。

【问题讨论】:

标签: css html footer


【解决方案1】:
footer {
    width: 640px;
    margin: 0% -320px;
    position: fixed;
    left: 50%;
    bottom: 0%;
}

示例:http://jsbin.com/imisig/3

文本堆示例:http://jsbin.com/imisig/4

【讨论】:

  • 您将如何修改代码以使其流动性达到 60%?只是感兴趣
  • 您可以使用width: 60%;left: 20%;,而不使用margin。见jsbin.com/imisig/11
【解决方案2】:

将页脚 HTML 放入 <div id="footer">。 CSS 应该是这样的:

#footer {
    width: 640px;
    position: fixed;
    bottom: 0px;
    left: 50%;
    margin-left: -320px;
}

解释

  • width 属性将宽度设置为640px
  • position: fixed 将使其随页面滚动
  • bottom: 0px 使其固定在页面底部(到底部的距离 = 0px)
  • left: 50%div 的左侧放在页面中心
  • margin-left: -320px - 现在我们必须将其从左侧移动 320px 以使其居中

【讨论】:

  • marginauto 不适用于 positionfixed;页脚将位于屏幕左侧。请参阅我的答案以了解改进的方法。
  • 没问题。 -310px 应该是 -320px,顺便说一句。
猜你喜欢
  • 2012-01-12
  • 1970-01-01
  • 1970-01-01
  • 2016-12-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-09
  • 2013-04-29
  • 2015-08-30
相关资源
最近更新 更多