How to dynamically toggle the visibility of neighboring HTML elements with CSS

https://i.sstatic.net/ENpqW.jpg

In the image linked above, there is a scenario where the create button and password inputs are initially disabled. When the user verifies their email address, the create button becomes enabled. The challenge is to use CSS to enable these two inputs based on the state of the button.

This task involves integrating with a third-party login system that restricts the use of JavaScript and other technologies. Therefore, the solution must be implemented using only CSS.

<div class="section1">
  <ul>
    <li>
      <label>Email Address</label>
      <input id="email">
      <button type="submit">Send verification code</button>
    </li>
    <li>
      <label>New Password</label>
      <input id="pwd" disabled>
    </li>
    <li>
      <label>Confirm Password</label>
      <input id="cnfpwd" disabled>
    </li>
  </ul>
</div>
<div class="section2">
  <button type="submit" **id="create"** disabled>create</button>
  <button type="submit">cancel</button>
</div>

<!-- CSS -->
label{
  width:100%;
  display:block;
}
input{
  display:block;
}

The objective is to use CSS to enable the inputs in section1 based on the status of the button in section2.

Answer №1

How can I style these two inputs to be enabled when this button is clicked, using only CSS?

This task may seem daunting.


To start, CSS lacks the ability to target elements above in the DOM,

and furthermore, it cannot alter the disabled status of an element in the first place.

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 paste plain text into a Textarea without any formatting?

A challenge I am facing in my project is related to copying and pasting text into a Textarea. When a user copies text, the style of the text is also inserted along with it. However, when the user manually types the text, it gets inserted correctly without ...

Utilizes an external CSS font file for eBay advertisement

After researching numerous answers, I am still unable to identify what I may be doing wrong. I have designed a collection of custom fonts using iconmoon, and after downloading the css and font files, I uploaded them to a directory on my website. I am attem ...

Slider with FadeIn effect remains unresponsive to the FadeOut command (JQuery / Javascript)

I'm currently working on a slider that is supposed to fade in and out. However, I am facing an issue where the slide fades in correctly but instantly disappears instead of fading out. Do you have any insights into why this might be happening and any s ...

Design question: how can we create a layout where the Header, Content, and Footer all have expanding background colors but still maintain centered content?

In my layout, I wanted everything to be centered using the "margin=0 auto" technique. However, I also needed the header and footer to expand to both sides when the browser window is enlarged. The challenge was that if I centered everything, the black backg ...

What is the best way to set conditions for document side script?

I'm struggling to disable the horizontal scroll when the viewport width is 480px or less. The script that controls the scroll behavior on my website looks like this: <script> $(function () { $("#wrapper").wrapInner("< ...

The Intersection Observer fails to function properly with images

I recently discovered that images require different intersection observer code than text in order to function properly. After making the necessary changes to the code, my intersection observer is behaving quite oddly. As I scroll down, the image stays hidd ...

Using HTML and CSS to create a display-table for laying out a form

Working on a dynamic HTML/CSS layout that simplifies the process by using classes like form, row, cell label, and cell input to control elements (width, alignment, etc.). I decided to utilize display: table along with its child elements table-row and tabl ...

What is the best way to replicate the orange outline when focused?

I am in the process of creating a series of divs that can be navigated by the user using the tab key. I would like to incorporate the standard orange focus outline for these elements. Is there anyone who can provide guidance on how to achieve this? I unde ...

Align text within HTML with the use of Bootstrap

Example data value category type item1 100 food fruit item2 50 drinks soda item3 75 snacks chips I want to achieve this forma ...

Is there a way to horizontally align the content in my footer section?

I am currently exploring React Material UI for the first time. The table I am working with can be found here under the "Custom pagination actions" section. Within this section, there is footer content containing buttons for rows per page, next, previous, ...

What is the best way to conceal just the scrollbar thumb in a Bootstrap modal?

When opening a modal in Bootstrap according to the documentation, it only hides the scrollbar thumb, like shown in the examples below: However, my modal hides the entire scrollbar. How can I modify it to hide only the scrollbar thumb? body { height: ...

Problems encountered when applying box-shadow for text background across multiple lines

Lately, I've become accustomed to using box-shadow to add backgrounds to text headings. I've been employing a little trick of applying a box-shadow to a span element within h1 tags in order to create a unique "background with padding" highlight e ...

What is the best way to leverage environment variables in my CSS within the context of Next.js for defining the primary color scheme?

Is there a way to use an environment variable to specify the base color in my CSS? I am working with NEXTJS. All of my colors are defined as variables in my globals.css: @layer base { :root { ... --primary: #0096d0; --primary-bright: ...

Creating a folded-corner effect in CSS with a clear background - here's how!

Can anyone assist me? I am trying to change the folded-corner to be transparent instead of a solid color. Please refer to the image below for guidance. https://i.sstatic.net/ZMrT8.png I have attempted to modify these codes: .back-ground { backgrou ...

Is there a way to make text fade in and out smoothly instead of abruptly disappearing and reappearing after an animation ends?

I'm seeking a unique animation effect for my right-to-left scrolling text. Instead of the text teleporting back to its origin at the end of the animation, I would like it to smoothly disappear and reappear from the margins. .custom-animation { he ...

Maintain the highlighting of the parent menu item even when hovering over the submenu (HTML/CSS/Jquery)

Having a menu with the potential for subitems, it seems simple enough. The goal is to highlight the parent menu item once the submenu is moused over. Unfortunately, this doesn't happen as expected because the browser reverts back to its default style ...

Dynamic font sizing in CSS allows text on a webpage to

I am working on creating a dynamic screen using AngularJS. Within this screen, there are objects with a specific size: .item { margin: auto; margin-bottom: 10px; width: 11vw; height: 11vw; text-overflow: ellipsis; overflow: hidden; } These i ...

What do you call this technique, and how can I replicate it? (Adjusting text)

Have you noticed the cool feature on ? It automatically changes the text midway through the page (Sketch is made for insert changing text here like you) after some time. I'm curious about how they achieved that and what it's called. I'm att ...

The Heading I am trying to navigate to is partially obscured by the fixed topbar

I admit my code is quite messy, but this is my first project and I'm still figuring out how to properly structure it. I attempted to use margin with h2::before in CSS, and it sort of worked, but it caused other issues with the text layout. I've h ...

Bootstrap only allows for styling the border row and outside of a table

I'm looking to remove the vertical border of a table using bootstrap, except for the outside border as illustrated below. https://i.sstatic.net/RYq7o.png I've attempted to achieve this by: <table class="table no-footer worker-data tabl ...