【问题标题】:Css for header,section and footer arrangement用于页眉、节和页脚排列的 CSS
【发布时间】:2017-11-07 15:20:19
【问题描述】:

我有基本的 html 代码:

<header></header>
<main>
<nav></nav>
<section></section>
</main>
<footer></footer>

我需要css来让页眉在顶部,页脚在底部,导航和页眉和页脚之间的部分,导航在左边,部分在右边。

例如:https://fr.wikipedia.org/

但在主要内容小于屏幕尺寸的情况下,我需要将页脚固定在屏幕底部。

我的 CSS 是这样的:

    header, nav, section, footer {
        padding: 1px 0;
    }

    header {
        background-color: lightcoral;
        text-align: center;
        background: #FF9900 url("/Content/Images/Etoile.png") 5px center no-repeat;
        background-size: 100px;
    }

    main {
        margin: auto;
    }

    nav {
        float: left;
        width: 15%;
        background-color: lightsalmon;
    }

    section {
        float : right;
        width : 85%;
        background-color: lightblue;
    }

    footer {
        background-color: lightgreen;
        text-align: center;
        clear: both;
    }

你能帮帮我吗?

【问题讨论】:

  • 你能发布你当前遇到的问题来展示这个问题吗?另请参阅How to create a Minimal, Complete, and Verifiable example
  • header, nav, section, footer { padding: 1px 0;} header { background-color: lightcoral;文本对齐:居中;背景:#FF9900 url("/Content/Images/Etoile.png") 5px center no-repeat;背景尺寸:100px;} 主 { 边距:自动;} 导航 { 浮动:左;宽度:15%;背景颜色:lightsalmon;}部分{浮动:对;宽度:85%;背景颜色:浅蓝色;} 页脚 { 背景颜色:浅绿色;文本对齐:居中; clear: both;} 对不起,我不知道怎么写like code
  • @LuisP.A.好的,看起来不错,但我需要一个标题,左侧的导航和右侧的部分。我会尝试这个解决方案
  • 我已经尝试在 Google 上搜索。事实上,我正在寻找解决方案的 2 小时。我尝试了所有我发现的东西,但都没有奏效

标签: html css header height footer


【解决方案1】:

您要做的是创建一个简单的页面布局。您可以查看this resource 了解有关如何执行此操作的一般信息,因为有多种方法。

从上述资源中获取的一个示例是使用 CSS float 属性。它应该为您提供足够的解决方案。

<!DOCTYPE html>
<html>
<head>
<style>
div.container {
    width: 100%;
    border: 1px solid gray;
}

header, footer {
    padding: 1em;
    color: white;
    background-color: black;
    clear: left;
    text-align: center;
}

nav {
    float: left;
    max-width: 160px;
    margin: 0;
    padding: 1em;
}

nav ul {
    list-style-type: none;
    padding: 0;
}
   
nav ul a {
    text-decoration: none;
}

article {
    margin-left: 170px;
    border-left: 1px solid gray;
    padding: 1em;
    overflow: hidden;
}
</style>
</head>
<body>

<div class="container">

<header>
   <h1>City Gallery</h1>
</header>
  
<nav>
  <ul>
    <li><a href="#">London</a></li>
    <li><a href="#">Paris</a></li>
    <li><a href="#">Tokyo</a></li>
  </ul>
</nav>

<article>
  <h1>London</h1>
  <p>London is the capital city of England. It is the most populous city in the  United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>
  <p>Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the Romans, who named it Londinium.</p>
</article>

<footer>Copyright &copy; W3Schools.com</footer>

</div>

</body>
</html>

【讨论】:

猜你喜欢
  • 2016-03-05
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-02
  • 2016-04-12
  • 2023-03-28
相关资源
最近更新 更多