I am struggling to create a drop-down menu and need help figuring it out

I've tried looking at other questions but still can't get my code to work. Below is the HTML and CSS I'm working with (feel free to condense or modify as needed).

.dropdown-menu li ul {
  display: none;
  height: auto;
  margin: 0;
  padding: 0;
  display: table;
}
.dropdown-menu li:hover ul {
  display: block;
  height: auto;
  margin: 0;
  padding: 0;
  display: table-cell;
}
<div class="nav">
  <div class="container">
    <ul class="pull-left">
      <li><a href="index.html">Home</a>
      </li>
      <li><a href="#">Contact Us</a>
        <ul class="dropdown-menu">
          <li><a href="contact.html">Contact Us</a>
          </li>
          <li><a href="request.html">Request a building</a>
          </li>
        </ul>
      </li>
    </ul>
  </div>
</div>

Answer №1

For optimal use, apply this to the main ul, rather than its drop-down counterpart. Additionally, eliminate the redundant declaration of the display property:

ul{
  list-style: none;
}
.pull-left > li{
  float: left;
  margin: 0 20px;
  overflow: hidden;
}
.pull-left > li > ul {
  display: none;
  height: auto;
  margin: 0;
  padding: 0;
}
.pull-left > li:hover > ul {
  display: block;
  height: auto;
  margin: 0;
  padding: 0;
}
<div class="nav">
  <div class="container">
    <ul class="pull-left">
      <li><a href="index.html">Home</a></li>
      <li><a href="#">Contact Us</a>
        <ul class="dropdown-menu">
          <li><a href="contact.html">Contact Us</a></li>
          <li><a href="request.html">Request a building</a></li>
        </ul>
      </li>
    </ul>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How do I access a specific option within an optgroup in a select tag using PHP in an HTML form?

Is it possible to access an option from a select tag by optgroup in an HTML form using PHP? For example: <select name="est" id="est"> <optgroup name="G1" label="Group 1"> <option>Option 1.1</option> </optgroup> &l ...

Bootstrap grid button with maximum flexibility

I am currently exploring the intricacies of the bootstrap grid system. My goal is to create a set of buttons that look like this: https://i.sstatic.net/V5meG.png Each button should expand to fill the width and height of its container. However, when a b ...

Retrieving data from a Ruby class based on a specific condition

Currently, I have a code snippet that adjusts the formatting of an editing page based on the number of values a question contains. <% (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aa9b8484eadbdfcfec8cdcac3c5c484dbc6ece0 ...

Tips for utilizing rowspan and colspan in BootstrapTable

I am creating a table using bootrapTable and would like to know how I can use rowspan or colspan to achieve a table layout similar to the one shown in this image: Click here for image description $table.bootstrapTable({ columns: [{ ...

Develop a custom content management system that utilizes GET parameters for enhanced functionality

Creating a news system for is my current project and it consists of 3 main pages: index.php | This page displays the latest news and allows users to select which article to read article.php | Users can view the full news post on this page post.php | Thi ...

Can you please provide guidance on implementing automatic horizontal scrolling with pauses between each div?

setInterval(function scroll() { $(".box_auto").each(function(i, e) { $("html, body").animate({ scrollTop: $(e).offset().top }, 500).delay(500); }); setTimeout(function() { $('html, body').animate({ scrollTop: 0 } ...

Tips for concealing images within a designated list and revealing them in a separate list

I have a question regarding image visibility. Is it possible to hide certain images from a "SHOW ALL" list, but have them appear in a different category list? Below is the code snippet: <section> <ul class="portfolio_filters"> < ...

Implementing a custom loader screen in jQuery Mobile instead of displaying an error page while loading

I am in the process of developing a hybrid mobile application using Intel XDK and jQuery Mobile for the user interface. One challenge I encountered is related to an ajax form submission, which involves two logins and the use of tabs (2). Initially, I focus ...

The background remains hidden from view as a result of its positioning

There seems to be an issue with the background color of my list not displaying correctly. The problem arose after floating elements left and right. Any suggestions on how to resolve this? If you'd like to take a look, here's the link to the fidd ...

Looking at an HTML string in its natural HTML form

In my AngularJS app, I have autogenerated HTML code that highlights certain texts. The specific line of code responsible for generating this HTML looks like this: var replaced = original.replace(regEx, '<span style="background-color: red;">&apo ...

What is the best way to create flexible Bootstrap 3 columns with varying heights?

I'm struggling to remove space and create a flex column .col-md-5 with varying heights. Despite trying various solutions found on Google, I still can't get it to function properly. The current outcome is not as expected. https://i.sstatic.net/fc ...

A snippet of jQuery programming that enables automatic transitions between images

Trying to figure out how to achieve this - I want an image to change every 3 seconds using jquery. Can anyone help me with this? Unfortunately, I haven't been able to find any resources on this specific topic. ...

Ways to ensure the menu remains fixed on a fluid website

Is there a way to prevent the main-menu from moving to a second line when resizing the page down, while still maintaining fluidity? Thank you, Ken ...

Implement a background image in the navigation bar links using CSS

Strange as it may seem, the image refuses to show up in the navbar. Adding borders or other styling makes it visible, but not the image itself. If I manually include the image using the <img/> tag in the HTML, it appears, but then the hover effect do ...

Is there a way to stop text from being selected when double clicking?

#btnLeft{ width:40px; padding:2px 5px 2px 5px; background-color: #20a0a0; border: thin solid #099; border-radius:7px; text-align:center; font-family:"Futura Md BT"; font-size:large; color:#FFF; } This particular code sn ...

Incorporating header and footer elements into the design

I am facing an issue while editing a layout. Currently, when clicking on some side of the layout, a header and footer appear in a certain way. However, I would like to change this so that the header and footer appear differently, similar to the example s ...

Press the html button and activate the button using Visual Basic

Being new to Visual Basic, I have created a simple app using the WebBrowser component. The web page that loads contains an HTML button. I want this HTML button press to enable a button in Visual Basic, but I don't know how to do it. I have researched ...

Display the file name of the following/preceding images on the backward/forward button

Hello, I am fairly new to web development and could use some professional assistance. I have a slideshow set up, but I am struggling with adding the filename of the next or previous images to the back/forward icons of the slideshow. Is this achievable with ...

Error: The property 'classList' of null is unreachable for HTMLImageElement

I'm facing an issue on my website that's causing the following error message to pop up: Uncaught TypeError: Cannot read property 'classList' of null at HTMLImageElement. Here's the code I've been using: https://jsfiddle. ...

Styling in Svelte/TS does not change when applied through a foreach loop

I've been experimenting with creating a unique "bubble" effect on one of my websites, but I'm facing difficulty changing the styling in a foreach loop. Despite no errors showing up in the console, I'm at a loss as to how to effectively debu ...