CSS导航菜单的位置

时间:2016-11-22 02:10:20

标签: html css

对不起,我的英语不是很好。

body {
  font-size: 16px;
  font-family: heveltica;
  margin: 0;
  padding: 0;
}

/*Con tenedor de la barra de navegacion*/
.container_menu {
  height: 100%;
  width: 18rem;
  display: inline-block;
  position: fixed;
  background-color: gray;
}

.container_menu .menu {
  width: 100%;
}

.container_menu ul {
  list-style-type: none;
}

.container_menu .menu li a{
  color: white;
  display: block;
  padding: 1rem 1.5rem;
  background-color: black;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="css/style.css" type="text/css">
  <title>MDN - Mockup</title>
</head>
<body>
  <nav class="container_menu">
    <ul class="menu">
      <li><a href="#">Teaching Activities</a></li>
      <li><a href="#">Web Literacy</a></li>
      <li><a href="#">Leadership Opportunities</a></li>
      <li><a href="#">Tools</a></li>
      <li><a href="#">Comunity</a></li>
    </ul>
  </nav>

  <main></main>

  <<footer></footer>

</body>
</html>

我在“.container_menu”中找到“ul”元素时遇到问题。假设以黑色显示的内容应完全适合于container_menu(灰色),但它有点外。

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:2)

&#13;
&#13;
ul {
  padding: 0;
  margin: 0;
}

body {
  font-size: 16px;
  font-family: heveltica;
  margin: 0;
  padding: 0;
}

/*Con tenedor de la barra de navegacion*/
.container_menu {
  height: 100%;
  width: 18rem;
  display: inline-block;
  position: fixed;
  background-color: gray;
}

.container_menu .menu {
  width: 100%;
}

.container_menu ul {
  list-style-type: none;
}

.container_menu .menu li a{
  color: white;
  display: block;
  padding: 1rem 1.5rem;
  background-color: black;
}
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="css/style.css" type="text/css">
  <title>MDN - Mockup</title>
</head>
<body>
  <nav class="container_menu">
    <ul class="menu">
      <li><a href="#">Teaching Activities</a></li>
      <li><a href="#">Web Literacy</a></li>
      <li><a href="#">Leadership Opportunities</a></li>
      <li><a href="#">Tools</a></li>
      <li><a href="#">Comunity</a></li>
    </ul>
  </nav>

  <main></main>

  <<footer></footer>

</body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

正如您所说,为了使您的菜单适合灰色块,请执行以下操作:

.container_menu .menu {
    width: 100%;
    padding: 0;
    margin: 0;
    height: 100%;
    background: black;
}

如果您不希望黑色为灰色父级的100%高度,则只需删除height: 100%行。