Is there a way to display the dropdown menu specifically when I hover over the Search Engine option?

As I embarked on creating the inception of my potentially useful website, my focus shifted to crafting the header and menu sections. Specifically, in the search engine portion, I envisioned a dropdown menu with various options revealed upon hovering over "Search Engine", yet remaining concealed otherwise. To visualize this concept, I temporarily disabled the display using CSS code by commenting out 'display: none'. Despite experimenting with the pseudo-class .dropdown:hover, the desired effect was not achieved. How can I ensure that the dropdown menu only appears when hovering over the Search Engine? The linked image serves as an example of the current state, not the intended outcome.

HTML

<!DOCTYPE html>
<html lang='en'>
  <head>
    <meta charset='UTF-8'/>
    <title>SerFin</title>
    <link href="https://fonts.googleapis.com/css2?family=Cinzel&display=swap" rel="stylesheet">
    <style>
      .title {
        font-family: 'Cinzel', cursive;
      }
    </style>
    <link href='test.css' rel='stylesheet'/>
  </head>
  <body>
    <header>
      <nav>
        <ul class="menu">
          <li><a href='#'>Customer Service</a></li>
          <li><a href='#'>Submission</a></li>
          <li class="dropdown">Search Engine ▾<li>
        </ul>
        <ul class="dropdown-menu">
          <li><a href="#">Universities</a></li>
          <li><a href="#">Jobs</a></li>
          <li><a href="#">Courses</a></li>
          <li><a href="#">Internships</a></li>
          <li><a href="#">Services</a></li>
        </ul>

        <ul class="setup">
          <li><a href='#'>Login</a></li>
          <li><a href="#">Sign up</a></li>
        </ul>
      </nav>
      <img class="logo" src="Logo.jpg"></img>
    </header>
  </body>
</html>

CSS

*{
margin: 0;
padding: 0;
box-sizing: border-box;
}

  body {
font-size: 18px;
line-height: 1.8em;
  }

  header {
background-color:#5D6063;
  }

  nav {
display: flex;
justify-content: space-around;
background-color: #54575A;
width: 100%;
height: 40px;
}

  li {
list-style: none;
display: inline;
padding-left: 10px;
padding-right: 10px;
  }

  a {
    color: #D3D3D3;
    text-decoration: none;
  }

  a:hover {
    text-decoration: underline;
    color: #54A5C4;
  }

  .menu {
    color: #EEEEEE;
    padding: 5px;
  }

  .setup {
    color: #EEEEEE;
    padding: 5px;
  }

  .title {
color: white;
display: flex;
justify-content: center;
padding: 150px;
  }

img {
  display: block;
  margin-left: auto;
  margin-right: auto;
  padding: 100px;
}
/*
---------------------------------------------------------------------------------------------
All of this is the heading, from now on everything has to do with the dropdown menu
*/
.dropdown {
  position: relative;
  z-index: 2;
}

 .dropdown-menu {
  display: flex;
  flex-direction: column;
  background: #54575A;
  border-radius: 1px;
  padding-top: 60px;
  position: absolute;
  top: -25px;
  left: 490px;
  z-index: 1;
}

.dropdown-menu li {
  list-style: none;
  border-bottom: 1px solid #FFF;
  padding: 0 40px 10px 20px;
  margin: 10px;
}

.dropdown-menu li:last-of-type {
  border-bottom: none;
}

.dropdown > span {
  z-index: 2;
  position: relative;
  cursor: pointer;
}

/*.dropdown-menu {
  display: none;
}*/

Answer №1

There are two options for achieving this functionality: using plain JavaScript or jQuery. Here is an example of how it can be done with jQuery.

$('.dropdown').hover( function(){ $('.dropdown-menu').show(); });

Answer №2

If you're working with JavaScript, you have the option to utilize the code snippet below to trigger an action on mouseover within an HTML element:

<img onmouseover="yourfunction()" src="path">

Alternatively, you can achieve the same effect by using the following JavaScript code:

object = document.getElementByID("element") (or any other reference to element)
object.addEventListener("mouseover", myScript);

I acquired guidance from: https://www.w3schools.com/jsref/event_onmouseover.asp

I hope you found this information useful.

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

Troubleshoot redirect issues in JavaScript or PHP

I am facing a simple issue that is proving to be time-consuming to solve. The challenge that I am encountering involves an HTML form with 2 buttons. Here is the relevant code snippet: $html1 = "<div class='pai-forms'> <form ...

Monitor the Ajax for any updates in the database and trigger the code accordingly

