What is the best way to create a flexible Ul-LI menu?

Is it possible to create a flexible menu where clicking on an item does not cover other items in the menu?

#demo {
  margin: 30px 0 50px 0;
  font-family: sans-serif;
}
#demo .wrapper {
  display: inline-block;
  width: 180px;
  height: 20px;
  position: absolute;
}
#demo .parent {
  height: 100%;
  width: 100%;
  display: block;
  cursor: pointer;
  height: 150%;
  background: #023b3b;
  color: white;
  z-index: 2;
  position: relative;
  text-align: center;
}
#demo .parent:hover,
#demo .content:hover ~ .parent {
  background: #122112;
}
#demo .content:hover ~ .parent {
  z-index: 0;
}
#demo .content {
  position: absolute;
  top: 0;
  display: block;
  z-index: 1;
  height: 0;
  width: 180px;
  padding-top: 30px;
}
#demo .wrapper:active .content {
  height: 100px;
  z-index: 3;
}
#demo .content:hover {
  height: 123px;
  z-index: 3;
}
#demo .content ul {
  background: #339933;
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100%;
}
#demo .content ul a {
  text-decoration: none;
}
#demo .content li:hover {
  background: #122112;
  color: white;
}
#demo .content li {
  list-style: none;
  text-align: left;
  color: white;
  font-size: 14px;
  line-height: 30px;
  height: 30px;
  padding-left: 10px;
}
<div id="demo">
      <div class="wrapper">
        <div class="parent">Dashboard</div>
      </div><br> <br>  
      <div class="wrapper">
        <div class="parent">Apps</div>
        <div class="content">
          <ul>
            <a href="#"><li>Inbox</li></a>
            <a href="#"><li>Contact</li></a>
            <a href="#"><li>Calendar</li></a>
            <a href="#"><li>Other</li></a>
          </ul>
        </div>

      </div><br><br>

      <div class="wrapper">
        <div class="parent">Layouts</div>
        <div class="content">
          <ul>
            <a href="#"><li>Header</li></a>
            <a href="#"><li>Aside</li></a>
            <a href="#"><li>Footer</li></a>
            <a href="#"><li>Other</li></a>
          </ul>
        </div>

      </div><br><br>
      <div class="wrapper">
        <div class="parent">Widget</div>
      </div>
    </div>

Answer №1

Explore this solution to see if it meets your needs. I've included the use of input and label.

#first {
  float:left;
  width:15%;
  color :bisque; 
  border-color: #023b3b;
  border-style : solid;
  height: 100%;
  background-color :#023b3b;
}

#boa{
  height: 5%;
  width: 20%;
  float: left;
}

.bob{
  text-indent: 200%;
  line-height: 210%;
  font-size: 150%;
  font-family: sans-serif;
  color: white;
  font-weight: bold;
}
.boc{
  text-indent: 4%;
  color : white;
  font-size: 83%;
  font-family: sans-serif;
  font-weight: normal;
}
.bod{
  color:white;
  font-size: 100%;
  font-family: sans-serif;
  line-height: 200%;
  list-style-type: none;
}
#demo {
  margin: 30px 0 50px 0;
  font-family:  sans-serif;
}
#demo .wrapper {
  display: inline-block;
  width: 180px;
}
#demo .parent {
  padding: 5px;
  display: block;
  cursor: pointer;
  background: #023b3b;
  color: white;
  position: relative;
  text-align: center;
}
#demo .parent:hover,
#demo .content:hover ~ .parent {
  background: #122112;
}
#demo .content:hover ~ .parent {
  z-index: 0;
}
#demo .content {
  height: 0px;
  transition: height 0.3s;
  z-index: 1;
  width: 180px;
}
#demo .wrapper input[type=radio] {
  position: absolute;
  opacity: 0
}
#demo .wrapper:hover input[type=radio]:checked + .content {
  height: 120px;
}
#demo .content:hover {
  height: 123px;
  z-index: 3;
}
#demo .content ul {
  background: #339933;
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100%;
}
#demo .content ul a {
  text-decoration: none;
}
#demo .content li:hover {
  background: #122112;
  color: white;
}
#demo .content li {
  list-style: none;
  text-align: left;
  color: white;
  font-size: 14px;
  line-height: 30px;
  height: 30px;
  padding-left: 10px;
}
 <div id="first" style="float:left; lngth:60%; ">
    <p><img src="image1.jpg"  id="boa"><span class="bob">First</span></p>
    <p class="boc" >Main</p>
    <div id="demo">
      <div class="wrapper">
        <div class="parent">Dashboard</div>
      </div><br> <br>  
      <div class="wrapper">
        <label for="apps"  class="parent">Apps</label>
        <input type="radio" name="menu" id="apps" />
        <div class="content">
          <ul>
            <a href="#"><li>Inbox</li></a>
            <a href="#"><li>Condact</li></a>
            <a href="#"><li>Calender</li></a>
            <a href="#"><li>Other</li></a>
          </ul>
        </div>

      </div><br><br>

      <div class="wrapper">
        <label for="layouts" class="parent">Layouts</label>
        <input type="radio" name="menu" id="layouts" />
        <div class="content">
          <ul>
            <a href="#"><li>Header</li></a>
            <a href="#"><li>Aside</li></a>
            <a href="#"><li>Footer</li></a>
            <a href="#"><li>Other</li></a>
          </ul>
        </div>

      </div><br><br>
      <div class="wrapper">
        <div class="parent">Widjet</div>
      </div>
    </div>

    <p class="boc">Componets</p>
    <p class="boc">Help</p>
    <p class="bod">&nbsp; Documents</p>
  </div>

