1

I was trying to create a drop-down but whatever I do, the content in the drop-down lines up horizontally instead of vertically. I tried going to multiple you tube videos to see what they did but that didn't work. Also, I tried using 'position: absolute' but that didn't work. Please tell me what I need to do in order to get the content in my drop-down to be vertical. Here is my code.

body {
  background-repeat: no-repeat;
  background-size: cover;
  font-family: Arial;
}

ul {
  margin: 0px;
  padding: 10px;
  list-style: none;
}

ul li {
  float: left;
  position: relative;
  width;
  200px;
  height: 40px;
  background-color: black;
  opacity: 0.8;
  line-height: 20px;
  text-align: center;
  font-size: 15px;
}

ul li ul {
  display: block;
}

ul li a {
  color: white;
  text-decoration: none;
}
<ul>
  <li><a href='#'>Home</a></li>
  <li><a href='#'>Classes</a>
    <ul>
      <li><a href="#">Level 1</a></li>
      <li><a href="#">Level 2</a></li>
      <li><a href="#">Level 3</a></li>
      <li><a href="#">Level 4</a></li>
      <li><a href="#">Level 5</a></li>
      <li><a href="#">Level 6</a></li>
    </ul>
  </li>
  <li><a href='#'>Programs</a>

    <ul>
      <li><a href="#">Level 1</a></li>
      <li><a href="#">Level 2</a></li>
      <li><a href="#">Level 3</a></li>
      <li><a href="#">Level 4</a></li>
    </ul>
  </li>
  <li><a href='#'>Contact</a></li>
  <li><a href='#'>Home-Work</a>
    <ul>
      <li><a href="#">Level 1</a></li>
      <li><a href="#">Level 2</a></li>
      <li><a href="#">Level 3</a></li>
      <li><a href="#">Level 4</a></li>
      <li><a href="#">Level 5</a></li>
      <li><a href="#">Level 6</a></li>
    </ul>

  </li>
</ul>
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
IbrahimLikeJava
  • 91
  • 1
  • 1
  • 9
  • `ul li` matches all `li` elements that have an ancestor `ul`; which is to say, all of them. Looks like you only want the first level of `li`s to have the `float:left`. Add a class to that `ul` and use the child selector. – Heretic Monkey Aug 14 '18 at 21:40
  • Possible duplicate of [Target first level
  • s and not the nested
  • s](https://stackoverflow.com/questions/4830624/target-first-level-lis-and-not-the-nested-lis)
  • – Heretic Monkey Aug 14 '18 at 21:41
  • @HereticMonkey I changed 'ul li ', to just 'ul' but everything got shifted to the side and wasn't spaced out. Can I fix that with just a padding? Or not. – IbrahimLikeJava Aug 14 '18 at 22:12
  • Did you happen tor read that duplicate question? It's pretty clear on what to do... – Heretic Monkey Aug 14 '18 at 22:14