CSS navbar with a unique design: Issue with List Hover not Persisting

I'm facing a common issue with a pure CSS navbar. I have constructed a navbar using ul and li elements, but I am unable to make the menus stay visible when I hover over them. The problem lies in the fact that the menu opens only when I hover over the link, and I'm unsure of how to fix this. I attempted using jQuery's mouseover function, but it did not work for me:

@font-face{
font-family: Bebas;
src:url(BEBAS.TTF);
}
body{

margin:0 auto;
height:500px;
    font-family: Bebas;

}
.header{
top:0;
position:absolute;
left:0;
right:0;
background:#ff6200;
height:50px;
width:100%;
color:white;
font-family: Bebas;

}
.header .call{

line-height:50px;
}
.call{
width:60%;
margin:0 auto;
}
.login{
float:right;
}
.callme, .loginme{
color:#AF2626;
}
.signup{
margin-left:10px;
}
.number{
margin-left:10px;
}
.navbar{
margin-top:50px;
right:0;
left:0;
position:relative;
height:130px;
width:100%;
background:#F7F7F7;
border-radius:0px;
padding:0px;
}
.inside-navbar{
line-height:130px;
width:60%;
margin:0 auto;
font-size:40px;

}
.logo{
color:#FF6200;
}

#navsman{
font-size:16px;
float:right;
display:inline-block;
min-width:300px;
position:absolute;
    padding-right: 20%;
}


#navsman  li{
display:inline;
position:relative;
padding-left:15px;
line-height:1.4;
}
#navsman li ul{
position:absolute;
display:none;
}

#navsman li:hover > ul.firstmenu{
display:block !important;
margin-top: -50px;
}

 #navsman li ul li{
position:relative;
padding-left:15px;
}
#navsman ul.secondmenu{
    margin-left: 40px;
    padding-top:15px;
padding-top: 30px;
    z-index: 2;
    width: 120px;
    display:none;
}
#navsman > li:hover > ul {
  left: auto;
  padding-top: 5px  ;
  min-width: 100%;
}
#navsman ul.firstmenu li:hover ul.secondmenu{
display:block !important;
margin-top: -50px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/js/bootstrap.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.css" rel="stylesheet"/>
<div class="headwrapper">
         <div class="header">
             <div class="call"><span class="callme">CALL US NOW!</span> <span class="number">777.77.7777.777</span>
                <span class="login"><span class="loginme">LOGIN </span><span class="signup">SIGNUP</span></span> 
            </div>
                 
            
         </div>
        <div class="navbar">
            <div class="inside-navbar">
            <span>YOUR<span class="logo">LOGO</span></span>

<ul id="navsman">
            <li><a href="">Title1</a></li>
            <li class="title2"><a href="">Title2</a>
    <ul class="firstmenu">
        <li><a href="#">SUBMENU1</a></li>
        <li><a href="#">SUBMENU2</a></li>
        <li><a href="#">SUBMENU3</a>
    <ul class="secondmenu">
        <li class="secondli-first"><a href="#">Sub link 1</a></li>
        <li class="secondli-second"><a href="#">Sub link 1</a></li>
    </ul>
          </li>
    </ul>



         
            <li><a href="">Title3</a></li>
            <li><a href="">Title4</a></li>
            <li><a href="">Title5</a></li>
            <li><a href="">Title6</a></li>
            <li><a href="">Title7</a></li>
            </div>
        </ul>
        </div>
</div><!--Navbar end-->
</div>

Answer №1

Update the following CSS code:

#navsman > li:hover > ul {
  left: auto;
  padding-top: 5px  ;
  min-width: 100%;
}

To this new CSS code:

#navsman > li:hover > ul li {
  left: auto;
  padding-top: 5px  ;
  min-width: 100%;
  height: 10px;
  margin-top:-15px;
  padding-left: 10px;
}

Answer №2

Address the discrepancy identified by @James Montagne

navsman li ul{

position:absolute;
display:none;
top:70px; <-- this is the additional line
}

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

Guide to iterating within a loop with a variable number of iterations above or below the specified amount in JavaScript

I am currently engaged in a project for a small theater group, and I am facing challenges with getting this loop to execute properly. <% include ../partials/header %> <div class="jumbotron jumbotron-fluid"> <div class="container"> ...

Use Select2 for efficient selection

I am attempting to implement select2 for a multi-select dropdown list of states, but I am encountering an issue. Typically, when you type in an option, it should be highlighted so that you can press enter to select it. However, in my case, it underlines t ...

Retrieve characteristics from removed or replicated entities and allocate them to different entities

