简体   繁体   English

如何在CSS / HTML中获得页脚?

[英]how do i get a sticky footer in CSS/HTML?

I have used this guys guide. 我曾经用过这个家伙指南。

http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page

however my footer just sits in the middle of the page and not the full width across the page. 但是我的页脚仅位于页面的中间,而不是页面的整个宽度。

Can anybody help please. 有人可以帮忙吗?

Here's the CSS. 这是CSS。

body {
background: url(images/topbg.png) repeat-x;
font-family: Arial, Helvetica, sans-serif;
font-size: 17px;
color:#000;
margin:0;
padding:0;
height:100%;
}


h1 {
font-size:100px;
color:#FFF; 
line-height: 10%;
font-family: 'Exo', sans-serif;
}

h2 {
font-size:100px;
color: #18942f; 
line-height: 80%;
font-family: 'Exo', sans-serif;
}

h3 {
font-size: 20px;    
}

.page-container {

width: 960px;
margin-bottom: auto; 
margin-left: auto; 
margin-right: auto;
min-height:100%;
position:relative;

}

.top-nav ul {
margin: 0;
list-style: none;
line-height: normal;
}

.top-nav li {
margin-left: 220px;
}

.top-nav a {
display: block;
float: left;
height: 38px;
margin-right: 1px;
padding: 4px 30px 0 30px;
text-decoration: none;
font-size: 34px;
font-weight: bold;
font-family: 'Exo', sans-serif;
color: #FFF;
}

.top-nav a:hover {
background:  #272727;
color: #18942f;
}

.top-nav .current_page_item a {
background:  #252525;
color: #FFF;
}

#name {
float: left;
margin-top: 70px;
}

#badge {
float:right;
margin-right: 100px;
margin-top: 10px;

}
.info {
clear: both;
padding-bottom:60px;
}

#about {
height: 250px;
width: 300px;
float:left;
}

#about2 {
width: 860px;   
}

#skills {
height: 250px;
width: 300px;
float: left;
text-align: center; 
}

#contact {
height: 250px;
width: 300px;
float: left;
text-align: right;
}

.about3 {
float:left;
width: 500px;   
}
.picture1 {
margin-left: 560px;
padding-top: 25px;
}
.about4 {
width:450px;

}

.footer {

background: url(images/footer.png)repeat-x;
position:absolute;
bottom:0;
width:100%;
height:60px;
}

.footer-links {
font-family:'Exo', sans-serif;
color: #FFF;
font-size:26px;
padding-top: 50px;
text-align:center   
}

And here's the HTML 这是HTML

<div class="page-container">
<div class="top-nav"> 
  <ul> 
    <li class="current_page_item"><a href="#">Home</a></li> 
    <li><a href="aboutme.html" class="links">About Me</a></li> 
    <li><a href="skills.html" class="links">Skills</a></li> 
    <li><a href="contact.php" class="links">Contact</a></li> 
  </ul> 
</div>
<div id="name"><h1>My</h1>
  <h2>Name</h2></div>
  <div id="badge"><img src="images/webbadge.png" alt="" width="310" height="310" /></div>
  <div class="info">
  <div id = "about"> </div>
   <div id = "skills"> </div>
  <div id = "contact"></div>

<div class ="footer">
<div class ="footer-links">

<a href="#" style="color:#FFF">Home </a> -

<a href="#" style="color:#FFF">About</a> -

<a href="#" style="color:#FFF">#</a> -

<a href="#" style="color:#FFF">#</a>
</div>
</div>
</div>
<style>
 .footer
{
   position:fixed;
   bottom:0px;
   z-index:2;
   width:100%;
   padding:5px;
}
</style>

just as simple as that? 就这么简单吗?

This one works pretty well, and has been tested across multiple browsers. 该程序运行良好,并且已经在多种浏览器上进行了测试。 Offers the basic CSS/HTML to get you started, and a decent manual 提供基本的CSS / HTML入门,以及不错的手册

