Using the "checked" attribute in an HTML input to hide content with CSS when blocks are positioned in different

Is there a way to connect input with buttons similar to the code below, or is it impossible without changing the HTML (unless using JS code)? Please don't critique the HTML code, this is just an example from a website, I'm trying to determine if it's possible to access other nested blocks.

input:checked ~ button{
    display: none;
  }

<div  id="form">
    <section class="container">
        <form class="form">
            <section class="checkbox-control">
                <label for="personal-data-checkbox" class="checkbox-border">
                    <input type="checkbox"  id="personal-data-checkbox">
                </label>
                <label for="personal-data-checkbox" class="checkbox-label">
                    <span class="consent-message"></span>
                </label>
            </section>

            <section class="checkbox-control">
                <label for="cookie-checkbox" class="checkbox-border">
                    <input type="checkbox"  id="cookie-checkbox">
                </label>
                <label for="cookie--checkbox" class="checkbox-label">
                    <span> </span>
                </label>
            </section>

            <section class="buttons">
                <section class="confirm">
                    <button class="accept-all-button button">Agree to all</button>
                    <button class="confirm-button button hidden-button">Confirm</button>
                </section>
            </section>    
        </form>
    </section>
</div>

Answer №1

Is it possible to link input with buttons?

Unfortunately, connecting input with buttons is not currently possible. As of April 2020, there is no selector available to select a parent element based on its child.

However, according to https://dev.w3.org/csswg/selectors4/#relational, there are plans to include a :has() selector in the future. This selector would allow you to achieve this by using the following code:

.checkbox-control:has(input:checked) ~ .buttons button {
      display: none;
}

It's important to note that this feature is not currently supported by browsers.

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

Flask Template Failing to Load Local CSS

Hello there, I am currently working on integrating custom CSS into my Flask application. While I had no issues loading Bootstrap, I seem to be facing some difficulties with my local CSS. Below is the method I am using to load my CSS: <link rel="st ...

Tips for choosing the right element in CSS

Can someone help me with this issue? https://i.stack.imgur.com/pBu1w.png I've tried setting a CSS selector, but it doesn't seem to be working as expected. What could be causing the selector to not work properly? Any suggestions on how I can f ...

Adding text values to an HTML form action

I am working on a form that includes a text input field and a submit button. Is there a way for me to add the value of the text box to the form action URL? For example, can I dynamically change the action attribute to something like: action="https://www. ...

Using Selenium IDE to click on a checkbox within a table row

Currently, I am utilizing Selenium IDE to navigate through a table with multiple rows and columns. Each row within the table contains its own checkbox for selection purposes. In my attempt to search for a specific row, I have been using the following comm ...

What is the most efficient method for applying multiple classNames to elements in Next.js?

Could you provide me with a list of all methods, both with and without packages? Also, I'm interested in knowing why one method is considered better than the others. ...

Is it possible to manipulate CSS on a webpage using javascript?

I have incorporated this piece of JavaScript to integrate a chat box onto my website: window.HFCHAT_CONFIG = { EMBED_TOKEN: "XXXXX", ACCESS_TOKEN: "XXXXX", HOST_URL: "https://happyfoxchat.com", ASSETS_URL: "https://XXXXX.cloudfront.ne ...

How can I use Java Script to create animation of vertical black bars of a specific width moving across a white background?

Looking for a JavaScript code that can animate vertical black bars of a specific width moving over a white background. The desired outcome is similar to the video found at: https://www.youtube.com/watch?v=bdMWbfTMOMM. Thank you. ...

Enhancing CSS with Additional Properties

As a web developer, I recently had the opportunity to explore the new LOGIN PAGE preview of GMAIL and was very impressed with the Sign In button's UI. After examining the Page's CSS, I discovered some interesting properties, such as: **backgroun ...

Top method for expanding a SASS class using an inner selector (sub-class)

When it comes to styling HTML to display messages, here's what I have: <div className="message"> <div className="message_label"> A message </div> </div> To style these messages, I am using the SCSS class bel ...

Dynamic Website Layout Bootstrap 4 [ card designs and Tabs ]

Currently, I am in the process of developing a web application that needs to be responsive across various devices including mobiles, tablets, and PCs. My focus right now is on creating a user profile page that adapts well to different screen sizes. To achi ...

Ways to show text in a password field

I'm looking to have the password field on a page. I'd like to show the text "Enter password" on the screen before the user starts entering their password, but once they focus on the field to enter their password, it should switch back to password ...

What method can I use to enlarge the carousel component from the flowbit-svelte library?

I have been working on a project that requires a Carousel, and I decided to incorporate the flowbit-svelte carousel into my svelte project. While the carousel is functioning well, I am facing an issue with the component size. It seems to be cutting off my ...

How to read a text file in JavaScript line by line

Coding Challenge: <script src="../scripts/jquery-3.1.0.min.js"></script> <script> $(document).ready(function(){ $('#test').click(function(){ var txtFile = '../data/mail.txt'; var file ...

Is there a CSS alternative to using <br clear=all> on divs that do not have set heights?

Back in the day, I used to rely on <br clear=all> at the end of a div, without specifying a height value in CSS, just to control its height. These divs would expand and contract based on the content within. Is there a more elegant approach to make ...

Comparison of button text alignment: stacking vs inline placement

I currently have a button on my webpage labeled "Learn More." Unfortunately, the text on the button is not lining up as it should. Instead of flowing in a line, the text seems to be stacking on top of each other. The HTML code for the button is included ...

Stop the container from wrapping and allow its children to wrap instead

Here is a snapshot of my current layout: <div class="left"> ... </div> <div class="right"> <div class="inner" /> ... several more of these ... <div class="inner" /> </div> My CSS code looks like this: ...

A variable in Javascript storing data about jQuery DOM elements

Currently, I am using the slick slider for my development (http://kenwheeler.github.io/slick/) In JavaScript, there is an event that returns a variable called 'slick' When I print the variable using console.log, this is what I see: https://i.s ...

Align the reposition button with the pagination in the datatables

I am looking to adjust the placement of my buttons. The buttons in question are for comparison, saving layout, and printing. I would like them to be inline with the pagination, as I am using datatables here. <table id="sparepart_id" cellspacing="0" ...

The method used in Redux does not function properly with my sessionStorage

I am currently in the process of learning about Redux. One of my goals is to implement a favorites feature using Redux. To achieve this, I have created actions such as addFavoriteSPORTSs, SPORTSReducer reducers, and have dispatched them in tab-demo.js whil ...

Arranging Boxes side by side

I am struggling to align three boxes horizontally on my website, as they are currently stacking vertically. I have implemented Twitter Boostrap's 'row' class in an attempt to achieve this layout. HTML: .img-box-kai { width: 300px ...