如何使页脚占据网页宽度的100%?

时间:2014-07-04 10:33:10

标签: html css

<!DOCTYPE html>
<html>
    <head lang="en">
        <meta charset="utf-8">
        <title>Jack Yuan | Web Developer</title>
        <link rel="stylesheet" href="CSS/normalize.css">
        <link href='http://fonts.googleapis.com/css?family=Gloria+Hallelujah' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Lobster&subset=latin,cyrillic-ext' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="CSS/main.css">
        <link rel="stylesheet" href="CSS/responsive.css">

    </head>

    <body>

        <header>

            <a href="index.html" id="logo">
                <h1>Jack Yuan</h1>
                <h2>Web Developer</h2>
            </a>

            <nav>

                <ul>
                    <li><a href="about.html"class="selected">About</a></li>
                    <li><a href="portfolio.html">Portfolio</a></li>
                    <li><a href="contact.html">Contact</a></li>
                </ul>

            </nav>
        </header>
        <div id="wrapper">
        <section>
            <ul id="gallery">
                <li id="pic1">
                    <a href="img/Jack.jpg">
                    <img src="img/Jack.jpg" width="500" height="400" alt="">
                    <p> This is me </p>
                    </a>
                </li>
                <li id="pic2">
                    <a href="img/Life.jpg">
                    <img src="img/Life.jpg"width="500" height="400"  alt="">
                    <p> This concludes my life(lol!) </p>
                    </a>
                </li>
                <li id="pic3">
                    <a href="img/Study.jpg">
                    <img src="img/Study.jpg"width="500" height="400" alt="">
                    <p> This shows what I study </p>
                    </a>
                </li>
                <li id="pic4">
                    <a href="img/2.jpg">
                    <img src="img/2.jpg"width="500" height="400" alt="">
                    <p> This is what I believe</p>
                    </a>
                </li>
            </ul>
        </section>
        <footer>
            <div id="mus">
            <embed src="Neo.mp3" loop="true" autostart="true" height="55mm">
            </div>
            <div id="logo">
            <a href="https://www.facebook.com/jackyuan.jack">
            <img src="img/facebook.gif" alt="FaceBook Logo" class="icon">
            </a>
            <a href="https://twitter.com/Jack19909100">
            <img src="img/twitter.png" alt="Twitter Logo" class="icon">
            </a>
            </div>
            <p>Jack Yuan</p>
            <p>All Rights Reserved.</p>
        </footer>
      </div>
    </body>
</html>

这是我的CSS

a {
    text-decoration:none;
}



#wrapper {
    max-width:940px;
    margin: 0 auto;
    padding: 0 5%;
}

#logo {
    text-align: center;
    margin: 0;
}

h1 {
    margin: 0;
    padding-top: 4mm;
    font-size: 2em;
    font-family: 'Lobster', cursive;
    font-weight: normal;
    line-height: 0.8em;
}

h2 {
    font-family: 'Gloria Hallelujah', cursive;
    font-size: 1.5em;
    margin: -5px 0 0;
    font-weight: normal;
}

body{
    font-family: 'Gloria Hallelujah', cursive;
}

a {
    color: #6ab47b;
}

header{
    background: #6ab47b;
    border-color:#599a68;
    float:left;
    margin: 0;
    padding: 5px 0 0 0;
    width: 100%;
}

nav{
    background:  #599a68;
    text-align: center;
    margin: 20px 0 0;
}

nav a, nav a:visited {
    color:#fff;
}

nav ul{
    list-style: none;
    margin: 0 10px;
    padding: 0;
}



nav a{
    font-weight: 800;
    padding: 15px 10px;
}

h1, h2{
    color:#fff;
}

nav a.selected , nav a:hover {
    color:#32673f;
}

footer{
    font-size: 1em;
    text-align: center;
    clear:both;
    padding-top: 20px;
    color: #ccc;
    line-height: 0.8em;
    background: black;
    margin:0;
}


img{
    max-width: 100%;
}

#gallery{
    margin: 0;
    padding: 0;
    list-style: none; /** remove bullet point **/
}

#gallery li{
    float:left;
    width: 45%;
    margin: 2.5%;
    background-color: #f5f5f5;
    color: #bdc3c7;
}

