Is there a way to alter visibility once a radio button has been selected?

I have a shape resembling a cube with 4 faces, all of which are currently visible. However, I would like to hide the other 3 faces when one face is showing.

For example: I attempted setting the opacity of the other cube sides to 0 when the first radio button is selected, but encountered difficulty in reverting the opacity back to 1 for the other sides when a different radio button is clicked.

I have tried implementing this in CSS, but it did not yield the expected results. Here is the code snippet:

.cube-container {
  width: 22.5em;
  height: 28em;
  text-align: center;
  perspective: 45em;
  margin: auto;
  text-align: center;
}

.cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition-duration: 2s;
  transform: rotateX(-15deg) rotateY(20deg);
}
// Rest of the CSS code omitted for brevity

<div class="cube-container">
  <input class="radio-button" type="radio" name="cube-gallery" checked/>
  // More input elements removed for simplicity
</div>

Desired outcome: when .radio-button:nth-child(1):checked => hide the other cube sides

Answer №1

If I'm understanding your query correctly, by incorporating the CSS provided below, you should achieve the desired outcome:

.radio-button:nth-child(1):not(:checked)~div.cube div.cube-side:nth-child(1) {
  visibility: hidden;
}

.radio-button:nth-child(2):not(:checked)~div.cube div.cube-side:nth-child(2) {
  visibility: hidden;
}

.radio-button:nth-child(3):not(:checked)~div.cube div.cube-side:nth-child(3) {
  visibility: hidden;
}

.radio-button:nth-child(4):not(:checked)~div.cube div.cube-side:nth-child(4) {
  visibility: hidden;
}

Please let me know if this solution was effective or not.

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 width of Bootstrap 5.3.0 form checkboxes varies between options

CSS input[type='checkbox'] { transform: scale( 2 ); margin-right: 1.5em; } Html <div class="form-check d-flex align-items-center mb-3"> <input class="form-check-input" type="checkbox" value=&quo ...

Displaying a preloaded image on the canvas

Once again, I find myself in unfamiliar territory but faced with the task of preloading images and then displaying them on the page once all elements (including xml files etc.) are loaded. The images and references are stored in an array for later retrie ...

Vue-Router failing to redirect in a Single Page Application using Vue and Laravel

I have been attempting to implement vue-router in a Vue.js/Laravel project. My project consists of two simple pages: home page: https://i.stack.imgur.com/GmHOR.png about page (single-page scrolling): https://i.stack.imgur.com/CZDnZ.png The files used ...

Mastering the art of manipulating Div elements using CSS for the optimal Print View experience

I have a table with several columns and 1000 rows. When I print the page, it breaks the rows onto different pages, showing the remaining rows on subsequent pages. I want to display the complete record in one go. Below is a sample code with only one row in ...

Strip the pound symbol from the end of a URL during an AJAX request

When I click on the News tab in my Rails application (version 2.3.4 and Ruby 1.8.7), an Ajax call is triggered to load data. <a href="News" onclick="load_feed();"><u>Show More...</u></a> <script> function load_feed() { $.a ...

Is it possible to use Selenium with Python for copying and pasting

Is there a way to use control + A in Selenium Python to select text and then retrieve the highlighted text? ...

What is the best way to transfer data between controllers in my particular situation?

Currently, I am working on developing a factory for the restful services. The main challenge I'm facing is how to transfer data from one controller to another in AngularJS. Specifically, I need to use the data obtained from the first service call to ...

creating circular shapes with canvas functions

Creating a circle in my game seems to be more challenging than I anticipated. While there are numerous tutorials available, none seem to address my specific issue. The problem lies in where and how to draw the circle within my existing code: function start ...

An issue with type conversion arises in Visual Basic when trying to access data from an HTML

I'm currently working with an HTML table that allows for dynamically adding and deleting rows with text-input's in the cells using JavaScript. Instead of ASP.NET TextBox controls, I am sticking to traditional HTML because I believe rows containin ...

Remove Chosen Pictures (Checkbox/PHP/MySQL)

I am currently displaying images from a Database using the following HTML code: <li> <input type="checkbox" id="1" /> <a rel="gallery_group" href="images/big/1.jpg" title="Image 1"> <img src="images/small/1.jpg" alt="" ...

Is it possible to customize the color of an SVG image within Next.js using next/image?

import Image from 'next/image' ... <Image src="/emotion.svg" alt="emtion" width={50} height={50} /> I am trying to change the color of the SVG using next/image. However, applying the following CSS rule does not seem ...

Using JQuery Slider to call a function without the need for an ID, instead utilizing the object directly

Currently, I am working on implementing a Slider using JQuery, and I have encountered an issue in my code. The function is set to run when the page loads, creating a slider with the Id specified in the div element: $(function() { $( "#slider& ...

Styling a div element in CSS with absolute positioning and the ability to

I am looking to set specific positions and dimensions for the div elements within my HTML document. Refer to this image for reference: https://i.stack.imgur.com/ANBVm.png For each of these div elements, I want a vertical scrollbar to appear if the content ...

Navigational bar with horizontal scrolling in Bootstrap

I'm looking to create a navbar that remains fixed at the top of the screen, without any vertical scrolling. However, I still want users to be able to scroll horizontally when necessary. The first div in the code below achieves the desired effect, stay ...

Choose all the HTML content that falls within two specific tags

Similar Question: jquery - How to select all content between two tags Let's say there is a sample HTML code as follows: <div> <span> <a>Link</a> </span> <p id="start">Foo</p> <!-- lots of random HTML ...

Reveal the MongoDB database connection to different sections within a Next.js 6 application

Currently developing an application using Next.js v6, and aiming to populate pages with information from a local mongodb database. My goal is to achieve something similar to the example provided in the tutorial, but with a twist - instead of utilizing an ...

What characterizes a dynamic webpage?

Can someone help me figure out how to determine the number of dynamic pages on a website? I'm not sure if the presence of a form means the page is dynamic. Any insights would be greatly appreciated. Thank you in advance for your assistance. ...

Transforming JavaScript statements and functions inside parentheses to make them React compatible

I'm struggling to understand the meaning and function of this parenthesis statement. Can someone provide clarity? function fadeOut(el){ el.style.opacity = 1; (function fade() { <-- Is this responsible for continuous execution? ...

What is the best way to show only the weekdays on the x-axis?

My goal is to create a scatter-linked graph using D3.js, showcasing the people count for various shifts on different dates in January 2020. Here is the code snippet I am working with: <!DOCTYPE html> <html lang="en" > <head> & ...

What is the process for implementing an image as the background instead of a color for each column in a Google chart?

I'm currently working with Google Chart and I have set up a column chart. However, I am looking to display a background image instead of a background color in each column. Is this achievable with Google Chart? If so, how can I accomplish this? If anyo ...