0

I have this CSS for placing footer at the bottom

footer 
{
    position: fixed;
    bottom: 0;
}

but then the footer is not in full width so I have to add width: 100%; to be

footer 
{
    position: fixed;
    bottom: 0;
    width: 100%;
}

Why do I have to add width, but when the footer is on normal position it has full width (when I do nothing with CSS)? Why browser is doing that?

EDIT: putting only display: block; doesn't fix, <footer> is by default block element. Saying that's the default behavior of footer tag doesn't explain why it has full width when you do nothing with css.

4

2 回答 2

0

因为那是浏览器的默认行为。

http://www.w3.org/TR/CSS2/visuren.html#choose-position

http://css-tricks.com/snippets/css/fixed-footer/

于 2012-12-12T12:17:56.567 回答
0

浏览器这样做是因为这是页脚标签的默认行为。这就是为什么他们声明页脚元素以及新的 HTML5 元素

display:block

看到这个 normalize.css https://github.com/necolas/normalize.css/blob/master/normalize.css

您必须将元素声明为display:block,这样您就不必指定它的宽度。

检查这个.. http://dabblet.com/gist/4267350。您可能会注意到页脚元素已经拉伸到全宽,因为它已经在他们的 CSS中被称为display:block 。

于 2012-12-12T12:15:17.353 回答