Answer №2

Implementing jQuery code:

   $("#sample").hide();
     $(".btn").click(function(){
     $("#sample").slideToggle();
   });

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

Creating a JSON body using a JavaScript function

I am looking to generate a JSON Body similar to the one shown below, but using a JavaScript function. { "events": [{ "eventNameCode": { "codeValue": "xyz api call" }, "originator": { "associateID": "XYZ", "formattedName": " ...

Understanding the Impact of npm Dependencies on AAB (Android App Bundle) Release Size in React Native

Switching over to React-Native and Node.js from a Python background has left me confused about how dependencies are managed in React-Native (which I assume is similar to node.js). Query When creating a React Native AAB, are all Node Modules declared in th ...

Exploring the differences between io.emit and socket.emit

Having just delved into the world of socket.io, I've come across something that's puzzling me. I'm unclear on the distinction between socket.emit and io.emit, and my search for a clear explanation has turned up empty. io.on('connection ...

Utilize .GLB and Blender file formats within a Gridsome project developed with Vue.js

I am working on a project using Three.js in Gridsome, but I am facing difficulties importing .glb files (3D models) with GLTFLoader. While Gridsome recognizes img (png/jpg) or .js files stored in src/assets, it does not seem to support glb files. This is ...

Issue with THREE.SpriteCanvasMaterial functionality

This unique piece of code (inspired by this and this example): generateCircle = (ctx) -> position = 0.5 radius = 0.5 ctx.scale(0.05, -0.05) ctx.beginPath() ctx.arc(position, position, radius, 0, 2*Math.PI, fa ...

Deactivate one select box depending on the value chosen in another select box

I am looking to disable one select box when the other select box equals 1, and vice versa. While I know how to achieve this with IDs, the challenge arises as the select boxes I want to target have dynamically generated IDs and names via PHP. Therefore, I n ...

What are the steps to repairing the footer on your website?

Here is the issue I am facing: The footer in my HTML code appears after the grid. How can I fix this problem and make my footer fixed? Below is my HTML and CSS code for reference: <footer> <li><a href="">Menu</a>< ...

Object Literal vs Object-Oriented Javascript: Comparing the Two

When it comes to using Object-Oriented Programming (OOP) in JavaScript, I often find myself not utilizing it much. For instance, instead of defining a constructor function and setting up prototypes like this: function Person(name){ return this.name = name ...

Can the functionality of a button be disabled after being clicked a total of 5 times?

Once a user clicks the button five times, I plan for it to be disabled. Can this be achieved solely with HTML, or would JavaScript be necessary? ...

When placed within a setInterval loop, the event.clientY variable becomes inaccessible

I am working on a script to move an element around a web page, and I have encountered a problem. Whenever I try to put it in a loop using setInterval while the mouse is down and moving, I receive an error message stating 'Uncaught TypeError: Cannot re ...

Is there a way to convert time measurements like minutes, hours, or days into seconds in React and then pass that information to an

Currently, I am working on an application that allows users to select a frequency unit (like seconds, minutes, hours, or days) and input the corresponding value. The challenge arises when I need to convert this value into seconds before sending it to the ...

Is the branch of ExtJS 4.1 TreeStore lazy loading extending?

I am working on implementing lazy loading of tree branches in an MVC application using extjs4.1. The branches are located on different URLs and I have faced several challenges along the way. Unfortunately, at this point, the branching functionality is not ...

Content will not render when JavaScript generates SVGs

As I delve into the world of JavaScript and SVG to create interactive graphics for a website, I've run into a puzzling issue with programmatically generated SVG paths not being drawn. Below is a sample code that highlights this problem: <!DOCTYPE ...

Obtain JSON information and integrate it into an HTML document with the help of

I am currently working on a PHP/JSON file named users-json.php. <?php include_once('../functions.php'); if (!empty($_GET['id'])) { $GetID = $_GET['id']; $query = "SELECT Username, Firstname WHERE UserID = :ID"; $stmt = $d ...

Guide to activating a CSS attribute for the AJAX tab panel with the use of JavaScript

Currently, I am utilizing the ASP.NET AJAX Tab Container with two tab panels. Each tab panel contains a div tag, and by default, my ActiveTabIndex is set to "0." Now, I am trying to apply CSS properties to the div tags using JavaScript without causing any ...

Can you please tell me the event that is triggered when an option is unselected in Vue.Drag

I am trying to figure out the event for selecting an item since I already know about the "choose" event. However, I am uncertain about what to use for un-selecting an item. In my particular case, I am unable to utilize the @end event. <draggable :list= ...

Unable to establish a connection with Metamask

Looking to connect to Metamask and retrieve the account balance: <!DOCTYPE html> <html> <head> <title>Testing Ethereum with Metamask</title> <meta charset="UTF-8"> <meta name=&quo ...

Sharing a Directive across multiple AngularJS modules: Tips and Tricks

AngularJS has truly captured my interest with its powerful capabilities. I am delving deeper into the world of Angular and finding myself falling in love with it more each day. Despite my efforts, certain doubts continue to linger, leaving me eager for cla ...

Unable to transform into a tangible entity

When I run the code below, I encountered an error stating: Uncaught exception: TypeError: Cannot convert 'validation.messages.field' to object $.fn.validate = function(validation) { $.each(validation.rules, function(field, fieldRules){ ...

Is it advisable to use npm devDependencies in a production environment?

While reviewing the package.json file for one of our products at work, I noticed that the SDK uses socket.io for a crucial function even though socket.io-client is listed as a devDependency. Despite this discrepancy, the SDK works flawlessly for our clie ...