Get footer to go to bottom of display

时间:2015-07-13 21:05:20

标签: html css

I got this footer im wanting to go to the bottom of my display and stay there (not so much a fixed position as i want it to change with the content that is in it). at the moment its made to be a sticky footer and moves with the content, im just wanting it to be constantly positioned at the bottom of the display so there isnt this weird floating gap with a huge space beneath it.

HTML:

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">    
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Home</title>
            <!--===================================================css links===================================================!-->
            <link href='http://fonts.googleapis.com/css?family=Raleway:600,500,400,200' rel='stylesheet' type='text/css'>
            <link href='http://fonts.googleapis.com/css?family=Roboto:400,700,900,100,300' rel='stylesheet' type='text/css'>
            <link href="css/default_style.css" rel="stylesheet" type="text/css" />
            <link href="css/contact_style.css" rel="stylesheet" type="text/css" />
        </head>   
        <body>
            <!--===================================================Header===================================================!-->
            <div class="wrapper">
                <div class="headerwrap">
                    <div class="social">    
                        <a href="www.facebook.com"><img class="move" src="images/deviant.png"></a>
                        <a href="www.facebook.com"><img class="move" src="images/yt.png"/></a>
                        <a href="www.facebook.com"><img class="move" src="images/fb.png"/></a>
                    </div>
                    <!--close social!-->
                    <div class="header">
                        <div class="logo">
                            <img src="images/logo.png" />
                        </div>
                        <!--close logo-->
                    </div>
                    <!--close header!-->
                    <div class="menu">
                        <ul class="menutxt">
                            <li><a href="index.html">HOME</a>
                            </li>
                            <li><a href="portfolio.html">PORTFOLIO</a>
                            </li>
                            <li><a href="contact.html">CONTACT</a>
                            </li>
                        </ul>
                    </div>
                    <!--close menu!-->
                </div>
                <!--close headerwrap!-->
                <!--===================================================Contact===================================================!-->
                <div class="toptxt">
                    <div id="test2">
                        <p class="infotxt">Get in touch...</p>
                    </div>
                </div>
                <div class="detailwrap">
                    <div class="contactspace"></div>
                    <!--close contactspace!-->
                    <div class="contact">
                        <img class="move2" class="hover" src="images/me2.png">
                        <p class="text">Luke Babich</p>
                    </div>
                    <!--close contact!-->
                    <div class="contact">
                        <img class="move2" class="hover" src="images/phone.png">
                        <p class="text">+27 72 836 0954</p>
                    </div>
                    <!--close contact!-->
                    <div class="contact">
                        <img class="move2" class="hover" src="images/mail.png">
                        <p class="text">lukerbab@gmail.com</p>
                    </div>
                    <!--close contact!-->
                    <div class="contactspace"></div>
                    <!--close contactspace!-->
                </div>
                <!--close detailwrap!-->
                <!--===================================================Footer===================================================!-->
                <div class="footerwrap2">
                    <p class="foottxt">Designed and developed by Luke Babich- All Rights Reserved ©2015</p>
                </div>
                <!--close footerwrap!-->
            </div>
            <!--close wrapper!-->
        </body>
    </html>

</i>

Layout CSS:

@charset "utf-8";
/*---------------------------- Body and Default ----------------------------*/
body {
    margin:0 auto;
    background:#171717;
    font-family: 'Roboto', sans-serif;
    color:#CCC;
} 
a{
    color:#000;
    transition:300ms;
}
a:hover {
    color:#000;
}
a:link {
    text-decoration: none;
}
/*---------------------------- Main Wrapper ----------------------------*/
.wrapper{
    position:relative;
    width:100%; 
}
/*---------------------------- Header ----------------------------*/
.header{
    position:relative;
    min-height:180px;
    height: 100%;
    padding-right:225px;
    margin: 0;
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    align-items: center;
    justify-content: center;
    -moz-box-shadow: 0px 10px 20px 0px #333 ;
    -webkit-box-shadow: 0px 10px 20px 0px #333 ;
    box-shadow: 0px 10px 20px 0px #000;
    z-index:200;
}
.logo{
    position: absolute;
    min-width:60px; 
    top:4%;
}
.logo img{
    display: block;
    margin-left: auto;
    margin-right: auto;
    width:100%;
}
.social{
    position: absolute;
    width:100%;
    min-width:20px; 
    top:15px;
    right:1%;
    z-index:500;    
}
.social img{
    float:right;
    width:35px;
    display: block;
    padding:0 0 0px 15px;
}
img.move {
    bottom:0px;
    transition: transform 0.4s cubic-bezier(0.2, 1, 0.44, 1.2);
}
img.move:hover {
    -webkit-transform: scale3d(1.1, 1.1, 1.1);
    transform: scale3d(1.4, 1.4, 1.4);    
}
/*---------------------------- Menu ----------------------------*/
.menu{
    position:absolute;
    width:100%;
    top:200px;
    z-index:401;
}
ul {
    margin: 0 auto;
    padding:0 0 5px 0;
    list-style-type: none;
}
li{
    display: inline;
    list-style:none;
    padding:1%;
    transition: all 300ms;
}
li a{
    color:#CCC;
    transition:300ms;
}
li a:hover {
    color:#900;
}
.menutxt{
    text-align: center;
    font-family: 'Raleway', sans-serif;
    font-size:1.8vw;
    font-weight:400;
    z-index:300;
}
/*---------------------------- Footer Text ----------------------------*/
.foottxt{
    width:100%;
    text-align: center;
    background:#070707;
    font-family: 'Roboto', sans-serif;
    padding:15px 0;
    font-size:0.7em;
    color:#FFFFFF;
    font-weight:200;
    margin: 0;
    box-sizing: border-box;
}

