What are the best strategies for optimizing my CSS drop down menu to be both responsive and mobile-friendly?

I am struggling to make my current CSS and HTML menu fully responsive and mobile-friendly. I have researched solutions from other sources but have been unable to implement them successfully. I am seeking help in modifying my menu so that it adjusts to smaller screens by collapsing into a mobile-friendly button for expanded navigation.

I am hoping someone can provide me with the specific code needed, including the correct class names. I have attempted to adapt existing solutions without success. While there are tools available to generate code for me, I prefer to keep the desktop version of my menu unchanged and simply optimize it for smaller screens.

It is important to me that the solution only involves HTML5 and CSS3, with the code being added to my index.php file and CSS stylesheet.

From my index page:

     <!-- NAV-BAR-START --> 

  <div id="navbar"><div id='cssmenu'>
     <ul>
       <li><a href='/?p=home'><span>Home</span></a></li>
   <li class='has-sub'><a href='/?p=gallery'><span>Gallery</span></a>
  <ul>
     <li><a href='/?p=photos'><span>Photos</span></a></li>
     <li><a href='/?p=videos'><span>Videos</span></a></li>
     <li><a href='/?p=audio'><span>Audio</span></a></li>
   </ul>
 </li>
 <li class='has-sub'><a href='/?p=ian-milne'><span>Ian Milne</span></a>
  <ul>
      <li><a href='/?p=about'><span>About Ian</span></a></li>
      <li><a href='/?p=testimonials'><span>Testimonials</span></a></li>
     <li class='last'><a href='/?p=location'><span>Location</span></a></li>
   </ul>
 </li>
  <li><a href='/?p=events'><span>Events</span></a></li>
   <li><a href='/?p=bookings'><span>Bookings</span></a></li>
<li class='last'><a href='/?p=contact'><span>Contact</span></a></li>
< /ul> 
 </div></div>

  <!-- NAV-BAR-END -->

Associated CSS:

/* CSS DROPDOWN MENU */

#cssmenu {
  border: none;
  border: 0px;
  margin: 0px;
  padding: 0px;
  font: 67.5% 'Lucida Sans Unicode', 'Bitstream Vera Sans', 'Trebuchet Unicode MS', 'Lucida Grande', Verdana, Helvetica, sans-serif;
  font-size: 14px;
  font-weight: bold;
  width: auto;
  text-align:center;

}
#cssmenu ul {
  background: #000dfa;
  height: 50px;
  list-style: none;
  margin: 0;
  padding: 0;
  -webkit-border-radius: 8px 8px 0px 0px;
  -moz-border-radius: 8px 8px 0px 0px;
  border-radius: 8px 8px 0px 0px;
  -webkit-box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
  -moz-box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
  box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
}
#cssmenu li {
  float: none;
  padding: 0px 0px 0px 15px;
  display: inline-block;
}
#cssmenu li a {
  color: #ffffff;
  display: block;
  font-weight: normal;
  line-height: 50px;
  margin: 0px;
  padding: 0px 25px;
  text-align: center;
  text-decoration: none;
}
#cssmenu li a:hover {
  background: #000894;
  color: #ff8400;
  text-decoration: none;
  -webkit-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
  box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
}
#cssmenu ul li:hover a {
  background: #000894;
  color: #ff8400;
  text-decoration: none;
}
#cssmenu li ul {
  display: none;
  height: auto;
  padding: 0px;
  margin: 0px;
  border: 0px;
  position: absolute;
  width: 200px;
  z-index: 200;
}
#cssmenu li:hover ul {
  display: block;
}
#cssmenu li li {
  display: block;
  float: none;
  margin: 0px;
  padding: 0px;
  width: 200px;
  background: #000dfa;
  /*this is where the rounded corners for the dropdown disappears*/

}
#cssmenu li:hover li a {
  background: none;
}
#cssmenu li ul a {
  display: block;
  height: 50px;
  font-size: 12px;
  font-style: normal;
  margin: 0px;
  padding: 0px 10px 0px 15px;
  text-align: left;
}
#cssmenu li ul a:hover,
#cssmenu li ul li:hover a {
  border: 0px;
  color: #ff8400;
  text-decoration: none;
  background: #000894;
  -webkit-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
  box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
}

I have also created a JSFiddle link for reference.

Answer №1

For each media query, you have the ability to customize the styling. Simply duplicate and tweak your styles to fit each specific case. Resize your browser window to view the changes for each media query - it's a great way to experiment and fine-tune your design for different aspect ratios.

@media (max-width: 600px) {
 #cssmenu {
  /*
  add styles here
  */
 }
}

Take a look at this example that caters to a variety of devices (though it may require updating for newer HD smartphones and tablets). https://gist.github.com/marcobarbosa/798569

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

A step-by-step guide on showcasing freshly submitted input data through Ajax

