`issues with concealing div upon hover`

Trying to create a new web design, I have implemented two divs with 50% width each that slide over on hover. However, I am facing an issue where I want the right 'logo' div to hide when hovering on the left 'slide' div and vice versa, but it's not working as expected. Can anyone offer some insight into what might be missing in my code? Any help would be highly appreciated!

    body {
        background:black;
    }
    .slide {
        position:absolute;
        top:0;
        bottom:0;
        width:50%;
        -webkit-transform:skew(-15deg);
        -moz-transform:skew(-15deg);
        -ms-transform:skew(-15deg);
        -o-transform:skew(-15deg);
        transform:skew(-15deg);
        z-index:2;
    }
    .slide:hover {
        width:60%;
        z-index:80;
    }
    .slide#left {
        left:0;
    }
    .slide#right {
        right:0;
    }
    .wrap {
        width:100%;
        height:100%;
        position:absolute;
        overflow:hidden;
        z-index:2;
    }
    .inner {
        width:100%;
        height:100%;
        -webkit-transform:skew(15deg) scale(1.5);
        -moz-transform:skew(15deg) scale(1.5);
        -ms-transform:skew(15deg) scale(1.5);
        -0-transform:skew(15deg) scale(1.5);
        transform:skew(15deg) scale(1.5);
        opacity:0.6;
        position:absolute;
    }
    .slide:hover .inner {
        opacity:0.9;
    }
    .inner#left {
        background:url(//savado.nl/new/key.jpg) no-repeat center center;
        -webkit-background-size:cover;
        -moz-background-size:cover;
        -ms-background-size:cover;
        -o-background-size:cover;
        background-size:cover;
    }
    .inner#right {
        background:url(//savado.nl/new/code2.jpg) no-repeat center center;
        -webkit-background-size:cover;
        -moz-background-size:cover;
        -ms-background-size:cover;
        -o-background-size:cover;
        background-size:cover;
    }
    .inner#left:hover .logo#right {
        display:none;
    }
    .inner#right:hover .logo#left {
        display:none;
    }
    .slide .logo {
        position:absolute;
        z-index:99;
        top:50%;
        height:30%;
    }
    .logo img {
        height:100%;
    }
    .logo#left {
        right:0;
        -webkit-transform:translateX(50%) translateY(-50%) skew(15deg);
        -moz-transform:translateX(50%) translateY(-50%) skew(15deg);
        -ms-transform:translateX(50%) translateY(-50%) skew(15deg);
        -o-transform:translateX(50%) translateY(-50%) skew(15deg);
        transform:translateX(50%) translateY(-50%) skew(15deg);
    }
    .logo#right {
        left:0;
        -webkit-transform:translateX(-50%) translateY(-50%) skew(15deg);
        -moz-transform:translateX(-50%) translateY(-50%) skew(15deg);
        -ms-transform:translateX(-50%) translateY(-50%) skew(15deg);
        -o-transform:translateX(-50%) translateY(-50%) skew(15deg);
        transform:translateX(-50%) translateY(-50%) skew(15deg);
    }
    div {
        -webkit-transition:opacity 0.6s ease, width 0.6s ease, z-index 0.6s ease;
        -moz-transition:opacity 0.6s ease, width 0.6s ease, z-index 0.6s ease;
        -ms-transition:opacity 0.6s ease, width 0.6s ease, z-index 0.6s ease;
        -o-transition:opacity 0.6s ease, width 0.6s ease, z-index 0.6s ease;
        transition:opacity 0.6s ease, width 0.6s ease, z-index 0.6s ease;
    }
    <div class='slide' id='right'>
        <div class='wrap'>
            <div class='inner' id='right'></div>
        </div>
        <div class='logo' id='right'>
            <img src='//savado.nl/new/logo.png' />
        </div>
    </div>
    <div class='slide' id='left'>
        <div class='wrap'>
            <div class='inner' id='left'></div>
        </div>
        <div class='logo' id='left'>
            <img src='//savado.nl/new/logo.png' />
        </div>
    </div>

And here is the [JSFIDDLE][1]!

Thank you for your assistance!

  [1]: http://jsfiddle.net/NZXeT/

Answer №1

The reason for this issue is due to your CSS

.inner#left:hover .logo#right {
  display:none;
}
.inner#right:hover .logo#left {
  display:none;
}

This code will not be effective because there is no .logo#right WITHIN your .inner#left:hover element, it only contains a .logo#left. The same applies to the other scenario.

You may need to reconsider your design approach in order to make this functionality work. Instead of having two logos that are hidden and shown based on hover states, why not consider using just one logo that moves from side to side? This could simplify your code and make the user experience smoother.

Answer №2

Your initial problem arises from the presence of multiple elements sharing the same ID, leading to confusion and invalid code. It is crucial to use unique IDs for each element.

In addition, CSS is limited in its ability to style only the targeted element, its siblings following that element, or its children. To work around this limitation using pure CSS requires some creative solutions.

Alternatively, utilizing javascript/jQuery offers a simple fix with just one line of code.

If you prefer sticking to HTML+CSS, you can employ the sibling selector ~ to affect the other slide. For example:

.slide#right:hover ~ .slide#left {display: none;}

This will successfully hide the left side when hovering over the right side as intended. However, achieving the reverse effect may prove challenging due to the order of elements in the markup. One workaround involves adding a hidden "trigger" element before .slide#right, matching the size and shape of

