Is there a way to switch classes on a div when the checkbox is checked?

Is there a way to deactivate the :hover effect when :checked on a div that contains my checkbox?
I've attempted:

input[type=checkbox]:checked ~ #mydiv:hover {my:css}

This only seems to work for the div/class that does not include my checkbox...

Any suggestions on how to accomplish this?

Below is my code: http://codepen.io/casimirp/pen/gxfqE?editors=110 I am specifically looking to modify the #card:hover{ top:50px;}

Thank you

Answer №1

In this scenario, the #card element serves as a parent of a hidden checkbox input. It's not possible to select a parent element based on its child in CSS. However, since the checkbox is already hidden, you can simply move it to another location, such as being placed as a previous sibling of #card. This way, you will have the ability to target #card using :checked ~ #card and eliminate the need for the top property.

Link to example: http://codepen.io/anon/pen/maDjp

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

What is the best way to apply a border to a div with the style 'overflow:auto' specifically when the scrollbar is in use?

I am facing an issue with a dynamically filled div where the content exceeds a specific height, causing overflow:auto to display a scroll bar only after surpassing that threshold. My task now is to apply a 1px border around the entire div only when the co ...

Having issues with RTL on MuiTextField when using special characters

Currently, I am working on a project where Mui is being used. I have successfully applied RTL according to the Mui guide. However, I am encountering a frustrating problem where special characters in MuiTextField are aligning to the left instead of the righ ...

Why is jshint giving an error for HTML in $scope in Angular JS?

I need help figuring out how to include HTML tags in my model. Here is a basic example where I am trying to include b tags: .controller('AccordionDemoCtrl', ['$scope', function($scope) { $scope.oneAtATime = true; ...

Combining Two Tables Using jQuery

I am currently attempting to combine two tables into one using jQuery in the following manner: var table = document.createElement("table"); table.id = "mergedTable"; $("#mergedTable > tbody:last") .append($("#csvInfoTable2 > tbody").html()) ...

Finding the Xpath for a checkbox element by identifying the label element following it based on its value

I've been putting in a lot of effort into this issue, but I haven't been able to find a specific answer on StackOverflow or figure it out myself through experimenting with Xpath. I'm still learning, so I apologize if this is a basic problem, ...

I'm having trouble getting my modal to open, it just displays the information on my page instead

I am encountering some difficulties with my model window. I would like it to open a modal that shows a larger version of the photo and description when the thumbnail is clicked. However, I have not been able to get it to work properly. The only time it pop ...

Ways to display HTML elements depending on the width of the window

Is there a way to create visually appealing hexagon containers for text that work well across all window widths? Currently, the design is only satisfactory at certain window sizes. I am looking to implement a solution where specific code will be displayed ...

Setting up global color variables for React with Material UI theming is essential for ensuring consistent and

Is there a way to customize the default material-ui theme using global CSS? Additionally, how can we incorporate HEX values for colors when setting primary and secondary colors in the theme? In my App.js root file, I have defined a custom theme and want t ...

Changing the div background color based on the status of the `.play()` function

I need assistance with changing the background color of a div based on whether an audio file is playing or not. $('.uprow2').on('click', function() { $('#karma')[0].play(); }); .uprow2 { width: 680px; height: 60px; ...

How can I correct the changing order of buttons when floating to the right?

When I align a few buttons to the right, the order of those buttons changes. I have included an image for reference. View Navbar Image This is the code I am currently using: .btn{ float: left; padding: 1.7em; text-align: center; display ...

Hide the scrollbar in the div depending on the specified condition

I'm having trouble with this particular process and haven't been successful so far... I currently have a customized scrollbar within a div element, and what I am attempting to do is remove the scrollbar when the height of the div is less than 19 ...

A structured design approach combining fixed and fluid elements tailored for the 960.gs framework

Our website is designed using the 960.gs grid system, and I am attempting to customize it into a 3-column layout with Fixed(100px) - Fluid(max width) - Fixed(100px) view. However, most online generators for 960.gs grids only offer fully fixed or fully flui ...

Arrange and overlay PNG images within a Bootstrap container using position:absolute

I've been attempting to align and stack some images within a bootstrap grid, but I'm having some trouble. Instead of aligning within the grid, the images seem to align to the window instead. I've been using position:absolute, which I found ...

Mobile-friendly website with consistent design across all devices

Can you help me figure out how to make my website appear at its normal size on mobile devices? I want the entire website to be visible without the need for scrolling, but still allow users to zoom in if needed. I've already tried: <meta name=" ...

What causes the parent and grandparent elements to shift when adjusting the margin of a header tag?

I'm facing an issue with the h1 tag where changing its margin-top property also affects the parent and grandparent elements. Can someone shed light on why this is happening and provide a solution? If you observe, setting the h1 margin to 0 auto creat ...

What is the process for creating a new web page? [Exploring web design]

When creating a new page, how exactly does it work? For instance, on a website that allows users to create posts, you may see a link like this: example.com/post/randomised123 I'm curious - does this process also involve server directories like pop ...

Shorten the text as necessary for the final elements

I am working with Bootstrap 4 and have the following HTML code: <div class="badge-container"> <span class="badge badge-pill badge-primary">One</span> <span class="badge badge-pill badge-primary">Two</span> <span clas ...

What is the best way to calculate the time elapsed between two consecutive double clicks using jQuery?

I am trying to calculate the time difference between two clicks on a single button. Here is my code snippet: <a href="#">click here</a> My current JavaScript code to capture the time of each click is as follows: var clickedTime = '&apos ...

Ways to Achieve the Following with JavaScript, Cascading Style Sheets, and Hypertext

Can someone help me convert this image into HTML/CSS code? I'm completely lost on how to do this and don't even know where to start searching for answers. Any assistance would be greatly appreciated. Thank you in advance. ...

Dealing with preventing form submission in JQuery due to the use of Char(13) causing newline issues

Currently, I am facing an issue with capturing the class for my address field. I have successfully prevented the enter key (char[13]) from submitting the form. However, I now need to make an exception for text blocks, such as the address field, where I wan ...