user3632882
user3632882

Reputation: 51

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?

Upvotes: 1

Views: 86

Answers (2)

Max
Max

Reputation: 71

As you said, for fitting your menu in a grey block, do:

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

If you don't want black to be 100% height of grey parent, then just remove height: 100% line.

Upvotes: 0

Chibiao.Wang
Chibiao.Wang

Reputation: 394

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>

Upvotes: 2

Related Questions