Don't conceal the :after and :before elements when using CSS custom checkboxes

I have created my own custom checkboxes using this CSS code:

input[type="checkbox"]{
  display: none;
}
.checkbox{
  position: relative;
  width: 60px;
  height: 19px;
  background-color: green;
  border-radius: 10px;
}

.checkbox input[type="checkbox"] + label{
  left: 0%;
  top: 0px;
  cursor: pointer;
  position: absolute; /*otherwise ,,left: x px;" isn't working*/
  display: block;
  width: 30px;
  height: 19px;
  border-radius: 100%;
  background-color: red;
  box-shadow: 0px 0px 3px 2px red;

  -webkit-transition: all .5s ease;
  -moz-transition: all .5s ease;
  -o-transition: all .5s ease;
  -ms-transition: all .5s ease;
   transition: all .5s ease;
}

.checkbox input[type="checkbox"]:checked + label{
   left: 50%;
   z-index: 1;
   background-color: blue;
   box-shadow: 0px 0px 3px 2px green;
}
.checkbox input[type="checkbox"]:checked + label:before{
   content: "\2714";
   position: absolute;
   left: 8px;
   color: white;
}

.checkbox input[type="checkbox"] + label:before{
  content: "\2718";
  position: absolute;
  left: 8px;
  color: white;
}

.checkbox:before{
  position: absolute;
  left: 5px;
  content: "Yes";
  color: white;
}

.checkbox:after{
  position: absolute;
  left: 35px;
  content: "No";
  color: white;
}

To see the result, I uploaded it to CSS Desk: CSSDesk: Decorative checkboxes. In another project, however, when trying to disable buttons with my custom checkboxes CSS Desk: 3D Buttons, there was an issue. The checkbox did not properly hide the :after/:before elements as expected. Even after enabling all buttons, the "s" from "Yes" remained visible next to "No". I suspect a font size change but am unsure how to confirm and rectify it. The only alteration made to the .checkbox div is adding display: inline-block; in order to display the checkbox alongside the buttons:

<div class="checkbox" style="display: inline-block;">
  <input id="disableInfo" type="checkbox">
  <label for="disableInfo"></label>
</div>disable info buttons
 <br/><br/><br/><br/>

If anyone can offer assistance on resolving this issue, I would greatly appreciate it. Thank you.

Answer №1

The default font-family in the first example is set to serif. However, in the second example, it has been changed to sans-serif by some styles from the page. You may need to identify which styles are causing interference or manually change it back to serif.


It's important to note that questions like "Here's my code, what did I do wrong?" may not be suitable for SO.

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 animating elements to move on scroll while navigating through the webpage

I came across a fascinating website that has a unique scrolling effect. As you scroll down the page, only the elements and images move while the page itself remains static, creating an interesting visual effect. I tried to replicate this on my own websit ...

Utilize CSS Animation to bring overlapped images to life

