首页 > 解决方案 > HTML/CSS 网页看起来不应该

问题描述

1)我的nav和aside不够高。他们不会在应该的地方开始,也不会在应该的时候结束。

2)我的部分(以及导航和旁边)不会在页面底部结束。

3) 我的页脚不在页面底部。

我正在使用 HTML 和 CSS。我目前正在使用谷歌浏览器。

我希望我的页面如下所示:

在此处输入图像描述

它看起来像这样: 在此处输入图像描述

HTTP:

<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <title>Titulazo</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <link rel="manifest" href="site.webmanifest">
  <link rel="apple-touch-icon" href="icon.png">
  <!-- Place favicon.ico in the root directory -->
  <link rel="stylesheet" href="css/normalize.css">
  <link href="style.css" rel="stylesheet">  
  <link rel="stylesheet" href="css/main.css">   

</head>

<body>      
    <header id = "MainHeader">
        <h1>Main Header h1</h1>
        <p>Hello world! This is HTML5 Boilerplate.</p>
    </header>

    <nav>
        <h1>Nav h1</h1>
        <ul>
            <li>bla</li>
            <li>bla</li>
            <li>bla</li>            
        </ul>
    </nav>

    <section>
        <h1>Section h1</h1>
        <header>
            <h1>Section header</h1>
        </header>   

        <article>
            <h1>Article h1</h1>
            <p>Posted on <time datetime="2009-10-22">October 22, 2009</time></p>
            <p>Article text</p>
        </article>

        <footer>
            <h1>Section Footer</h1>
        </footer>
    </section>

    <aside>
        <h1>Aside h1</h1>
        <p>Aside text</p>       
    </aside>

    <footer id = "MainFooter">
        <h1>Main Footer, copyright 2018, Álvaro Puertas</h1>
    </footer>


    <!-- Google Analytics: change UA-XXXXX-Y to be your site's ID. -->
    <script>
    window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
    ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
    </script>
    <script src="https://www.google-analytics.com/analytics.js" async defer></script>
</body>

</html>

CSS:

body{
    width:100%;
    position:absolute;
    height:auto; 
}

header#MainHeader{  
    width: auto;
    height: auto;
    background-color: orange;
    margin: 20px;        
 } 

nav { 
  position: relative;
  float: left;
  height: auto;  
  width:200px;
  margin: 20px;
  top: 0px;
  background-color: lightblue;
  bottom: 0px;
}

section{
    width: 900px;
    height: auto; 
    float: left;    
    top: 500px;
    background-color: pink; 
}

aside{
    width: 200px;
    height: 100%;
    margin: 20px;
    top: 0px;
    float: right;
    background-color: lightgreen;   
}

footer#MainFooter{
    width: auto;
    height: auto;   
    background-color: gray;

    margin: 20px;   
    clear:both; 
}

标签: htmlcssuser-interface

解决方案


尝试添加以下css:最终输出:点击这里

body{
    width:100%;
    position:absolute;
    height:auto; 
    margin: 0;
}

/*mycode*/
header p{
  margin-bottom: 0;
}


header#MainHeader{  
    width: auto;
    height: auto;
    background-color: orange;
    margin: 20px;        
 } 

nav { 
  position: relative;
  float: left;
  height: 100%;
  min-height: 75vh;  
  width:15%;
  margin: 0 20 10px 20px;
  top: 0px;
  background-color: lightblue;
  bottom: 0px;
}

section{
    width: 64%;
    min-height: 75vh; 
    float: left;    
    top: 500px;
    background-color: pink; 
}

aside{
    width: 15%;
    height: 100%;
    min-height: 75vh;
    margin: 0 20 10px 20px;
    top: 0px;
    float: right;
    background-color: lightgreen;   
}

footer#MainFooter{
    width: auto;
    height: auto;   
    background-color: gray;

    margin: 20px;   
    clear:both; 
}

这不是最好的做法。我建议您学习引导网格布局并学习使用 chrome 开发人员工具。


推荐阅读