How come my div can alter its own attributes on hover, but its sibling cannot?

As I delve into the realm of web development, my initial project involves creating a portfolio site. However, I am facing difficulties with the dropdown section in one of the menus. I incorporated a :hover pseudo-class to the dropdownhover div to signal when to display the dropdown menu. Unfortunately, the dropdownnav class does not seem to change on line 67 as expected. I attempted altering the pseudo-class to only affect itself, which worked fine. However, when trying to modify a sibling class, it failed. Could this be due to a mistake with my combinators?

@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital@1&display=swap');

* {
    margin: 0;
    z-index: 0;
}

body {
    background-color: #EF2F88;
}

.navbar {
    background-color: #8843F2;
    margin: 0
}

.navlist {
    margin-right: 0;
    margin-left: 40%;
    height: 7rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    list-style: none;
}

.navlist li {
  height: 100%;
  text-align: center;
  flex: 1;
  position: relative;
}

.navlist li a {
    text-decoration: none;
    color: white;
    font-family: Source Code Pro;
    font-size: 2.5rem;
    top: 2rem;
    position: relative;
}

.dropdownnav {
    background-color: #8843F2;
    margin-top: 3rem;
    height: 8rem;
    opacity: 0;
}

.dropdownlist {
    justify-content: space-between;
    display: flex;
    gap: 1rem;
    flex-direction: column;
    list-style: none;
}

.dropdownlist li {
    text-align: left;
}

.dropdownlist li a {
    font-size: 1.5rem;
}

.dropdownhover:hover + .dropdownnav {
    opacity: 1;
}

.dropdownhover {
    position: absolute;
    top: 0;
    height: 15rem;
    width: 100%;
}
<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="UTF-8">    
        <link rel="stylesheet" href="styles.css"></link>
        <title>Portfolio</title>
    </head>
    
    <body>
            <!--NAV BAR SECTION-->
        <nav class="navbar">
            <ul class="navlist">
                <li id="about">
                    <a href="index.html">About Me</a> 
                </li">
                <li id="projects">
                    <a href="index.html">Projects</a> 

                    <nav class="dropdownnav">
                        <ul class="dropdownlist">
                            <li class="mania">
                                <a href="">Clicking Mania</a>
                            </li>
                            <li class="bloopville">
                                <a href="">Bloopville</a>
                            </li>
                        </ul>
                    </nav>

                    <div class="dropdownhover"></div>
                </li">
                <li id="skills">
                    <a href="index.html">Skills</a> 
                </li">
                <li id="contact">
                    <a href="index.html">Contact</a> 
                </li">
            </ul>
        </nav>
    </body>
</html>

Answer №1

.dropdownhover:hover + .dropdownnav:hover {
    visibility: visible;
}

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

Run a function upon clicking a button in JavaScript

Could someone please help me figure out what I am doing incorrectly in the code below? I am attempting to trigger a function when a button is clicked. The HTML: <button id="btn1">Press me!</button> <input type="button" id="btn2" value="Pr ...

What is the best method for implementing border-radius on select2 elements?

I previously had a default bootstrap user select box with a border-radius style applied: <div class="container"> <select class="form-control" style="border-radius: 1rem;"> <option value="1">Us ...

Ensure Focus Retention Upon Clicking Inside Iframe with li a:focus

How can I prevent my ul.SideNav_Main li a:focus class from losing focus when I click on the iframe or elsewhere on the page? Shouldn't it maintain focus until I click on another URL in the list? Is it possible to solve this issue with just CSS, or wo ...

The JQuery script functions properly when directly embedded in an HTML file, but fails to work when linked from an external file

While I'm working on some code using JQuery's .hover method, I've encountered an interesting issue. It seems to work fine when written directly in the main HTML file index.html, but for some reason, it fails to execute when written in a Java ...

How about mixing up your backgrounds with an overlay effect for a unique look?

Hey there, I'm currently working on adding random backgrounds to my website through an overlay, but I've hit a roadblock when it comes to displaying them. Here is the code I'm working with: .css / .php #intro { background: ...

