Changing the li reordering list

I have a banner-style list, one of which is a drop-down list. For some reason, the list is not displayed in the correct order. There should be four elements: "Home", "Products and materials", "Reviews" and "Contact", the second of which should be a drop-down list. Instead of what happens, the dropdown is displayed last.

HTML:

<ul class="banner">
  <li class="banner"><a href="#home"><H2>Home</H2></a></li>
  <li class="dropdown">    
      <a href="#javascript:void(0)" class="dropbtn"><h2>Products and Materials</h2> </a>
      <div class="dropdown-content">
       <a href="#student"><h4>Materials for School settings</h4></a>
       <a href="#adult"><h4>Materials for adult clinical settings</h4></a>
       <a href="#teletherapy"><h4>Materials for Teletherapy</h4></a>
      </div>
  </li>
  <li class="banner"><a href="#home"><H2>Testimonials</H2></a></li>
  <li class="banner"><a href="#home"><H2>Contact</H2></a></li>
</ul>

CSS

/*bannner buttons*/
ul.banner {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

li.banner {
    float: left;
}

li a, .dropbtn {
    display: inline-block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn {
    background-color: #00e5ee;
}

li.dropdown {
    display: inline-block;
}


/*dropdown button*/

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
    color: black;
    padding: 5px 15px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
    display: block;
}
+4
source share
2 answers

you missed adding a float to the left

li.dropdown {
    display: inline-block;
    float: left;
}
+3
source

In CSS, instead of writing li.banner, change it to .banner li as follows:

ul.banner {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #333;
}

.banner li {
    float: left;
}

li a, .dropbtn {
    display: inline-block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn {
    background-color: #00e5ee;
}

li.dropdown {
    display: inline-block;
}


/*dropdown button*/

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
    color: black;
    padding: 5px 15px;
    text-decoration: none;
    display: block;
    text-align: left;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
    display: block;
}

<ul class="banner">
  <li><a href="#home"><H2>Home</H2></a></li>
  <li class="dropdown">    
      <a href="#javascript:void(0)" class="dropbtn"><h2>Products and Materials</h2> </a>
      <div class="dropdown-content">
       <a href="#student"><h4>Materials for School settings</h4></a>
       <a href="#adult"><h4>Materials for adult clinical settings</h4></a>
       <a href="#teletherapy"><h4>Materials for Teletherapy</h4></a>
      </div>
  </li>
  <li><a href="#home"><H2>Testimonials</H2></a></li>
  <li><a href="#home"><H2>Contact</H2></a></li>
</ul>
+1

Source: https://habr.com/ru/post/1665813/


All Articles