Looking for a bit of assistance with an array transformation: [ {Code:13938, Country:699, Name:"Crocs", codeProduct:1} {Code:13952, Country:699, Name:"Polo Club", codeProduct:14} {Code:13952, Country:699, Name:"Polo Club", codeProduct:1} {Code ...

The method request.getParameter in Servlet may sometimes result in a null

My website utilizes JQuery to make an Ajax call to a servlet. function sendAjax() { $.ajax({ url: "/AddOrUpdateServlet", type: 'POST', dataType: 'json', ...

Parent Directory Injector: Prioritizing Injection of Parent Directories

Currently, I am utilizing 'grunt-injector' to inject a list of files using 'app/**/*.js'. However, I am facing dependency errors due to the alphabetical order in which the files are injected. To avoid these issues, I am looking for a so ...

How to Extract YouTube Audio URL on an iPhone

I have been working on a JavaScript code that can fetch the direct download URL for videos from the mobile YouTube website. [webView stringByEvaluatingJavaScriptFromString:@"function getURL() {var player = document.getElementById('player'); var ...

The transition effects between iOS5 and jquery-mobile can cause brief flickering

I have been struggling to eliminate a bothersome flickering effect on jqmobile transitions when using iOS 5. Despite trying various methods mentioned in other posts, such as -webkit-backface, I have not been able to find a complete solution. Upon closer ob ...

Issues with Angular route links not functioning correctly when using an Array of objects

After hard coding some routerLinks into my application and witnessing smooth functionality, I decided to explore a different approach: View: <ul class="list navbar-nav"></ul> Ts.file public links = [ { name: "Home&quo ...

Progressive form upload with AJAX and sophisticated file uploading bar

I am currently working on a photographer portal that requires full administration, and I am facing challenges in implementing a progress bar for image uploads. While I am familiar with creating progress bars for simple file uploads, the complexity of the f ...

Updating template views in Grails without the use of ajax enables seamless and dynamic

In my GSP template, I am looking to provide the user with updates on the progress of a task within an overlay. Once the user submits their data, the controller triggers a service to carry out the task. Simultaneously, another service calculates the percen ...

What is the best way to exclude the bottom four rows when sorting with MatSort?

Is there a way for me to keep the last four rows fixed when sorting the table based on the column header? Here is an image of the table: table image <table mat-table [dataSource]="dataSourceMD" matSort (matSortChange)="getRowMaximoTable( ...

When using the jQuery .first() method, it actually retrieves a selection of elements rather than just the initial

When utilizing the first() method on a group of elements, it appears to exhibit unusual behavior. $("button.overlay").on("click",function(e){ e.stopPropagation(); let i = $(e.target).closest('.style-display').children( ...

What is the correct way to format a URL in an AJAX request using CodeIgniter in PHP?

I'm just starting out with CodeIgniter and I'm having trouble retrieving data from the controller using an AJAX request. I think I may have made a mistake in writing the URL for the controller function in the AJAX call. Below is the code for my ...

There seems to be a problem with the background repeating space in the CSS

body { background-image: url("https://source.unsplash.com/user/c_v_r/100x100"); background-size: 100px; background-repeat: space; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA- ...

Angular select automatically saves the selected option when navigating between views

I would like the selected option in my dropdown menu to stay selected as I navigate through different views and then return back. Here is the view: <select ng-model="selectedSeason" class="form-control" ng-options="season as 'Season '+ seas ...

Confirming whether the digit entered in jQuery is a number

My website has a user input field where numbers are expected to be entered. I wanted to find a convenient way to validate the input using jQuery. After some research, I discovered jQuery's built-in function called isDigit. This handy function allows ...

Press the delete button located on the child component to trigger an action in the

I'm in the process of developing a simple to-do application from scratch in order to familiarize myself with ReactJS. One challenge I'm facing is implementing the delete functionality for todos, as I want to keep the button within the Todo compon ...

Is it possible to request/scrape pages from the client side?

Let me present the issue at hand: I am currently managing a web application that serves as a notification system which updates frequently. This application is operational on several local computers, each of which solely display information without any inp ...

Arrange the text in a div element in a horizontal direction

While developing a friends list script for a website, I encountered an interesting UI issue in the chat section. When a lengthy chat message is added to the chat content div with the CSS attribute overflow: scroll, it causes the div to stretch out horizont ...

How can you position an image and text side by side without specifying the width using a div?

Having some trouble aligning an image (which is contained in a div) and some text (also in a div) on the same line without setting a width for the text. Here's what I've tried so far. <div id="container"> <div id="image" style="flo ...