http://www.cssstickyfooter.com/ http://www.cssstickyfooter.com/

This should be : 应该是:

.footer {
background: url(images/footer.png)repeat-x;
width:100%;
height:60px;
}

or: 要么:

.footer {
background: url(images/footer.png)repeat-x;
position:absolute;
top:{TOP}px;
width:100%;
height:60px;
}

With playing with {TOP} to fix the footer where you want. 与{TOP}一起玩,将页脚固定在所需的位置。

I did a bit of clean up on your code, this is how I would tackle the problem: 我对您的代码做了一些清理,这就是我要解决的问题:

http://jsfiddle.net/hPWVk/ http://jsfiddle.net/hPWVk/

HTML HTML

    <div class="page-container">

        <div class="top-nav"> 
            <ul> 
                <li class="current_page_item"><a href="#">Home</a></li> 
                <li><a href="aboutme.html" class="links">About Me</a></li> 
                <li><a href="skills.html" class="links">Skills</a></li> 
                <li><a href="contact.php" class="links">Contact</a></li> 
            </ul> 
        </div>

        <div class="content">

            <div id="name">
                <h1>My</h1>
                <h2>Name</h2>
            </div>

            <div id="badge"><img src="images/webbadge.png" alt="" /></div>

            <div class="info">
                <div id = "about"></div>
                <div id = "skills"></div>
                <div id = "contact"></div>

            </div>

        </div>

        <div class ="footer">
            <div class ="footer-links">
                <a href="#" style="color:#FFF">Home </a> -
                <a href="#" style="color:#FFF">About</a> -
                <a href="#" style="color:#FFF">#</a> -
                <a href="#" style="color:#FFF">#</a>
            </div>
        </div>

    </div>

</body>

CSS CSS

body {
background:orange url(images/topbg.png) repeat-x;
font-family: Arial, Helvetica, sans-serif;
font-size: 17px;
color:#000;
margin:0;
padding:0;
height:100%;
}


h1 {
font-size:100px;
color:#FFF; 
line-height: 10%;
font-family: 'Exo', sans-serif;
}

h2 {
font-size:100px;
color: #18942f; 
line-height: 80%;
font-family: 'Exo', sans-serif;
}

h3 {
font-size: 20px;    
}

.page-container {

width: 960px;
margin-bottom: auto; 
margin-left: auto; 
margin-right: auto;
min-height:100%;
position:relative;

}

.top-nav
{
   overflow:hidden; 
}

.top-nav ul {
margin: 0;
list-style: none;
line-height: normal;
}

.top-nav li {
margin-left: 220px;
}

.top-nav a {
display: block;
float: left;
height: 38px;
margin-right: 1px;
padding: 4px 30px 0 30px;
text-decoration: none;
font-size: 34px;
font-weight: bold;
font-family: 'Exo', sans-serif;
color: #FFF;
}

.top-nav a:hover {
background:  #272727;
color: #18942f;
}

.top-nav .current_page_item a {
background:  #252525;
color: #FFF;
}


.content { overflow:hidden; }

#name {
float: left;
margin-top: 70px;
}

#badge {
float:right;
margin-right: 100px;
margin-top: 10px;

}

#badge img { width:50pxl height:50px; }

.info {
overflow:hidden;
padding-bottom:60px;
}

#about {
height: 250px;
width: 300px;
float:left;
}

#about2 {
width: 860px;   
}

#skills {
height: 250px;
width: 300px;
float: left;
text-align: center; 
}

#contact {
height: 250px;
width: 300px;
float: left;
text-align: right;
}

.about3 {
float:left;
width: 500px;   
}
.picture1 {
margin-left: 560px;
padding-top: 25px;
}
.about4 {
width:450px;

}

.footer {

background: url(images/footer.png)repeat-x;
position:fixed;
bottom:60px;
width:100%;
height:60px;
}

.footer-links {
font-family:'Exo', sans-serif;
color: #FFF;
font-size:26px;
padding-top: 50px;
text-align:center   
}​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM