CSS导航栏改变大小

时间:2017-03-16 11:33:07

标签: html css

所以我希望我的导航栏与内容框的大小相同。但是,当在不同的显示器上时,导航大小会改变并变形。我尝试了一切,使它保持相同的大小,我不能

Html编码 -

body {
  background-color: rgb(229, 178, 146);
}

ul.navigation {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid;
  background-color: #333;
  width: 80%;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 20px 103.8px;
  text-decoration: none;
  float: left;
}

li a:hover {
  background-color: #FFF;
  color: #000;
}

.active {
  background-color: #000;
}

div.content {
  background-color: #FFF;
  width: 80%;
  height: 100%;
  margin: -22;
}

div.footer {
  background-color: #333;
  text-align: center;
  overflow: hidden;
  color: white;
  border: solid;
  width: 100%;
  padding: 0%;
  margin auto;
}

hr {
  border: 1px solid;
  border-color: #FFF
}

h1 {
  text-align: center;
  color: grey;
}
<!DOCTPYE HTML>
<html>

<head>
  <title>Shahed's Portfolio</title>
  <link rel="stylesheet" type="text/css" href="css/site.css" />
</head>

<body>
  <hr/>
  <h1>Shahed Miah's Portfolio</h1>
  <hr/>
  <center>
    <ul class="navigation">
      <li><a class="active" href="home.html">Home</a></li>
      <li><a href="about.html">About</a></li>
      <li><a href="projects.html">Projects</a></li>
      <li><a href="contact.html">Contact</a></li>
    </ul>

    <div class="content">
      <h1>Home</h1>
      <p>What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make
        a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
        and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    </div>
  </center><br/>

  <div class="footer">
    <p>Copyright &copy;Shahed Miah</p>
  </div>


</body>

</html>

1 个答案:

答案 0 :(得分:1)

更改css

body {
    background-color: rgb(229, 178, 146);
}
ul.navigation {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid;
    background-color: #333;
    width: 80%;


}
li{float: left;
    width: 25%;}
li a {
    display: block;
    color: white;
    text-align: center;
    padding: 20px 0;
    text-decoration: none;

}

li a:hover {
    background-color: #FFF;
    color: #000;
}
.active {
    background-color: #000;
}
div.content {
    background-color: #FFF;
    width: 80%;
    height: 100%;
    margin: -22px;

}
div.footer {
    background-color: #333;
    text-align: center;
    overflow: hidden;
    color: white;
    border: solid;
    width: 100%;
    padding: 0%;
    margin auto;
}
hr {
    border: 1px solid;
    border-color: #FFF
}
h1 {
    text-align: center;
    color: grey;
}

https://jsfiddle.net/LLk9a8fq/