My objective is to send requests to a php file with specific parameters in this format: <!DOCTYPE html> <html> <head> <script> function onsubmit() { var id = $_SESSION['user']['id']; var xmlhttp; if ...

Unable to apply styling to border when clicking on radio button in React

I've created these divs to act like radio buttons: [![these 4divs][1]][1] When I click on one of them, I want the border to turn blue like this: border: 2px solid blue; However, instead, the issue shown below is happening: [![the problem][2]][2] ...

When I expand the accordion next to it, the accordion disappears, and it also vanishes when I close that accordion

After incorporating accordions into my site, I encountered a peculiar issue (as shown in this video): when I open one accordion, the adjacent accordion also opens unexpectedly. Similarly, closing one accordion causes its neighboring accordion to mysterious ...

Minimizing load time to create a seamless user experience

After working diligently on a website, we successfully reduced the total content for a page load from 13.7MiB's to 2.4, but unfortunately, the page still loads at a snail's pace. This Joomla site is loaded with redundant DOM elements (2000+ for ...

Creating designs on the canvas

With this code snippet, I have the ability to create lines using mouse points on a canvas. My goal is to identify when these lines connect to form a shape and then fill that shape with color. <script language="javascript" src="//ajax.googleapis.com/a ...

Troubleshooting: Javascript success callback not executing upon form submission

A snippet of my JavaScript looks like this: $(document).ready(function(){ $("#message").hide(); $("#please_wait_box").hide(); $("#updateinvoice").submit(function(e){ $("#message").hide(); ...

Struggling with getting basic CSS to work with React's MUI framework

I've been attempting to incorporate basic CSS with MUI components. According to their website, it should be feasible. https://material-ui.com/guides/interoperability/#plain-css But unfortunately, I'm having trouble getting it to function prope ...

The column on the right does not extend all the way to the bottom of the page

Hello, I currently have a website with the following design: I'm looking to extend the right column all the way down to the bottom of the body, even if there's not enough content to push it down. How can I accomplish this using CSS? Here is the ...

Clicking on AngularJS ng-click to navigate to a different page within an Ionic framework application

My goal is to navigate to another page when clicking on a button in the Ionic navbar at the top. However, I am encountering an issue where upon clicking, all nav bar buttons disappear. Interestingly, using dummy codes triggers an alert successfully. But w ...

Tips for aligning text and an image next to each other within a table column using HTML

I have a table where I am displaying an image and text in separate columns, with the image above the text. However, I want to showcase them side by side and ensure that the table fits perfectly on the screen without any scroll bars. Here is my HTML code s ...

In Firefox version 3.6, sIFR 3 is displaying text in a random arrangement along a single line

For some reason, sIFR 3 is behaving oddly in Firefox. In other browsers like IE, Chrome, and Safari, the Flash element within a 412px wide box remains consistent at that width. However, in Firefox, it initially stretches to the width of the Body element b ...

I am looking to set an HTML file as the homepage for my Next.js project

Is there a way in next.js to render a normal .html file (index.html) when someone visits my root directory at "https://example.com/"? I have researched and edited my config file as shown below, /** @type {import('next').NextConfig} */ const next ...

Aligning images in a table grid of 300px by 300px dimensions

I've included my code below and I am searching for the most effective method to use CSS to center an image both horizontally and vertically within a 300 by 300 pixel square. If the image is larger, it should be resized to fit within the square, while ...

Tips for eliminating flicker upon the initial loading of a webpage caused by dynamic changes in CSS styles through JavaScript

Struggling with the load order of my CSS and JavaScript... Currently, I have a div with a blue background that is styled to appear sliced diagonally. However, upon initial page load (or CTRL+SHIFT+R), there's a brief moment where the slice effect doe ...

Storing a form in a database using SQL

I have developed a PHP script that is meant to save form input into a database called XXXX_comments in a table called Comments, with columns for Name and Comment. When a user clicks the Save button, the form data should be inserted into the database. The d ...

Automatically resizing images in a canvas when their resolution exceeds the canvas size in HTML5

I am currently using Html5, fabric.js, and JavaScript to upload multiple images to a canvas. However, there are instances where the uploaded image size exceeds that of the canvas. I am looking for a way to ensure that the image is set to a fixed size. v ...

How can I use jQuery to implement a progress bar for Iframes loading?

My job involves working on an intranet where I have a complex aspx page with multiple Iframes, all of which we control. Each iframe is dynamically set using JavaScript/jQuery by different buttons on the page. Some buttons set the src attribute for iframes ...

The correct rendering of background image paths is not functioning properly

Currently, I am utilizing Django Compress to streamline the process of using fewer files in their original format, rather than converting them to CSS files. This method has been successful except for a minor issue with translating the paths for background ...

Discovering additional element information while utilizing the 'Sortable' feature

My Current Objective: In my setup, I have a 'calendar' comprising 5 columns, each column containing 5 separate divs known as timeslots. The main purpose here is to show appointments in these specific timeslots and utilize JQuery's Sortable ...