I'm having trouble with this issue! Once I submit the new input, it doesn't show up in the div. Below is my JavaScript code: $('#addVariable').validate({ rules: { variable: {required:true}} , submitHandler: functio ...

Guide on submitting a multi-step form using jQuery

Greetings, I am in need of assistance with submitting a jQuery step wizard form. Although I have a plugin that helps, it primarily uses jQuery rather than HTML. So far, I have accomplished the following steps: - Set up the necessary database and table - C ...

What are the best strategies to perfectly insert an image within a div, ensuring that no background color is visible?

Is there a way to fix the issue of a white background appearing at the bottom of this div? .flexbox-item_one { display: inline-block; width: 200px; margin: 10px; background-color: white; box-shadow: 5px 5px 5px; overflow: hidden; } .flexb ...

What is Microsoft's equivalent to an embedded Java web applet?

Is there a Microsoft alternative to embedded Java web applets? Can you provide an example from the internet? Furthermore, why is ajax prevalent in dynamic web development compared to embedded applications? ...

Tailwind.css - a "sticky" element is positioned outside of the parent "wrapper" element

Seeking your kind assistance. I am facing an issue where a fixed element is being displayed outside the parent container on large screens, as it is treated as "fixed" from the viewport rather than relative to its parent element. https://i.sstatic.net/mw2 ...

Instructions for receiving user input and displaying it on the screen, as well as allowing others with access to the URL to view the shared input provided by the original user

<h1>Lalan</h1> <input type="text" name="text" id="text" maxlength="12"> <label for="text"> Please enter your name here</label> <br><input type="submit" value ...

Crafting visually stunning interfaces with Material UI

I'm a beginner in Material Design and I could use some assistance with the following structure. Can anyone guide me on how to create this? https://i.stack.imgur.com/NpiVz.png I've managed to add a text box, but now I'd like to place a label ...

The CSS layout is not positioning elements correctly

Here is a preview of how I want my final design to appear: I am facing difficulty in properly aligning the two columns using my CSS code. Whenever I apply the float: left; property, the columns end up stacking on top of each other. /*------ Code st ...

Padding-left in InfoBox

Currently, I am in the process of developing a map using Google Maps API3 along with the InfoBox extension available at this link I have successfully implemented an overall padding to the Infobox using the following code snippet: var infoOptions = { disa ...

Adjust the height of a div using jQuery once the AJAX call retrieves the data

There is a div that always matches the height of the adjacent div, depending on the content loaded in it. This setup was functioning properly until I implemented a search feature using jQuery. Now, when I perform a search, the element used in the jQuery ca ...

Issue with Nivo Lightbox: image not properly centered or resizing correctly

Whenever an image is clicked, it opens in the Nivo lightbox. This feature used to work flawlessly, but recently, it seems to be experiencing issues. The image should be centered and resize responsively to stay in the center. (For example, it worked correct ...

Unusual behavior in ReactJS and HTML5 video player observed

I currently have two React presentation components that include HTML5 video tags. The first component, named Homepage, is as follows: export default class Homepage extends React.Component { render() { return( <div className="Homepage"> ...

Tips for Showing Empty Data in a Nonexistent `<td>` Element within a Table

This particular query appears to be quite simple... I am seeking the HTML code for creating a table: <table> <tr> <th>Heading 1</th> <td>or</td> <th>Heading 2</th> </tr> <tr> ...

I'm curious about how I can apply @media queries given that certain phones possess higher resolution than computers

There seems to be a common recommendation to utilize @media queries for adjusting CSS based on whether the user is on mobile or not. However, I'm a bit confused because my phone has a width of 1440p while my computer has 1920p. Should I consider apply ...

Create the columnHeader to match the width of the CSS column

Here's what I attempted: http://codepen.io/helloworld/pen/BcjCJ I aim for each column to have the same width as the column header visually. Currently, a slight difference in width exists between the column header and the actual column. Refer to the ...

Removing empty commas from a string with JQuery

I am looking to utilize JQuery to eliminate any empty commas from a given string. Take a look at the provided images for further clarity. ...

Open the PDF document in a stylish jQuery popup like fancybox or a similar plugin

Can a PDF file be loaded in a popup? I understand that some browsers may require Adobe Reader to view PDFs, but Chrome has its own built-in PDF viewer. ...

Navigate to the following input field upon a keyup event occurring within the table

I have a table that contains multiple input fields in a single row within a td element. I am trying to implement functionality that will automatically shift focus to the next input field when any number is entered. The code works perfectly without the tabl ...

Automatically populate fields when the selection changes

Currently, I am facing an issue with a mysql table named clients that I utilize to populate the options of a select in one of the rows. The goal is to automatically fill out 2 input fields with client information when a specific option is selected. To acc ...

Having trouble getting CSS to center text properly. It just won't cooperate

After spending 2 days trying to figure this out on my own, I have come to a dead end. It seems that my lack of expertise in CSS is the root cause of the issue. Here is the code snippet I am working with: <table class="demo"> <tr> <th style ...