.slide#left</code, and applying the same rule but targeting <code>#lefttrigger
.

Does this explanation clarify the solution?

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

Overlay popup within iframe doesn't appear at the forefront of the page

I am facing an issue with displaying overlay and popup within an iframe on my aspx page. The iframe is calling another aspx page that includes the overlay and popup div elements. When I click a button within the iframe, the overlay and popup appear but t ...

Customize your HTML email by highlighting a specific part of a link with color

Can you apply different colors to specific parts of a link when using HTML in an email? I attempted the following: <a href=""><span style="color: #AB2328 !important;">red part of link</span> normal part</a> ...I understand that s ...

Guide on creating a square within an element using JavaScript

After conducting thorough research, I find myself unsure of the best course of action. My situation involves a Kendo Grid (table) with 3 rows and 3 columns. Initially, the table displays only the first column, populated upon the page's initial load. S ...

Collect data from website submissions via email

Is it possible to receive the results via email when someone submits their details on my site using a script? My server does not allow .php or .asp files, only .css. How can I achieve this? ...

Applying CSS to select a different element style within a webpage

I was thinking about the possibility of linking one style to another using events like :focus or :hover in CSS alone, without the need for JavaScript. For instance, can the class "hitArea" change the background attribute of "changeArea" when it is in foc ...

Styling the arrow of a CSS select box

Is it possible to place a dropdown arrow inside a select box? I have tried, but the arrow always displays behind the select box. How can I modify the CSS code to position the arrow properly inside the select box? .form-item-custom-search-types::before { ...

Is it possible to implement an automatic scrolling functionality in this code snippet?

https://codepen.io/hexagoncircle/pen/jgGxKR?editors=0110 Stumbled upon some interesting code to tinker with and came across this piece. Attempted to search online for solutions, but my grasp on React (or maybe Java?) is close to zero. Tried following guid ...

Changing JSON names to display on a webpage

I am looking to modify the name displayed in a json file for presentation on a page using ion-select. mycodehtml ion-select [(ngModel)]="refine" (ionChange)="optionsFn(item, i);" > <ion-option [value]="item" *ngFor="let item of totalfilter ...

Addressing Layout Problems When I Enlarge the Browser Width

My website is www.adventureswithross.com When the device width is larger than 601px, I have specific requirements: I need the menu and custom header to be seamlessly connected without any spacing in between. To address the issue of space above the custo ...

Integrating JavaScript and CSS files into Spring MVC

Greetings, I am currently exploring the Spring Framework and building my first application with it. However, I have encountered a particular issue that I would appreciate some assistance with. Please excuse any errors in my English. The problem I am facin ...

View complex response objects in Postman as easily digestible tables

I am interested in displaying the data provided below as a table using Postman Tests. The table should have columns for product, price, and quantity, with Items listed in rows. It's important to note that there may be multiple shippingGroups within th ...

Show results from selecting multiple dropdown options

I am looking to create a search function that displays results based on multiple dropdown selections. I have 4 dropdown menus and a submit button, but I am unsure how to show the search results upon clicking the submit button. The desired outcome is to dis ...

Instructions on sending search fields by pressing the enter key

Developing my application in React.tsx, I have a menu window that consists of numerous div elements with input fields, checkboxes, and select elements. Upon clicking the submit button, a list of results with user-selected filters appears. As an additional ...

How to Choose Between Landscape and Portrait Printing Modes in Firefox and Internet Explorer 8

Currently, I am using the latest version of FireFox and IE8. In order to change the printing orientation, I utilized the following code in my CSS file: @page { size: portrait; } You can find more information about the @page property here. Although it i ...

Cross-platform mobile browsers typically have scrollbars in their scrollable divs

I have successfully implemented scrollable div's on a page designed for tablets running Android 3.2+, BlackBerry Playbook, and iOS5+ (except iPad 1). However, I would like to add scrollbars to improve the user experience. For iOS5, I can use the suppo ...

Form submission not functioning within a bootstrap popover

I'm having trouble saving a URL from an input field (the form is inside a Bootstrap popover) - nothing happens when I click the save button. Below is my HTML code: <div id="popover-content" class="hide"> <form name ="bform" method = "post" ...

What are some ways to enhance mobile browsing with CSS?

I'm facing a challenge with optimizing my webpage for different mobile resolutions in my beginner HTML/CSS course. Whenever I use a website resolution simulator to test, the layout doesn't look right on certain settings. Is there a method to aut ...

Ways to keep a div anchored to the bottom of two other divs

I have three div elements each with 33% width. <div class="row"> <div class="col-md-4">a</div> <div class="col-md-4">a</div> <div class="col-md-4">a</div> </div> Is it possible to style the third div ...

What is causing the page to automatically scroll upwards when a gallery thumbnail is clicked on?

Currently encountering some unusual behavior with my photo gallery. Whenever I click on a thumbnail to view an image, not only does the image display but it also causes the page to scroll up. If the gallery is positioned slightly below the top of the scree ...

Here's a way to programmatically append the same icon to multiple li elements generated using document.createElement:

I am new to creating a to-do app and need some guidance. When a user enters a task, I successfully create a list item for that task. However, I am unsure how to add a delete icon next to the newly created li element. Can someone please help me out? Below ...