How can I transform this checkbox HTML structure into a slider using only CSS?

Hello everyone, this is my first time posting on stackoverflow ;)

Recently, I started using a WordPress plugin called "WooCommerce TM Extra Product Options". I noticed that when I create options for any WooCommerce product with checkboxes, the plugin generates HTML code like the example below (with default checkbox appearance):

<label for="tmcp_choice_0_0_1_1519167210">
<input class="tmcp-field ingredientepizza tmhexcolor_0_0_1_1519167210 tm-epo-field tmcp-checkbox" name="tmcp_checkbox_0_0_1519167210" data-limit="" data-exactlimit="" data-minimumlimit="" data-image="" data-imagec="" data-imagep="" data-imagel="" data-image-variations="[]" data-price="" data-rules="[&quot;&quot;]" data-original-rules="[&quot;&quot;]" data-rulestype="[&quot;&quot;]" value=" molho de tomate_0" id="tmcp_choice_0_0_1_1519167210" tabindex="1" type="checkbox" checked="checked">
<span for="tmcp_choice_0_0_1_1519167210"></span><span class="tc-label tm-label"> molho de tomate</span></label>

I am wondering if there is a way to adjust the CSS code in this CodePen (https://codepen.io/macbobbitt_/pen/BjepPG) to work specifically with the above HTML structure since I cannot modify it myself.

Thank you in advance for any assistance provided.

Answer №1

be sure to assign a classname instead of directly applying it globally

$(function() {
$("input[type='checkbox']").change(function() {
   if ($(this).is(":checked")) {
     $(this).parent().addClass("active");
   } else {
     $(this).parent().removeClass("active");
   }
})
  
});
/* for the lazy */
@import url(https://fonts.googleapis.com/css?family=Sanchez);

*,
*::before,
*::after {
  transition: 400ms all ease-in-out 50ms;
  box-sizing: border-box;
  backface-visibility: hidden;
}


html,body{ font-family: 'Sanchez', serif;}

input[type="checkbox"] {
  display: none;
}

/*Button is :CHECKED*/

.toggle-container.active {
  background: rgba(73,168,68,1);
  box-shadow: 0 0 2px rgba(73,168,68,1);
}

.toggle-container.active span:not(.tc-label) {
  left: 110px;
  transform: rotate(360deg);
}


/*shared*/

label,
span:not(.tc-label) {
  border-radius: 50px;
}


/*'un':checked state*/

label {
  height: 100px;
  width: 200px;
  background: rgba(43, 43, 43, 1);
  position: relative;
  display: block;
  box-shadow: 0 0 2px rgba(43,43,43,1);
  text-align: center;
}
label .tc-label {
  bottom: -40px;
  position: absolute;
  width: 100%;
  left: 0%;
}

span:not(.tc-label) {
  height: 80px;
  width: 80px;
  background: rgba(255, 255, 255, 1);
  position: absolute;
  top: 10px;
  left: 10px;
  cursor: pointer;
}

span:not(.tc-label)::before {
  content: '';
  height: 60px;
  width: 5px;
  position: absolute;
  top: calc(50% - 30px);
  left: calc(50% - 2.5px);
  transform: rotate(45deg);
}

span:not(.tc-label)::after {
  content: '';
  height: 5px;
  width: 60px;
  position: absolute;
  top: calc(50% - 2.5px);
  left: calc(50% - 30px);
  transform: rotate(45deg);
}

span:not(.tc-label)::before,
span:not(.tc-label)::after{
  background: rgba(43,43,43,1);
  border-radius: 5px;
}

/* pesduo class on toggle */

.toggle-container.active span:not(.tc-label)::before{
  height: 50px;
  top: calc(55% - 25px);
  background: rgba(73,168,68,1);
}
.toggle-container.active span:not(.tc-label)::after{
  width: 20px;
  top: calc(95% - 25px);
  background: rgba(73,168,68,1);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


        <label for="tmcp_choice_0_0_1_1519167210" class="toggle-container">
        <input class="tmcp-field ingredientepizza tmhexcolor_0_0_1_1519167210 tm-epo-field tmcp-checkbox" name="tmcp_checkbox_0_0_1519167210" data-limit="" data-exactlimit="" data-minimumlimit="" data-image="" data-imagec="" data-imagep="" data-imagel="" data-image-variations="[]" data-price="" data-rules="[&quot;&quot;]" data-original-rules="[&quot;&quot;]" data-rulestype="[&quot;&quot;]" value=" molho de tomate_0" id="tmcp_choice_0_0_1_1519167210" tabindex="1" type="checkbox" checked="checked">
    <span for="tmcp_choice_0_0_1_1519167210"></span><span class="tc-label tm-label"> molho de tomate</span></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

Creating an image border for various sizes of an HTML div using CSS and JavaScript code

I am in the process of developing an HTML5/Javascript game that will be compatible with modern browsers. The game will feature dialog boxes, or modal popups, which will have borders made up of images such as vertical, horizontal, and corner pieces. These p ...

Using Python and Selenium to interact with HTML tags within a table

Here is a table structure that I am working with:- <table> <tbody> <tr class="stripe"> <td colspan="3"/> </tr> <tr> <td style="width: 160px;">Field1:</td> <td style="wi ...

How do I hide a dropdown menu when the selector's value changes in iOS6?

I'm currently developing a hybrid application using Worklight. When I tap on a select control, a native dropdown appears. However, when I choose an option and the onchange event is triggered, the dropdown doesn't disappear unless I tap on the do ...

Is there a way to stop ng-repeat in AngularJS 1.2 from encoding or escaping my content, or do I have to create my own directive for this?

Is there a way to stop ng-repeat in AngularJS 1.2 from encoding or escaping my content without creating a custom directive? I know that ng-bind-html-unsafe is no longer supported in Angular 1.2, but I'm unsure about its compatibility with ng-repeat. S ...

What is the best way to denote multiple line breaks in HTML code?

When creating blank lines on my webpage, I typically use the code <br />. However, inserting 20 - 40 of these can be quite cumbersome as each br tag is placed on a separate line after formatting. Is there a more elegant way to achieve the same effe ...

Issues with embedding iframes and hyperlinks

Simply put, we have a webpage containing an iframe, and I need to dynamically target the page URL. To keep it clear, our main page is located at . The iframe resides on the 3.aspx page and directs to a completely different URL, let's say . I am aimi ...

Tips for resolving the Bootstrap 4 carousel glitch

Hello, I am currently working on implementing a multi-item Carousel that moves one item at a time with each click. However, in my case, clicking the right arrow results in the entire slide changing. To help you understand better, I have provided a link to ...

Height of dropdown items in the horizontal navbar

I am working on a navbar that includes a dropdown menu. Currently, the dropdown items are being displayed horizontally in full width with a larger height. However, I would like them to be displayed vertically in full width and with a smaller, normal height ...

Create a stylish layout by utilizing the power of CSS and P tags to

I want to create columns using a p tag. Since the content is being generated by a content manager, it's wrapped inside a box within a p element. I'm unable to add multiple divs for creating columns; as mentioned earlier, the content is placed in ...

What is the method for inserting the document URL into a text input?

Can someone provide guidance on grabbing the top URL and inserting it into a text input field? I've tried the following method, but it's not working. Any suggestions or ideas? Additionally, is there a way to make this text input field uneditable? ...

A step-by-step guide on deleting an element within a div using jQuery

I am attempting to delete an HTML element using JQuery like this $('#' + divId + ' .settings_class').remove('.print_settings'); This code does not result in an error or remove the specified html element, however, the selecto ...

Separate a string into substrings based on the number of spaces it contains

My goal is to split a string into multiple parts based on spaces, resulting in an array with 3 values. For instance, if I have the string "SIZZLING STEAK TERIYAKI BOY" and divide it into 3 parts, the output should be ["SIZZLING STEAK", "TERIYAKI", "BOY"]; ...

Hide the mobile menu after an option is clicked

I managed to implement a mobile menu on my single-page website by utilizing code I found online. Currently, the menu only opens or closes when the main navigation bar is selected due to the JavaScript I have integrated. Is it feasible for the menu to autom ...

Error 404 occurs when images are not able to load when stored in a different directory

When I encounter a custom 404 Error on my website at http://ericmuir.tk and it happens in a directory other than the home one, none of the images on the page load. I faced a similar issue with loading CSS scripts, but resolved it by using style tags which ...

A technique to execute multiple Ajax calls simultaneously without having to wait for each one to finish in an onClick event

<html> <head></head> <body> <button onclick="ajaxcall()">Run the function</button> </body> <script> function ajaxcall() { $.ajax({ url: 'insertdata.php', ...

Is there a way to confirm when all 3 html pages (panes) have been completely refreshed?

I have a webpage with 4 panes, each implemented as separate HTML pages. The last pane needs to perform an action when the previous 3 panes are refreshed. For instance, while the first 3 panes are refreshing, the last pane should display a "LOADING" message ...

Problem with showing div when hovering

I'm having trouble displaying a div on hover. When I hover over the div element A, the div element B appears as expected. However, when the mouse pointer leaves the div element A, the div element B does not disappear. $('.display_cal'). ...

Bootstrap 4: Inline Button with Full Width Styling

Although the title may seem misleading, I struggled to come up with a better one. What I need is to have an image aligned with text within a div, and a button below that text. However, I'm facing difficulty in making the button take up the full width ...

What is the best way to include a permanent placeholder within an input field?

I'm trying to insert a font icon inside an input field using the following method: <input type="text" name="your name" placeholder="&#xe00b; YOUR NAME" style="font-family:Flaticon" class="restrict"> Currently, the font icon &#xe00b; is ...

Having trouble verifying the selection option in Angular 6

I've been trying to implement Select option validation in Angular 6, but neither Aria-required nor required seem to be effective. The requirement is for it to display a message or show a RED border similar to HTML forms. Here's the HTML snippet ...