user3632882 user3632882 - 10 days ago 4
CSS Question

Position of navigation menu with CSS

Excuse me my english is not very good.



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>





I have a problem locating an "ul" element inside a ".container_menu". It is assumed that what appears in black color should fit perfectly in the container_menu (gray color), but it is a bit outside.

Could someone help me?

Answer

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;
}
<!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>

Comments