#gallery li a p{
    margin: 0;
    padding: 0;
    font-size: 1.5em;
    color: #bdc3c7;
}



.icon{
    width: 40px;
    height: 40px;
    margin: 5mm 5px;
}

body{
    background: orange;
    margin:0;
    color:#999;
}

为什么它只占网页宽度的一部分? 我试图设置最大宽度和宽度100%,它没有用。 如何使页脚占据网页宽度的100%? 这就是我想要做的。

4 个答案:

答案 0 :(得分:4)

footer位于div.wrapper内。将其移到div之外。您必须修复margin

答案 1 :(得分:0)

您当前的结构是:

<div id="wrapper"> ... <footer> .. </footer> </div>

你必须从包装div中拉出页脚,如:

<div id="wrapper"> ...  </div> <footer> .. </footer>

<强> Demo

答案 2 :(得分:0)

<!DOCTYPE html>
<html>
    <head lang="en">
        <meta charset="utf-8">
        <title>Jack Yuan | Web Developer</title>
        <link rel="stylesheet" href="CSS/normalize.css">
        <link href='http://fonts.googleapis.com/css?family=Gloria+Hallelujah' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Lobster&subset=latin,cyrillic-ext' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="CSS/main.css">
        <link rel="stylesheet" href="CSS/responsive.css">

    </head>

    <body>

        <header>

            <a href="index.html" id="logo">
                <h1>Jack Yuan</h1>
                <h2>Web Developer</h2>
            </a>

            <nav>

                <ul>
                    <li><a href="about.html"class="selected">About</a></li>
                    <li><a href="portfolio.html">Portfolio</a></li>
                    <li><a href="contact.html">Contact</a></li>
                </ul>

            </nav>
        </header>
        <div id="wrapper">
        <section>
            <ul id="gallery">
                <li id="pic1">
                    <a href="img/Jack.jpg">
                    <img src="img/Jack.jpg" width="500" height="400" alt="">
                    <p> This is me </p>
                    </a>
                </li>
                <li id="pic2">
                    <a href="img/Life.jpg">
                    <img src="img/Life.jpg"width="500" height="400"  alt="">
                    <p> This concludes my life(lol!) </p>
                    </a>
                </li>
                <li id="pic3">
                    <a href="img/Study.jpg">
                    <img src="img/Study.jpg"width="500" height="400" alt="">
                    <p> This shows what I study </p>
                    </a>
                </li>
                <li id="pic4">
                    <a href="img/2.jpg">
                    <img src="img/2.jpg"width="500" height="400" alt="">
                    <p> This is what I believe</p>
                    </a>
                </li>
            </ul>
        </section>
      </div>
    <footer>
        <div id="mus">
        <embed src="Neo.mp3" loop="true" autostart="true" height="55mm">
        </div>
        <div id="logo">
        <a href="https://www.facebook.com/jackyuan.jack">
        <img src="img/facebook.gif" alt="FaceBook Logo" class="icon">
        </a>
        <a href="https://twitter.com/Jack19909100">
        <img src="img/twitter.png" alt="Twitter Logo" class="icon">
        </a>
        </div>
        <p>Jack Yuan</p>
        <p>All Rights Reserved.</p>
    </footer>
    </body>
</html>

Woking jsFiddle

实际上你必须在主DIV之外取出......

答案 3 :(得分:0)

试试这个:

CSS

footer{
font-size: 1em;
text-align: center;
clear:both;
margin:0;
}

.footer_content{
width: 100%;
position: absolute;
left: 0;
font-size: 1em;
text-align: center;
clear:both;
padding-top: 20px;
color: #ccc;
line-height: 0.8em;
background: black;
margin:0;
}

HTML

    <footer>
        <div class="footer_content">
        <div id="mus">
        <embed src="Neo.mp3" loop="true" autostart="true" height="55mm">
        </div>
        <div id="logo">
        <a href="https://www.facebook.com/jackyuan.jack">
        <img src="img/facebook.gif" alt="FaceBook Logo" class="icon">
        </a>
        <a href="https://twitter.com/Jack19909100">
        <img src="img/twitter.png" alt="Twitter Logo" class="icon">
        </a>
        </div>
        <p>Jack Yuan</p>
        <p>All Rights Reserved.</p>
        </div>
    </footer>