Removing the tick mark from a simulated checkbox

I'm looking for guidance on updating this code to manage unchecking an emulated checkbox.

Let's start with the original input HTML:

<input type="radio" name="rf538" id="rf538" class="page_checkbox">

Next, here is the CSS for the class page_checkbox:

.page_checkbox {
   display: none;
}

Following the input HTML, we have:

<label for="rf538"><span></span>Pleasures</label>

Here's the CSS for the span inside the label:

.page_checkbox+label span {
    display: inline-block;
    width: 18px;
    height: 18px;
    margin: -2px 8px 0px 0px;
    background-color: #ffffff;
    vertical-align: middle;
    cursor: pointer;
    border-radius: 1px;
}

Finally, here is the CSS that styles the checkbox and check:

.page_checkbox:checked+label span:before {
    position: relative;
    left: 3px;
    top: 2px;
    content: '\002714';
    color: #f06000;
    font: 16px/16px Arial, Helvetica, Sans-serif;
}

While there is a CSS style for the checked state, I'm unsure how to handle unchecking the checked span box. Is JavaScript necessary for this functionality?

Answer №1

To solve the issue of not being able to uncheck a radio button without JavaScript or a reset button, consider changing the radio button to a checkbox. By making this simple switch, you will be able to achieve the desired functionality.

.page_checkbox {
  display: none;
}

.page_checkbox+label span {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin: -2px 8px 0px 0px;
  background-color: #ffffff;
  vertical-align: middle;
  cursor: pointer;
  border-radius: 1px;
}

.page_checkbox:checked+label span:before {
  position: relative;
  left: 3px;
  top: 2px;
  content: '\002714';
  color: #f06000;
  font: 16px/16px Arial, Helvetica, Sans-serif;
}
<input type="checkbox" name="rf538" id="rf538" class="page_checkbox">
<label for="rf538"><span></span>Pleasures</label>

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

a pair of browser windows displaying a web application built with ASP.NET MVC

We are currently in the process of developing an ASP.NET MVC web application for internal use within our organization. Our users' productivity can greatly benefit from having a larger screen space, which is why we have decided to provide each user wit ...

CSS confusion: What's causing the header to not align horizontally and the footer to not justify evenly spaced?

I am new to coding and experimenting with CSS flexbox to design a responsive layout. I am struggling with aligning the header elements horizontally in the widest viewport and adjusting the footer to space out evenly. For the header, I attempted using disp ...

What is the best way to change CSS style for a button when clicked using JavaScript?

Is there a way to switch the background style of a CSS div when clicking the same button? function changeBg() { var divElem = document.getElementById("change-bg"); if (divElem.style.backgroundColor === "yellow") { divElem.style.backgroundColor ...

Tips for displaying the message "{"POWER":"ON"}" within the else if statement (this.responseText == ({"POWER":"ON"})) {

Hey everyone, I'm trying to adjust the color of a button on my webpage based on the response I receive from this.responseText. I understand the JSON response, but for some reason, I can't seem to incorporate it into my code. If anyone could lend ...

Transform HTML or formatted text from an iPhone 4 Notes backup SQLite file into plain text

I was looking to recover some missing notes from an iTunes backup of an iPhone 4 by accessing the notes.sqlite file. After querying the table that stores the note text: select zcontent from znotebody I found that the text is in HTML format. Is there a wa ...

Opening a Material UI dialog results in a change in the style of other components

Whenever I open the Dialog component from a button on the AppBar component, the margin on my navbar elements changes unexpectedly. I have checked the HTML using dev tools and there are no CSS changes on either of the components. Any suggestions on how to p ...

Ways to differentiate between buttons in a button cluster?

I have created a set of 3 buttons using the code from this resource. However, the buttons are currently positioned vertically close to each other as shown in the source code. I would like to adjust the spacing between them. Is there a way to achieve this ...

Arranging Bootstrap columns based on click action

How can I rearrange the order of columns using bootstrap and jQuery when clicked? I've tried to implement this functionality for the left button, but it doesn't seem to be working as expected: $("#left").on("click", function() { ...

What is the best method to assign a CSS class to specific nodes within a TreeView using CodeBehind?

I need to apply unique styling to certain nodes in the codebehind. Within my TreeView, parents have two categories of children. One category matches the parent type (e.g. organizationalUnit), while the other does not (e.g. organizationalMembers). I aim t ...

What are the steps to create a CSS grid like this?

Any suggestions on how to create a grid template similar to the image shown in this picture? I am looking to achieve this design without rounded borders and without any gaps between the elements. ...

JavaScript Magic: Hide Div when Clicking Away

I need a solution where clicking outside of the My DIV with the ID Container_ID will hide all elements within the Container by setting their style to display: none;. Currently, the JavaScript code I am using partially achieves this functionality, but it al ...

HTML Automated Email

I am currently working on developing a WIFI landing page that requires users to input their email address in a textbox. Upon clicking 'Connect', the entered email address will be sent to another designated email for review. While I have found co ...

Troubleshooting media queries on an example webpage

Hey there! So, I'm having a bit of trouble with running media queries on a simple HTML page. It's been a while since I worked on this stuff, and I feel like I must be doing something silly that I can't quite pinpoint. If you want to take a ...

How can I move one of the multiple input fields to the top right side?

I am facing an issue and need some assistance. I have created a page with multiple font controls, but in my prototype design, there is a field on the right side where the inputs are positioned at the top and on the right. How can I achieve this? I have cr ...

Loading AJAX content within the existing page instead of a pop-up window

My goal is to have the page links load in a popup, but after adding this script, the page loads at the bottom instead. How can I make it open in a popup window instead? $('a[rel="ajax:jmodal"]').click(function(event) { $.ajax({ url: $(this).a ...

Align columns to the right and left using Bootstrap

It should be simple enough, but I can't seem to find my mistake. Goal: The entire markup should be centered with a width of col-10. Within the same 10-column width, there should be two divs each taking up 50% of the space. Using Bootstrap 5, for so ...

Having trouble getting PostCSS nesting to work with CSS variables in Tailwind CSS and Next.js?

I've been attempting to utilize PostCSS nesting alongside CSS variables, but unfortunately the CSS variables are not being converted at all. Instead, I am seeing Invalid property value in the DOM for CSS Variables. The tailwind.css file I have inclu ...

Django causing issues with displaying Bootstrap modal on website

I am having issues with implementing a Bootstrap modal in my Django template. I followed an example from the Bootstrap website to create a button that triggers a modal, but when I click the button, nothing happens. There are no errors displayed in the co ...

Tips for creating a dynamic id for the <li> element

I am working on a div that contains UL and LI elements. I want to dynamically generate IDs for these LI elements, instead of using static HTML like this: <li id= "nav-fragment-1"> <li id= "nav-fragment-2"> <li id= "nav-fragment-3"> <l ...

Trigger a function when clicking outside the element, similar to how a Bootstrap modal is closed

I have successfully created a popup box using angular in my project. It appears when I click on an icon and disappears when I click on the close button. However, I would like it to also close if someone clicks outside of the popup. Can anyone help me with ...