D. Ester
D. Ester

Reputation: 45

CSS drop down menu, what am I doing wrong?

Goodday,

I just copy the HTML and CSS from this example to my own documents: https://codepen.io/remilaudanski/pen/gbBGyN

But the problem by me is that I got the following problems that you don't see on the link:

Bar under the buttonEnumeration shows before text

My code is like the same code as on the example:

/* Générales */

body {background-color : #ededed; font-family : "Open Sans", sans-serif;}

h1 {padding: 40px; text-align: center; font-size: 1.5em;}

li a {text-decoration : none; color : #2d2f31;}

/* Nav */

nav {
  width : 300px; 
  background: #d9d9d9; /* Couleur de fond des liens */
  margin : 40px auto; /* Marge à virer */
}

/* Titre */

span {
  padding : 30px;
  background : #2d2f31; /* Couleur de l'en-tête */
  color : white;
  font-size : 1.2em;
  font-variant : small-caps;
  cursor : pointer;
  display: block;
}

span::after {
  float: right;
  right: 10%;
  content: "+";
}

/* Liste */

.slide {
  clear:both;
  width:100%;
  height:0px;
  overflow: hidden;
  text-align: center;
  transition: height .4s ease;
}

.slide li {padding : 30px;}

/* Checkbox */

#touch {position: absolute; opacity: 0; height: 0px;}    

#touch:checked + .slide {height: 300px;} /* Hauteur à gérer en fonction du nombre de liens */ 
<!DOCTYPE html>
<html>



<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>



<body>
<h1>CSS Dropdown Menu</h1>

<nav>

  <label for="touch"><span>titre</span></label>               
  <input type="checkbox" id="touch"> 

  <ul class="slide">
    <li><a href="#">Lorem Ipsum</a></li> 
    <li><a href="#">Lorem Ipsum</a></li>
    <li><a href="#">Lorem Ipsum</a></li>
    <li><a href="#">Lorem Ipsum</a></li>
  </ul>

</nav> 
</body>



</html>

Where is the problem? What am I doing wrong? Who can help me? Thanks.

Upvotes: 1

Views: 37

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167240

You forgot to reset the margin and padding:

* {margin: 0; padding: 0;}

Add this:

/* Générales */

* {margin: 0; padding: 0;}

body {
  background-color: #ededed;
  font-family: "Open Sans", sans-serif;
}
h1 {
  padding: 40px;
  text-align: center;
  font-size: 1.5em;
}
li a {
  text-decoration: none;
  color: #2d2f31;
}
/* Nav */

nav {
  width: 300px;
  background: #d9d9d9;
  /* Couleur de fond des liens */
  margin: 40px auto;
  /* Marge à virer */
}
/* Titre */

span {
  padding: 30px;
  background: #2d2f31;
  /* Couleur de l'en-tête */
  color: white;
  font-size: 1.2em;
  font-variant: small-caps;
  cursor: pointer;
  display: block;
}
span::after {
  float: right;
  right: 10%;
  content: "+";
}
/* Liste */

.slide {
  clear: both;
  width: 100%;
  height: 0px;
  overflow: hidden;
  text-align: center;
  transition: height .4s ease;
}
.slide li {
  padding: 30px;
}
/* Checkbox */

#touch {
  position: absolute;
  opacity: 0;
  height: 0px;
}
#touch:checked + .slide {
  height: 300px;
}
/* Hauteur à gérer en fonction du nombre de liens */
<h1>CSS Dropdown Menu</h1>

<nav>
  <label for="touch"><span>titre</span></label>
  <input type="checkbox" id="touch">

  <ul class="slide">
    <li><a href="#">Lorem Ipsum</a></li>
    <li><a href="#">Lorem Ipsum</a></li>
    <li><a href="#">Lorem Ipsum</a></li>
    <li><a href="#">Lorem Ipsum</a></li>
  </ul>

</nav>

Upvotes: 1

Related Questions