Content CSS:

@charset "utf-8";
/*---------------------------- Content ----------------------------*/
.toptxt{
    margin-top:130px;
    width:100%;
}
/*.contactwrap{
    width:100%;                 change back if cant figure it out
    margin-top:60px;
}*/ 
.detailwrap{
    margin-top:100px;
    width:100%;
    text-align: center; /* center align .contacts */
}
/* clearfix */
.detailwrap:after {
    content: "";
    display: table;
    clear: both;
}
.infotxt{
    text-align: center;
    font-family: 'Raleway', sans-serif;
    font-size:2em;
    font-weight:400;
}
.contact {
    display: inline-block; /* make it possible to use text-align */
    width: 15%;
    min-width: 180px; /* avoid 15% being making the contacts less than 115px */
    margin: 4% 1% 10% 0;
}
.contact img{
    width: 90px;
    display: block;
    margin: 0 auto;
    max-width: 100%; /*bring back if needed*/
    height: auto;  /*bring back if needed*/
}
.contact .text {
    top:-15px;
    text-align:center;
    visibility:hidden;
}
.contact:hover .text {
    animation: fadein 2s;
    visibility:visible;
}
img.move2 {
    bottom:0px;
    transition: transform 1s cubic-bezier(0.2, 1, 0.44, 1.2);
}
img.move2:hover {
    -moz-transform: translate(-2px, -2px);
    -ms-transform: translate(-2px, -2px);
    -o-transform: translate(-2px, -2px);
    -webkit-transform: translate(-2px, -2px);
    transform: translate(0px, -10px)    
}
/*---------------------------- Footer ----------------------------*/
.footerwrap2{
    position:relative;
    width:100%;
    z-index:501;
    -moz-box-shadow: 0px -10px 20px 0px #000;
    -webkit-box-shadow: 0px -10px 20px 0px #000;
    box-shadow: 0px -10px 10px 0px #000;
}
/*---------------------------- Textfader ----------------------------*/
#test2 p {
    animation: fadein 5s;
    -moz-animation: fadein 5s; /* Firefox */
    -webkit-animation: fadein 5s; /* Safari and Chrome */
    -o-animation: fadein 5s; /* Opera */
    transition: opacity 5s;
}
@keyframes fadein {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-moz-keyframes fadein { /* Firefox */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-webkit-keyframes fadein { /* Safari and Chrome */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-o-keyframes fadein { /* Opera */
    from {
        opacity:0;
    }
    to {
        opacity: 1;
    }
}

i wasnt too sure what code was needed and had 2 style sheets that may affect the footer div......So basically im wanting .footerwrap2 to be at the bottom of the browser even after device and browser size changes. Thanks in advance!

1 个答案:

答案 0 :(得分:0)

我将所有代码复制到本地页面并添加以下行:

对于footerwrap2,我将位置从相对位置更改为绝对位置,并将其定位在页面底部。

position:absolute; bottom: 0;

正如您可能已经发现的那样,这还不够。正文和包装器div不知道内容页面是如何TALL的,因此,它们根据内容确定大小。

我通过将以下样式添加到主包装器(.wrapper)

来解决了这个问题
height: 100vh;

这使用最新的CSS3视图高度,因此它只适用于现代浏览器。如果您必须保持与旧浏览器的兼容性,则需要将主体,包装器以及可能的html标签的高度设置为100%。

我在本地测试它,它就像一个冠军。如果你无法让它发挥作用,我会把它变成小提琴。

祝你好运!