The font remains the same despite the <Div style=> tag

I have a script that loads external HTML files, but I am facing an issue with changing the font to Arial. The script is as follows: <script type="text/javascript"> $(document).ready(function(){ $("#page1").click(function(){ ...

Bootstrap overrides the color of the calendar year in jQuery UI

I am facing an issue where the CSS styles of my jQuery UI calendar are being overridden by the Bootstrap CSS styles. Take a look at the screenshot provided. As you can see, the text color of the calendar's year is not black as intended. https://i.ss ...

Streamlined Boilerplate to Kickstart Your Project

Can anyone suggest a well-crafted boilerplate .less file to kickstart a new project? I'm looking for a comprehensive .less file that includes: CSS Resets styles CSS Normalizer styles CSS3 Helpers (box radius, gradients, box shadow, transition) Basic ...

Incorporating an external JSX file into an HTML page in a React project

I have a React code in my js/script.js file. My HTML page's head tag is structured like this: <head> <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="06746367657246373328302834" ...

Height of the Accordion List

I have a code snippet below for an accordion list that I put together. I initially set the height for all the heading boxes to be uniform, but it seems like box A is displaying larger than the others. Can you help me figure out what went wrong? Any suggest ...

Customizing checkbox appearance without including a label

After following a tutorial on how to style checkboxes found here, I was able to create a custom styled checkbox. However, I noticed that when I removed the label from the checkbox, it disappeared and was no longer visible. Is there a way to display the c ...

A tutorial on allowing a background element to capture the click event triggered by a foreground element

Within a container div, I have a background and foreground div. I want the click event on the foreground div to be passed through to the background div for handling the event. How can this be achieved in Angular 2+? Here is an example structure of my div ...

Developing a Java applet for the purpose of showcasing it in a web browser

As I embark on the journey of creating a basic Java applet to showcase my program's output in a web browser, I find myself facing unfamiliar territory. To gain a grasp on how applets function, I decided to follow a tutorial and create a simple "Hello ...

Is there a simpler method to access the source element for an event?

I'm just starting to learn JavaScript and jQuery, and right now I have the following code in my HTML: <a id="tog_table0" href="javascript:toggle_table('#tog_table0', '#hideable_table0');">show</a> After that, I hav ...

Unfold an HTML element and reveal a sneak peek of its content with the aid of JQuery

I need a way to organize and display a set of 5 lines of text vertically. Specifically, I want them arranged like this: 1) Line one 2) Line two 3) Line three 4) Line four 5) Line five However, I have a special requirement where only the first ...

How can recursive data be displayed in a template?

I am working with a model in Django that has a ForeignKey pointing to itself, and I need to display all the data from the database using lists and sublists: Below is my model definition: class Place(models.Model) name = models.CharField(max_length=1 ...

How can you align square cells within a container using CSS grids while maintaining a consistent grid gap?

Our objective is to perfectly align square cells with the edges of their container while maintaining a consistent gap between cells in each row and column. Although this Codepen solution is close, there are two key issues: (1) vertical spacing doesn' ...

Struggling with modifying class in HTML using JavaScript

I've been attempting to replicate a JavaScript code I came across on the internet in order to create a functioning dropdown menu. The concept is quite straightforward - the div class starts as xxx-closed and upon clicking, with the help of JavaScript, ...

Is there a way for me to view the output of my TypeScript code in an HTML document?

This is my HTML *all the code has been modified <div class="testCenter"> <h1>{{changed()}}</h1> </div> This is my .ts code I am unsure about the functionality of the changed() function import { Component, OnInit } f ...

Strategies for enhancing the performance of this arbitrary playlist HTML5 audio script

<script type="text/javascript"> function random_music(){ var myrandom=Math.round(Math.random()*4); var musicurl='http://dummy.xy/dummy.mp3'; if (myrandom==0){musicurl='http://path_to.mp3';} else if (myrandom= ...