html - 网页的CSS布局?

标签 html css

<分区>

我对 CSS 比较陌生。我正在尝试使用 HTML 和 CSS 创建一个正常的页面布局,但我遇到了一个问题。这是我的 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>
    <title>Jquery</title>
    <link rel="stylesheet" type="text/css" href="../css/StyleSheet1.css">
    <script type="text/javascript" src="../javascript/jQuery.js""></script>
</head>
<body>
    <div class="container">
        <div class="header"></div>
        <div class="content"></div>
        <div class="footer"></div>
    </div>
</body>
</html>

这是我的 CSS 脚本

html,body
{
    padding: 0px;
    margin: 0px;
    color: #555;
    font-size: 20px;
    font-family:  "Open Sans","lucida grande","Segoe UI",arial,verdana,"lucida sans unicode",tahoma,sans-serif;
    height: 100%;
}

.container
{
    height: 100%;
    background-color: Green;
    position: relative;
}

.header 
{
    height: 300px;
    width: 100%;
    background-color: Red;
}

.content
{
    width: 100%;
    background-color: Black;
}

.footer
{   
    height: 500px;
    width: 100%;
    background-color: Violet;
    position: absolute;
    bottom: 0px;
}

我正在尝试创建页眉、页脚和内容 div。但是我的内容 div 应该会自动改变它的高度。如果内容 div 中没有任何内容,那么我的页面的内容高度至少应等于(页面高度 - (页眉高度 + 页脚高度))。

最佳答案

将位置更改为相对位置如何?我稍微摆弄了一下:

.footer
{   
    height: 500px;
    width: 100%;
    background-color: green;
    position: relative;
    bottom: 0px;
}

JsFiddle example .看到它并告诉我这是你想要的。

关于html - 网页的CSS布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17682586/

相关文章:

html - Div 不删除 float - CSS

html - 响应式 HTML 电子邮件 - Outlook 的 3 列布局间距

html - 当我调整我的浏览器大小时,我的内容落在我的标题之外,我该如何阻止它?

html - 使 Nivo Slider 全宽

.net - .NET 中更好的 CSS?

php - 将文本区域按行转换为数组,然后使用 Jquery 将其附加到 div?

javascript - 在 HTML 表单上展开 div

html - Div AutoResize(好像它是空的)

jquery - 更改大于或小于给定值的值在 jQuery 中不起作用?

css - 使用语义主题更改选项卡背景