Trying to replicate the animation featured on the CISO website header. I have created a JSFiddle demo showcasing my attempt, but it seems like something is not quite right. img { transition: all .3s ease; overflow: hidden ...

Summon the keyboard to appear

How do I make the keyboard appear on my website? I have a javascript function that recognizes keyboard input, but I am struggling to display the keyboard on my mobile device. Is there a way to simulate traditional input and generate key events? I should ...

The state of XMLHttpRequest always remains in a perpetual state of progress, never

I have come across an MVC Core application. One of the methods in this application currently has the following structure: public IActionResult Call(string call) { Response.ContentType = "text/plain"; return Ok(call); } In addi ...

Is there a way to perfectly center text both vertically and horizontally to the right side of an image?

I'm working on developing a mobile website using jQuery Mobile and I want to include images in my "collapsible" elements. Here is the code I am using: <div data-role="collapsible" data-collapsed="true"> <h3><img src="image ...

Switching over to a stored procedure

I have been using a query string for the jQuery Autocomplete plugin, but I think it would be better to switch to a stored procedure. However, when I tried to do so, it didn't work. Can anyone provide guidance on how to convert my code? Original ASHX ...

Resolving Problems with Ion-Split-pane in the Latest Versions of Angular and Ionic

There seems to be a perplexing issue with the ion-split-pane element that I just can't wrap my head around. Once I remove the split-pane element, the router-outlet functions perfectly fine. The navigation is displayed after a successful login. The on ...

Show the json data on a PHP table

I've been attempting to showcase JSON content in a PHP table, but I keep encountering errors. It seems like there are some syntax issues that I can't quite pinpoint. Any suggestions on what needs to be modified? PS. I'm using the Slim frame ...

A HTML table featuring a horizontal scroll and cells with a fixed width for optimal visibility

Seeking assistance with creating an HTML table with a horizontal scroll and fixed cell width. I have managed to implement the horizontal scroll feature using the code below, but struggling to adjust the cell widths. Any tips or suggestions would be greatly ...

What could be causing my Bootstrap navbar menu item to move to the line beneath it when there is centered text?

I've implemented a basic Bootstrap navbar from the example provided on the Bootstrap website at . However, when I tried to add custom text to the center of the navbar, it caused the "Contact Us" menu item to break onto two lines instead of staying on ...

Generating a JavaScript variable linked to a Rails Active Record relationship

I'm trying to implement an active record association in the DOM, but I'm encountering some difficulties. Here is my editor class: .editing .row .col-sm-3 .col-sm-8 .text-left #font-20 .title-font . ...

Include a search button within the search box of the Custom Search Engine

Can anyone help me with adding a search button to my HTML code? I've tried implementing it, but when I try to search something on a website like YouTube, the results show up without displaying my search query. How can I fix this issue and what changes ...

JavaScript script to modify the parameter 'top' upon clicking

Here is the pen I've made. HTML <div class = 'cc'> <div class = 'bb'><div class = 'aa'> Some word </div></div> </div> CSS .cc { width: 100%; min-height: 90px; margin: 0; ...

Laravel issues with displaying data in a 'foreach' loop

I encountered a quirky issue while working with Laravel 5.2. I have a chunk of text that I'm attempting to display using some explode functions. The strange part is, Laravel is rendering it oddly by adding incorrect ':' before the end of the ...

What's up with portable devices requiring two taps to hover over one DIV and affect another DIV?

Upon implementing "hover one DIV - affecting another inner DIV," a strange issue arose on iPad/iPhones where it now requires two taps to click on the link within the DIV with the hover effect: Below is the HTML code: <div class="portfblock"> &l ...

In search of advice on the best web-based database management technology

I'm looking to create a prototype for a web-based database manager, similar to the desktop version in the image below, with specific features in mind. Initially, the schema will be provided through a flat file. Considering HTML5 as an option, I am a ...

Steps for modifying a cell within a table using a button click

Hello, I am currently working on a project where I want to display a specific div portion when a user clicks on an image icon within a table. However, I am encountering an issue with the JavaScript code as it only shows the div portion in the first row and ...

Creating dynamic checkboxes in Angular4 and binding them to an array of IDs

Hey there developers, I've been encountering an issue while trying to bind my dynamically generated checkboxes to an array in my project. In my users.template.html file, I have the following code snippet: <div *ngFor="let r of roles" class="checkb ...

How can I position my navbar above my background image using Bootstrap?

I am a newcomer to using bootstrap and I am attempting to create the following design: https://i.sstatic.net/EV9A1.png In the design, the navbar is situated on top of the background image. However, with my current setup, this is what I have: <!DOCTYPE ...

What's the best way to trigger an alert popup after calling another function?

Here are some HTML codes I've been working with: <button id="hide" onclick="hide()">Hide</button> <p id="pb">This paragraph has minimal content.</p> My goal is to have the paragraph hide first when the button is clicked, foll ...