Display the input button element using only CSS

In order to make a section visible when a checkbox in another section is checked, I would like it to appear with a top-down animation effect. Below is the code snippet for the input located in the other section:

<div className="continue" id="first">
        <button className="btn-continue">
          Hire Plan
          <input type="checkbox" id="reveal-email" role="button"/>
        </button>

      </div>

      <section className="plan-section" id="plan-section">
        <div className="next">
          <i class="arrow down"></i>
        </div>
        <div className="form-block">
          <form className="form">
            <div className="plan-form">
              <div className="input-block">
                <label htmlFor="name">Name</label>
                <input type="text" name="name" id="name" onChange={props.handleChange} required className="input" />
              </div>

              <div className="continue">
                <button className="btn-continue" id="plan-continue" disabled={props.step.isLast()} onClick={props.next}>
                  <span className="btn-text">Hire Plan</span>
                  <img className="check-btn" src={check} />
                </button>
              </div>
            </div>
          </form>
        </div>
      </section>

It's worth noting that the section I want to reveal initially has a display:none style attribute.

Answer №1

This is a traditional JavaScript task. Implement an onclick event to verify if the checkbox is selected and then modify the section's visibility from display: none to display: block. Additionally, include an onclick event to activate the JavaScript function.

function showSection() {
  var showSection = document.getElementById("reveal-email"),
      planSection = document.getElementById("plan-section");
  if (showSection.checked == true) {
    planSection.style.display = "block";
  } else {
    planSection.style.display = "none";
  }
}
#plan-section {
  display: none;
}
<div className="continue" id="first">
  <button className="btn-continue">Contratar Plano
    <input type="checkbox" id="reveal-email" onclick="showSection()">
  </button>

</div>

<section className="plan-section" id="plan-section">
  <div className="next">
    <i class="arrow down"></i>
  </div>
  <div className="form-block">
    <form className="form">
      <div className="plan-form">
        <div className="input-block">
          <label htmlFor="name">Nome</label>
          <input type="text" name="name" id="name" onChange={props.handleChange} required className="input" />
        </div>

        <div className="continue">
          <button className="btn-continue" id="plan-continue" disabled={props.step.isLast()} onClick={props.next}>
                  <span className="btn-text">Contratar Plano</span>
                  <img className="check-btn" src={check} />
                </button>
        </div>
      </div>
    </form>
  </div>
</section>

Answer №2

Here's a suggestion for your code:

<button className="btn-continue">
                    Hire Plan
    <input type="checkbox" id="reveal-email" role="button"></input>
</button>

It's not recommended to include a checkbox and text within a button element in HTML. Consider using a label instead.

If you are open to a JavaScript solution, follow these steps:

  1. Locate the checkbox and section elements in the DOM
  2. Add an event listener that will trigger a callback function when the checkbox state changes
  3. In the callback function, adjust the style of the section accordingly

The complete code snippet is provided below:

var checkbox = document.getElementById('reveal-email');
var section = document.getElementById('plan-section');

checkbox.addEventListener('change', onChange)

function onChange() {
  if (this.checked) {
    section.style.display = "block";
  } else {
    section.style.display = "none";
  }
}
<div className="continue" id="first">
  <button className="btn-continue">
    Hire Plan
    <input type="checkbox" id="reveal-email" role="button"/>
  </button>
</div>

<section className="plan-section" id="plan-section" style="display:none">
  <div className="next">
    <i class="arrow down"></i>
  </div>
  <div className="form-block">
    <form className="form">
      <div className="plan-form">
        <div className="input-block">
          <label htmlFor="name">Name</label>
          <input type="text" name="name" id="name" onChange={props.handleChange} required className="input" />
        </div>

        <div className="continue">
          <button className="btn-continue" id="plan-continue" disabled={props.step.isLast()} onClick={props.next}>
            <span className="btn-text">Hire Plan</span>
            <img className="check-btn" src={check} />
          </button>
        </div>
      </div>
    </form>
  </div>
</section>

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

Tips for ensuring that the lightbox scrolling feature only affects the lightbox and not the entire page

Currently, I am utilizing the lightbox_me jQuery plugin to trigger a lightbox when a user clicks on a product. The issue I am facing is that the lightbox content often extends below the visible area, causing the entire page to scroll when using the right s ...

Components within components within components

