CSS页脚布局问题

时间:2011-05-09 22:29:26

标签: css layout footer

我试图创建一个跨浏览器3列页脚,它们的宽度相等,但不会超出900px的主体宽度。这段代码没有这么做??

html
<div id="footer">
    <p class="left">About<br />Contact<br />Next line here</p>
    <p class="right"> does not evaluate or guarantee the accuracy</p>
<p class="centered">Terms<br />Privacy<br />Disclaimer</p>
</div>

css
 #footer  {
  color: #ffffff;
  width:100%;
  background: #111;
  clear: both;
  overflow: auto;   
   } 

.left {
text-align:left;
float:left;
}

.right{
float:right;
text-align:right;
}

.centered{
text-align:center;
}  

4 个答案:

答案 0 :(得分:1)

我能看到的最简单的解决方案是:

#footer {
    width: 900px;
}
#footer > p {
    width: 30%;
    display: block;
    float: left;
}

p:nth-child(odd) {
    background-color: #ccc;
}

JS Fiddle demo

<小时/> 已修改建议稍作修改,因为您的页脚div似乎是其他内容的链接列表,我建议修改您的加价,并将以下内容作为建议指南:

<div id="footer">
    <ul>
        <li>menu one
            <ul>
                <li>About</li>
                <li>Contact</li>
                <li>Next line here</li>
            </ul></li>
        <li>menu two
            <ul>
                <li>Does not evaluate, or guarantee the accuracy</li>
            </ul></li>
        <li>menu three
            <ul>
                <li>Terms</li>
                <li>Privacy</li>
                <li>Disclaimer</li>
            </ul></li>
    </ul>
</div>

CSS:

#footer {
    width: 900px;
    overflow: hidden;
}

#footer > ul {
    width: 100%;
}

#footer > ul > li {
    width: 30%;
    display: block;
    float: left;
    font-weight: bold;
}

#footer > ul > li > ul {
    font-weight: normal;
}

JS Fiddle demo

答案 1 :(得分:1)

试试这个:

    <div id="footer">
    <div class="left">About<br />Contact<br />Next line here</div>
    <div class="right"> does not evaluate or guarantee the accuracy</div>
<div class="centered">Terms<br />Privacy<br />Disclaimer</div>
</div>

用于你的html,这适用于你的风格:

#footer  {
  color: #ffffff;
  width:100%;
  background: #111;
 overflow: auto;   
   } 
#footer div {
 width:33%;   
}
.left {
text-align:center;
float:left;
}

.right{
float:right;
text-align:center;
}

.centered{
text-align:center;
    float:left;
}  

如此小提琴所示:http://jsfiddle.net/kLqZP/9/

答案 2 :(得分:1)

HTML

>   <div id="footer">
>         <p class="left">About<br />Contact<br />Next line here</p>
>         <p class="centered">Terms<br />Privacy<br />Disclaimer</p>
>         <p class="right"> does not evaluate or guarantee the accuracy</p>
>     
>     </div>
>     
>     css
>      #footer  {
>       color: #ffffff;
>       width:100%;
>       background: #111;
>       clear: both;
>       overflow: auto;   
>        } 
>     
>     .left {
>     text-align:left;
>     float:left;
>     }
>         .centered{
>     text-align:center;
>     float:left;  }
> 
>     .right{
>     float:left;
>     text-align:right;
>     }

只需在每列中添加float,然后排列div。看看是否有效

答案 3 :(得分:0)

如果你浮动你的<p>他们将从他们的内容中取出他们的宽度,他们将不会有相同的大小。而BTW,div

可能<p>可能是更好的选择