html - CSS 导航栏改变大小

标签 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>

最佳答案

更改样式

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/

关于html - CSS 导航栏改变大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42832933/

相关文章:

javascript - 如何使 div 可编辑到 textarea 并上传/删除现有图像

html - 如何在我的网站上显示 SVG 图像?

css - 如何为 IE 和其他浏览器居中这个容器?

jquery - 使用 AJAX 请求和注入(inject) html,但是如何将 css 应用于注入(inject)的 html?

css - 有没有办法在 CSS 中制作自定义边框?

iphone - float :right; elements causing elements to break outside of containers on iPhone/iPad

html - 为什么包含的 div 需要填充以使包含的元素的边距位于 div 中?

javascript - 在导航栏正下方制作 Bootstrap 轮播

html - SVG 变换 :rotate() not working in ie9

html - CSS:将背景图像添加到:具有淡入淡出效果的伪元素之后