Jough Drak
Jough Drak

Reputation: 15

I want to make my menu dropdown

I want to make my navigation menu to be dropdown. I tried different ways, but nothing happend.

This is my HTML code:

<ul>

  <li><a href="index.html">Home</a></li>

  <li><a href="Countries.html">Geography</a></li>

  <li><a href="English.html">English</a></li>

  <li class="icon">
    <a href="javascript:void(0);" onclick="myFunction()">&#9776;</a>
  </li>

</ul>

And this is my CSS code:

ul {
  padding: 15px;
  margin: -10px;
  overflow: hidden;
  list-style-type: none;
  background-color: #171B29;
}

li {
  float: left;
}

li a {
  display: inline-block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  transition: 0.3s;
  font-size: 17px;
}

li a:hover {
  background-color: #555;
}

li icon {
  display: none;
}

@media screen and (max-width:680px) {
  ul.topnav li:not(: first-child) {
    display: none;
  }
  ul.topnav li.icon {
    float: right;
    display: inline-block;
  }
}

@media screen and (max-width:680px) {
  ul.topnav.responsive {
    position: absolute;
  }
  ul.topnav.responsive li.icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  ul.topnav.responsive li {
    float: none;
    display: inline;
  }
  ul.topnav.responsive li a {
    display: block;
    text-align: left;
  }
}

When I try to make a dropdown menu, the whole menu becomes very bad. I know that my code is very bad for reading but I will appreciate it if someone have a solution. Thank you in adva

Upvotes: 0

Views: 45

Answers (3)

dietary-wheevil
dietary-wheevil

Reputation: 4481

If your issue is that you want the <li> elements to be stacked vertically, you can solve this quite simply using flexbox. Additionally, if you were planning on effecting the "drop-down" effect with just HTML & CSS, you need to add a :hover pseudoclass on the top-level element from which the navigation menu derives. In the example I'm linking to below, I did so on the <ul> element. Alternatively, you'd use the mouseover event in JavaScript.

Additionally, note that the li icon CSS selector you used is not actually a valid selector. There is no actual icon tag in HTML, although many people use the <i> tag as a container for icons.

https://jsfiddle.net/IsenrichO/8t4jhvcs/20/

Upvotes: 0

James
James

Reputation: 323

Have you included the JavaScript too? You are specifying a toggle (myFunction) on click so you need the JavaScript too.

Of course you can just use HTML and CSS for dropdowns, as listed in the post above.

Upvotes: 0

Vinko Vorih
Vinko Vorih

Reputation: 31

You should try to find answer on http://www.w3schools.com/css/css_dropdowns.asp
Webpage have pretty decent content and its easy understandable.

Upvotes: 1

Related Questions