Having trouble with hover effects not working on links due to the container? Here's a solution for you

I would like to create a layout with 3 columns for menu, story, and description. Each story should have its own unique description. Everything was working fine until I added a div to the middle column. The same issue arose with the right column but I managed to resolve it by adding div to ~ .desc, ~ .s1-desc, and ~ .s2-desc. I understand why the selection doesn't work for the middle column, but I am unsure of what needs to be implemented to achieve the desired outcome. How can I make it so that when I hover over .s1, .s1-desc is displayed?

Here is the code snippet that is currently functioning: (The div causing issues in the HTML has been commented out)

<!DOCTYPE html>
<html>
<head>
    <style>
        .row {
            display: flex;
        }

        .sideCol {
            flex: 30%;
            margin: 10px;
            padding: 10px;
        }

        .midCol {
            flex: 40%;
            margin: 50px;
        }

        .desc, .s1-desc, .s2-desc {
            display: none;
        }

         a:not(.home):hover ~ div .desc {
            display: block;
            color: red;
        }
        
        .s1:hover ~ div .s1-desc, .s2:hover ~ div .s2-desc {
            display: block;
            color: purple;
            padding: 10px;
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <div class="row">
        <div class="sideCol">
            <p>Menu</p>
            <a href="#">Category One</a>
            <a href="#">Category Two</a>
        </div>
        
        <!-- <div class="midCol"> this div is what breaks the scope but I need a column here -->
            <p>Selection</p>
            <a class="home" href="#">Home</a>
            <a class="s1" href="#">Story One</a>
            <a class="s2" href="#">Story Two</a>
        <!-- </div> -->
        
        <div class="sideCol">
            <p class="desc">Description</p>
            <p class="s1-desc">Desc of Story One. A Desc of Story One. Desc of Story One. A Desc of Story One. Desc of Story One.</p>
            <p class="s2-desc">Desc of Story Two. A Desc of Story Two. Desc of Story Two. A Desc of Story Two. Desc of Story Two.</p>
        </div>
    </div>
</body>
</html>

The following code snippet showcases the issue:

<!DOCTYPE html>
<html>
<head>
    <style>
        .row {
            display: flex;
        }

        .sideCol {
            flex: 30%;
            margin: 10px;
            padding: 10px;
        }

        .midCol {
            flex: 40%;
            margin: 50px;
        }

        .desc, .s1-desc, .s2-desc {
            display: none;
        }

         a:not(.home):hover ~ div .desc {
            display: block;
            color: red;
        }
        
        .s1:hover ~ div .s1-desc, .s2:hover ~ div .s2-desc {
            display: block;
            color: purple;
            padding: 10px;
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <div class="row">
        <div class="sideCol">
            <p>Menu</p>
            <a href="#">Category One</a>
            <a href="#">Category Two</a>
        </div>
        
        <div class="midCol">
            <p>Selection</p>
            <a class="home" href="#">Home</a>
            <a class="s1" href="#">Story One</a>
            <a class="s2" href="#">Story Two</a>
        </div>
        
        <div class="sideCol">
            <p class="desc">Description</p>
            <p class="s1-desc">Desc of Story One. A Desc of Story One. Desc of Story One. A Desc of Story One. Desc of Story One.</p>
            <p class="s2-desc">Desc of Story Two. A Desc of Story Two. Desc of Story Two. A Desc of Story Two. Desc of Story Two.</p>
        </div>
    </div>
</body>
</html>

Answer №1

Here's an example:

.row {
  display: flex;
  display: -webkit-flex;
}

.sideCol {
  flex: 30;
  -webkit-flex: 30;
}

.summary {
  display: none;
  position: fixed;
  top: 20%;
  right: 0;
  width: 30%;
  border: solid;
}

a:hover+.summary {
  display: block;
}
<body>
  <div class="row">
    <div class="sideCol">
      <p>Navigation</p>
      <a href="#">Link One</a>
      <a href="#">Link Two</a>
    </div>

    <div class="midCol">
      <p>Content</p>
      <a class="home" href="#">Home</a>
      <a class="s1" href="#">Section One</a>
      <div class="summary">
        <p>Details for Section One</p>
      </div>
      <a class="s2" href="#">Section Two</a>
      <div class="summary">
        <p>Details for Section Two</p>
      </div>
    </div>
    
    <div class="sideCol"></div>
  </div>
</body>

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 concept of CSS sprites and managing background positions

I have been working on integrating a star-rating widget that requires the use of a sprite file. The sprite file I am using looks like this: https://i.stack.imgur.com/ZSMMj.png This is how my HTML is structured: HTML <span id="star-ratings" class="c ...

The CSS show and hide feature is effective across all browsers except for Safari. What steps can be taken to address this issue

My toggle trigger works perfectly in Chrome, but I'm having trouble getting it to work in Safari. Any suggestions? <a href='#show'class='show'>see more --></a> <a href='#hide'class='hide&apos ...

Determine if the HTML Application Cache is void

Our website uses a "manifest.appcache" file to manage the application cache. Some pages are designed to be accessed offline, so they have references in the html tag to the manifest, while others do not. Is there a way to determine if the cache is empty ac ...

How can I determine if a user has reached the end of a non-scrollable div by utilizing HostListener and directives within Angular?

In my Angular project, I have designed a main layout using flex display with specific height and overflow settings. The main content div inside this layout has its own unique styling to ensure consistent appearance for any components inserted within it. By ...

Using the identical code, Wicked PDF generates distinct reports on separate computers

While utilizing Ruby on Rails to render a PDF using WickedPDF and sending it via email, I encountered an unexpected issue. The same code is present on two separate computers, both with up-to-date versions synced from GitHub. However, the generated PDF repo ...

Utilize the atan2() function to rotate a div so that it follows the movement of the mouse

I am trying to create an effect where the mouse aligns with the top of a div and the div rotates as the mouse moves. The rotation should happen when the top part of the div is in line with the mouse cursor. My goal is to achieve this using the atan2 functi ...

Utilizing the hcSticky plugin for creating a scrolling effect on webpage content

I'm attempting to utilize the JQuery plugin, hcSticky, in order to achieve a scrolling effect on my fixed content. However, I seem to be encountering some difficulty getting it to function properly. What could I possibly be doing incorrectly? JSFIDDL ...

What is the best way to direct users to an input field within a dynatree title?

I am currently utilizing Dynatree to display a tree view, and my goal is to focus on an input field within the dynatree title element. However, I am encountering an issue where the focus is being lost. My code attempts to address this problem but unfortun ...

The res.download() function in Express is failing to deliver the accurate URL to the client

When trying to utilize the res.download() method for downloading specific files from a server, there is an issue where triggering the res.download does not redirect the client to the correct URL. The files intended for download are located in a directory s ...

Having Trouble with jQuery toggleClass

I'm currently working on a project where I have implemented a button that displays a menu when clicked. I am attempting to change the color of the button when it is active, however, the toggleClass function is not behaving as expected. Below is the co ...

Guide on adjusting image dimensions in JTextPane using HTML and CSS in the Java Swing environment

I am looking to add an image (such as a formula created from LaTeX) into JTextPane, using HTML+CSS for text formatting and manually setting its size. I attempted the following approach: import java.awt.Dimension; import javax.swing.JFrame; import javax.swi ...

What causes the source code of a website to change when accessed from various browsers?

When analyzing the source code of bartzmall.pk using various browsers, it reveals different classes being added to the html tag for each browser. For Firefox: <html class="firefox firefox53 otherClasses"> For Chrome: <html class="webkit chrome ...

What is the best way to ensure that my multiple choice code in CSS & JS only allows for the selection of one option at a time? Currently, I am able

I'm currently facing a small issue that I believe has a simple solution. My knowledge of Javascript is limited, but I am eager to improve my skills in coding for more visually appealing websites. My problem lies in the code snippet below, where I am ...

Unexpected behavior from HTML5 number input field

Is there a way to prevent users from entering values outside the specified max and min attributes? The constraints work when using the arrows in the input field, but not when typing directly into it. Note: I am considering utilizing angularjs for this fun ...

Crafting CSS for styling input type file elements

My attempts to style the input type file with CSS have been unsuccessful. In my current code, the "choose file" button is displaying above my styled button. How can I use CSS to remove this? I am aiming to only display a blue colored button for uploading ...

What is the best method for developing a draggable element that remains stable?

I have developed a simple script for draggable elements, however, I am facing an issue. Whenever I move the mouse quickly, the element loses focus. Is there a way to improve the stability of the dragging functionality regardless of how fast I move the mou ...

Tips to prevent modal impacts on underlying elements?

When I click on a button, a modal pops up. However, the background contents seem to spread out and sometimes scroll automatically when the modal appears. I have searched for a solution to this issue but have been unsuccessful. Can anyone please help me ide ...

Animating a gradient within an SVG element following along an SVG path

I successfully created an SVG egg and animated a path while adding a gradient, but I am facing an issue. The linear gradient goes from top to bottom, but I want the dark color at 0% and the light color at 100%. Essentially, I want the gradient to follow th ...

Achieve uniform height for two elements using Material UI

Here is the code snippet I have: <div className="center"> <TextField variant="outlined" className="manualUserFollowTxt" required id="manualUserFollowTxt" label="Username" name="username" autoComplete="username" a ...

Is it possible to create a hyperlink in the <button> element?

Having been immersed in HTML5 for quite a while now, I recently encountered a challenge while working on my login/register page project. I wanted to create a button that would redirect me to another HTML page upon clicking. While I am familiar with the < ...