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

The persistent loading animation in AngularMaterial Autocomplete does not come to an end

Exploring AngularJS and AngularMaterial: Currently, I am delving into the world of AngularJS and experimenting with AngularMaterial. To put it to the test, I decided to create a sample based on the code provided in the documentation (check codepen). My ap ...

Show a dynamic modal with a widget displayed inside

I am facing an issue with my Angular.js website that is filled with a multitude of widgets. Each widget consists of a template.html file paired with a controller.js file to form an angular module. These widgets are utilized on a dashboard where users have ...

Developing a Form Submission Feature Using JQuery Mobile

I'm having trouble submitting a form using JQuery Mobile. Currently, my code looks like this: <form action="#pagetwo" method="post" name="myform"> <input type="text" name="myname"> <input type="submit" value="submit" /> ... and th ...

Will synchronous programming on an Express server prevent other users from accessing the page simultaneously?

Currently working on a simple one-page web app that depends on loading weather data from a file. To avoid multiple HTTP requests for each visitor, I have a separate script refreshing the data periodically. In this particular instance, I am using fs.readFi ...

Examining whether an ajax call was not initiated within an Angular application

Is there a way to verify that an ajax request has not been made using Angular's $httpBackend? I attempted to use verifyNoOutstandingRequest() but it doesn't seem to be triggering test failures in version 1.1.5. Here is more information about the ...

Navigating Modal Pop-ups in Django

My current approach for handling modal windows involves referring to this article here. However, I am struggling with implementing some basic functionality using this method. Within my HTML code, I have the following structure: {% for order in queryset% ...

Can you create asynchronous code or functions without using Web APIs at all?

Even though JavaScript is single-threaded, I can't help but wonder about a function that takes an unusual amount of time without any involvement from web APIs like this: console.log("start") function banana() { let bananaCount = 10; while (b ...

JavaScript code that displays items in a shopping cart

I've set up the HTML and JS functionality for the cart, but I'm facing an issue where the JS doesn't render the cart items when the shop item is clicked. The styling in my HTML is done using Tailwind. If anyone could provide some assistance ...

Listening for Angular 2 router events

How can I detect state changes in Angular 2 router? In Angular 1.x, I used the following event: $rootScope.$on('$stateChangeStart', function(event,toState,toParams,fromState,fromParams, options){ ... }) In Angular 2, using the window.addEv ...

The hover effect in CSS brings life to list items when filled with content

I am attempting to create an animation for an <li> element that gives the illusion of a fill effect moving from left to right when hovered over. This is my current progress: ul { list-style-type: none; } .hoverTest { float: left; margin-right: 1 ...

Automatically populate the checkbox with the specified URL

Is it possible to pre-fill a checkbox in an HTML form using the URL? For example, if we have a URL like www.example.com/?itemname=sth Would there be a similar method to pre-select a checkbox via the URL? <ul class="list-group"> <li c ...

What sets flex-start apart from baseline?

When using the align-* properties in flexbox, what sets flex-start apart from baseline? In the code snippet below, both align-self: flex-start and align-self: baseline produce the same result. Can you identify scenarios where align-self: flex-start and a ...

Ways to store a filestream coming from Node.js into AngularJS

When using my express server, I have a post-request set up to retrieve a pdf file from Amazon S3 and then send it back to Angular. This is the endpoint in my express server: var fileStream = s3.getObject(options).createReadStream(); fileStream.pipe(res); ...

I am unsure about implementing the life cycle in Svelte.js

Unknown Territory I am not well-versed in front-end development. Desire to Achieve I aim to utilize the lifecycle method with SvelteJS. Error Alert An error has occurred and the lifecycle method is inaccessible: ERROR in ./node_modules/svelte/index.m ...

Is the original object cloned or passed by reference when passing it to a child React component through props?

When passing an object to a child component through the components props in React, does the object get cloned or does it simply pass a reference to the original object? For instance, in my App.js, I am importing a JSON object called ENTRY_DATA. Then, I pa ...

window.print function appears multiple times

Looking for help with a sample script I have that prints a section of my website page when a button is clicked. The issue arises when using ajax to transition and clicking the same button results in window.print activating multiple times. How can I ensur ...

Exploring how to read class decorator files in a Node.js environment

I've developed a custom class decorator that extracts permissions for an Angular component. decorator.ts function extractPermissions(obj: { [key: 'read' | 'write' | 'update' | 'delete']: string }[]) { re ...

Looking for a sophisticated approach in Spring MVC to manage the escaping and unescaping of strings being passed to the Front End

Currently, I am in the process of developing a web application utilizing Spring MVC. This project involves retrieving multiple objects from the Database, each containing strings as attributes. It's worth noting that I have no control over the format o ...

Other options besides re-flowing and repainting

After doing some research on various platforms like Stack Overflow, I've come across information stating that re-paints and re-flows can be quite taxing on a browser's resources. I am interested in learning about alternative CSS/JS techniques to ...

What is the best way to eliminate a specific element from a JavaScript array?

What is the best way to eliminate a particular value from an array? For example: array.exclude(value); Limitations: I must solely rely on pure JavaScript without any frameworks. ...