Hi. I cant get the footer to stick in the bottom of the page. It only sticked to viewport. So when pages height goes over resolution it ruins the layout. Heres HTML and CSS

<!DOCTYPE html> 
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
<title>Viped.net</title>
</head>
<body>
<div id="container">
<div id="top">
<?php
include ("get_user_info.php");
session_start();
if (isLogdin() == true) {

    $sql = "";
    $sql = "SELECT * FROM modules WHERE enabled = 1";
    $result = mysql_query($sql);

    echo "<a href='index.php'><img src='pics/logo.png'></a> ";
    echo "<a href='index.php?s=tekstit'>Tekstit</a> ";
    echo "<a href='index.php?s=upload_file'>Tiedostot</a>";
    while ($row = mysql_fetch_array($result)) {
        echo "<a href='index.php?s=$row[name]'>" . $row['name'] . "</a>"; 
    }

    if (isAdmin() == true) {
        echo " <a href='index.php?s=admin'>Admin</a>";
    }

    echo "<a href='log_out.php' class='right'>Log out</a>";
    echo "<a href='index.php?s=user' class='right'>$UserName</a>";

} else {
    echo "<a href='index.php'><img src='pics/logo.png'></a> ";
}
?>
</div>

<?php 
//Virheilmoitukset näkyviin
//ini_set("display_errors", 1);
//ini_set("error_reporting", E_ALL | E_STRICT);
//Varsinainen koodi alkaa
$sql = "";
$sql = "SELECT * FROM modules WHERE enabled = 1";
$result = mysql_query($sql);
$s = $_GET['s'];
if (isLogdin() == true) {
    echo "<div id='main'>";
    if ($s == null) {
        include ("etusivu.php");
    } else if ($s == "tekstit") {
        include ("texttitles.php");
    } else if ($s == "new_text") {
        include ("new_text.php");
    } else if ($s == "text") {
        include ("texts.php");
    } else if ($s == "text_edit") {
        include ("text_edit.php");
    } else if ($s == "admin" && isAdmin() == true) {
        include ("admin.php");
    } else if ($s == "user") {
        include ("user.php");
    } else if ($s == "upload_file") {
        include ("upload_file.php");
    } else if ($s == "modules") {
        include ("modules.php");
    }   
    while ($row = mysql_fetch_array($result)) {
        if ($s == $row['name']) {
            include ("modules/$row[name]/index.php");
        }   
    }
    echo "</div>";
    echo "<div id='footer'>";
    echo "testi";

} else {
    echo "</div>";
    echo "<div id='nologd'>";
    include ("log_in.php");
    if (regOpen() == true) {
        echo "<br>" . "Rekisteröidy:" . "<br>";
        include ("register.php");
    }
    $s = $_GET['s'];
    echo "</div>";
}
function isLogdin() {
    if ($_SESSION["logdin"] != "") {
        return true;
    } else {
        return false;
    }
}

function isAdmin() {
    if ($_SESSION['admin']) {
        return true;
    } else {
        return false;
    }
}

function regOpen() {    
    include ("connect.php");
    $sql = "";
    $sql = "SELECT regopen FROM site";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    if ($row['regopen'] == "1") {
        return true;
    } else {
        die();
    }
}
?>
</div>

and the css

body {
    text-align: center;
    margin: 0 auto;
    background-color: #eeee11;
}

#top {

    text-align: left;
    background-color: #666666;
    width: 100%;
    height: 60px;
    border-bottom: 1px solid;

}

#container {
    width: 100%;
    height:100%
    margin: 0 auto;


}

#main {
    text-align: left;
    width: 60%;
    min-height: 500px;
    margin-left: auto;
    margin-right: auto;
    border-left: 1px solid;
    border-right: 1px solid;
    border-bottom: 1px solid;
    -moz-border-bottom-right-radius: 15px;
    border-bottom-right-radius: 15px;
    -moz-border-bottom-left-radius: 15px;
    border-bottom-left-radius: 15px;
    border-color: #000000;
    padding: 10px;
    left: 20%;
    background-color: #ffffff;
    position: absolute;
    z-index: 1;
}

#nologd {
    text-align: left;
}

a {
    text-decoration: none;
    color: black;
}

#top img {
    vertical-align: middle;
}

#top a {
    line-height: 60px;
    color: white;
    margin-left: 10px;
}

#footer {

    width: 100%;
    clear: both;
    position: absolute;

    bottom: 0px;

    min-height: 350px;

    background-color: #666666;

    border-top: 1px solid;

    z-index: -2;

}

.right {
    float: right;
    margin-right: 20px;
}

.table {
    width: 600px;
}

ul {
    line-height: 0px;
}

I first thought that I should remove php code and leave only html but I decided to leave it there for now if someone has ideas to make code better.

Recommended Answers

All 4 Replies

You need to define the total height,

So:

*{
    height: 100%;
}

body{
    height: 100%;
}

I think that shall solve it, good luck!

Thanks, but it didn't. It only makes footer start from top.

Okay fixed, not absolute positioning did the trick this time.

Okay it almost did the trick now the footer is bottom but it moves with viewport. When it should be scrolled out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.