I am looking to create a wrapper for my content in order to utilize some general events within it. The desired structure would be as follows: var Table = React.createClass({ render: function () { return ( React.createElement(&apos ...

What is the best method for customizing the color of angularjs spinners?

As I delve into developing an AngularJS application, my focus has been on seamlessly integrating an AngularJS spinner. Taking it a step further, I managed to tailor some of the spin-kit CSS properties to customize the appearance and behavior of the spinn ...

Mastering the Integration of React in Node.js

I've been eager to experiment with Server Side Rendering in React, however, my code isn't functioning as expected. It seems like I might be overlooking something crucial. Being new to React, it's challenging to pinpoint the issue. https:// ...

The error message "Cannot find property 'X' on type 'number' in React TypeScript" is appearing

When iterating over the list of brands, I am facing an issue where the brand properties are not loading properly. During this time, the indexed array is displayed as a skeleton structure. While JavaScript handles this situation well, TypeScript encounter ...

Despite including the bearer token in the Axios request, it still comes back as unauthorized

When using axios in my react app to make REST API requests, I encounter a 401 error code when including the Authorization header. How can I resolve this issue? Below is the snippet of my code: import Axios from "axios"; import { BASE_URL } from ...

Positioning background images in Bootstrap CSS with fixed position

Currently, I am developing a website using bootstrap, HTML, and CSS. The structure of the HTML code is as follows: wrapper for fixed footer at bottom { content fixed bg content } The overall wrapper has relative positioning. The fixed background is ...

Perfecting the CSS Flip Animation

My latest project involves creating a flip effect using CSS, and I need some assistance. You can check out my fiddle link here: https://jsfiddle.net/Munja/db11mmut/ The issue I am facing is that the back side of the element remains hidden until the front ...

Unattractive mobile modal

Hey there, This is how my .modal CSS code appears: .modal { position: fixed; top: 10%; left: 50%; z-index: 1050; width: 560px; margin-left: -280px; background-color: #fff; border: 1px solid #999; border: 1px solid rgba ...

The placement of an object on a webpage

Seeking the (x,y) coordinates of an element using JavaScript, utilizing the offset property from jQuery. Here is my code snippet: var offsets = $('#11a').offset(); var top = offsets.top; var left = offsets.left; console.log("Coor ...

Issue with loading CSS in Magento transactional emails

I designed a custom email template specifically for order cancelations. The email is functioning properly, with the header and footer displaying correctly. However, the existing CSS is not being applied to the email template. While default headers and fo ...

When working with a React component, utilize the array.filter() method to filter elements without expecting a return value. In cases where no elements match the filter criteria, an empty

Running into a dilemma with a React function component that involves destructuring a name parameter using useParams to specify the array of dog objects being passed in as props. Despite confirming the successful passing of the dogs array and the correct d ...

The responsive navigation menu expands

Struggling with my responsive menu issue here. I must admit, I am not a coding expert by any means, but I've been tasked with web design responsibilities at work. The problem at hand is that the website isn't fully responsive, except for the "ar ...

Encountered an error while attempting to execute the command npx create react app: spawn UNKNOWN error occurred

After attempting to execute a basic npx create-react-app, an unexpected error occurred: D:\>npx create-react-app abc npx: installed 67 in 4.255s Creating a new React app in D:\abc. Installing packages. This might take a couple of minutes. In ...

Dynamic elements cannot be referenced by jQuery

I am looking to apply a class to dynamically added content upon the successful execution of $(ajax). In an external Javascript file included at the beginning of the page and with all code executed within document.ready(), I have the following function tha ...

React build - error: Unable to locate the 'buffer' module

When attempting to build my application in React, I encountered an error that only appeared during the build process. Strangely, restarting the development server also triggered the same error. It seems like a recent change I made is causing this issue, as ...

Is there a method to send a function through a remix loader function?

I'm currently attempting to pass a function as one of the values from a remix route loader function export const loader: LoaderFunction = async ({ request }) => { const userId = await requireUserId(request) const user = await getUserById(userId ...

Centering the date vertically in JQuery Datepicker

I'm currently customizing the appearance of the jQuery datepicker, but I'm facing difficulty in aligning the dates vertically at the center. Here's the progress I've made so far: https://jsfiddle.net/L4vrkpmc/1/ Since the datepicker i ...

Is it necessary to save the user's sign-in status in Local Storage in order to render the component (using React, Next.js, and Firebase Authentication)?

(Implementing Google Signin with Firebase and React(Next)) When a user signs in, the state is set to true. The home component and login component are rendered in index.js based on the state value. Initially, I stored this state in local storage, but I rea ...

"Aligning Text in the Middle of the Navigation Bar with

I am attempting to align the text in this scenario, but I am encountering difficulties. <div class="col-md-10"> <br> <br> <div class="navbar navbar-default"> <div class="container"> <p style="font-size: ...