Personalized CSS Checkbox featuring text within

I am currently working on developing a custom CSS design for checkboxes to match the specifications provided by the designer. The checkboxes need to be circular with a radius of 60px, and the label should be centered within the circle. Additionally, when the checkbox is checked, the background color should change to red.

Here is the progress I have made so far: http://codepen.io/anon/pen/qdrQbV

Below is the code :

HTML

<div class="mybox">
  <input type="checkbox" value="None" id="sth" name="check" checked />
  <label for="sth">
    <span>
      Test
    </span>
  </label>
</div>

CSS

.mybox {
  width: 120px;
  position: relative;
  margin: 0;
  padding:0;
  label {
    color: #000;
    width: 120px;
    height: 120px;
    padding:0;
    cursor: pointer;
    position: absolute;
    top: 0;
    left: 0;
    text-align: center;
    line-height: 120px;
    border-radius: 50%;
   border: 2px solid black;
    &:after {
      box-sizing: border-box;

      content: '';
      width: 120px;
      height: 120px;
      position: absolute;
      top: 0px;
      left: 0px;
      border: 2px solid red;
      background: red;
      opacity: 0;
      border-radius: 50%
    }


  }
  input[type=checkbox] {
    visibility: hidden;
    &:checked + label:after {
      opacity: 1;
    }    
  }
}

The current outcome is close to meeting expectations, but there is an issue with the caption being obscured by the red overlay. I am seeking suggestions to resolve this problem.

Any insights or ideas would be greatly appreciated! Thank you!

Answer №1

One easy solution is to include the following CSS rule for your after-element: z-index: -1

Answer №2

Make sure to review this piece of code

.mybox {
  width: 120px;
  position: relative;
  margin: 0;
  padding: 0;
}
.mybox label {
  color: #000;
  width: 120px;
  height: 120px;
  padding: 0;
  cursor: pointer;
  position: absolute;
  top: 0;
  left: 0;
  text-align: center;
  line-height: 120px;
  border-radius: 50%;
  border: 2px solid black;
}
.mybox label:after {
  box-sizing: border-box;
  content: '';
  width: 120px;
  height: 120px;
  position: absolute;
  top: 0px;
  left: 0px;
  border: 2px solid red;
  background: red;
  opacity: 0;
  border-radius: 50%;
}
.mybox label span {
  position: relative;
  z-index: 9;
}
.mybox input[type=checkbox] {
  visibility: hidden;
}
.mybox input[type=checkbox]:checked + label:after {
  opacity: 1;
}
    <div class="mybox">
      <input type="checkbox" value="None" id="sth" name="check" checked />
      <label for="sth">
        <span>
          Test
        </span>
      </label>
    </div>

simply insert

position: relative;
      z-index: 9;
for the span element within the 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

Changing position with flair in CSS

Is there a way to create a transition effect on an element when it changes position from static to fixed? I attempted using the code: transition: position 2s linear;, however, it does not seem to have any impact. Are there any other methods I could experi ...

How can I select the HTML element that precedes a specific class?

When scraping data, I am facing a challenge in extracting the element of the “th” tag that precedes another “th” element with the "type2" class. My preference is to locate this element by identifying it as the “th” before the one with the class ...

Angularjs orderBy filter causing deletion of incorrect row

When creating a table with AngularJS, I utilized the orderBy filter. However, after implementing this filter, my delete function started removing rows unexpectedly without me clicking to delete. Below is the code for the filter: <tr class = "table-row ...

Automatically resize and vertically align a centrally positioned div in a designated container

I have a div container that is centered in the middle of another container. I managed to adjust it for one slide, but the issue arises when I create multiple .html files using the same css file - the height of the container does not meet my expectations. I ...

Having difficulty uploading custom 3D model with three.js

After spending two full days attempting to follow tutorials on how to load my own 3D model using JavaScript, I'm still unable to get the model to display in my browser. Everything appears to be set up correctly from my perspective, yet nothing is show ...

Displaying a webpage in JavaFX Scene Builder

Is it possible to display a webpage or an HTML file using JavaFX Scene Builder? Thank you. ...

Is it possible to dynamically change the recipient of a mailto: link using HTML and JavaScript based on the URL used to visit the website?

I manage multiple websites that share a common privacy policy page. I wish to dynamically change the email address based on which site the user is accessing it from. For instance, if a user visits the privacy page from Site A and clicks on [email pro ...

Is there a way to showcase SVG and PNG images retrieved from a database simultaneously?

I've encountered an issue with displaying images from the database. While png images are showing up correctly, the svg images don't seem to display at all. public ActionResult GetImage() { // some code here return new FileContentResult(im ...

Various iFrame placements

Is there a way to divide a webpage into sections using iFrames and position them similar to the arrangement shown in this image: ? Each "box" would contain a scrollable iFrame, such as a list of "Genres" in the top-left pane, followed by a list of "Compo ...

Is there a way to ensure that the column widths in the Huxtable RTF output align perfectly with the widths of the HTML

It appears that the HTML output in huxtable has a column width setting that automatically adjusts to fit the content, creating an aesthetically pleasing output. On the other hand, the RTF output makes all columns equal width, which is not as visually appea ...

Partial postback support for numerical values in animations

Recently, I incorporated an animation into a design: .map > img:hover { -webkit-animation-name: MapFloatingChrome; -webkit-animation-duration: 3s; -webkit-animation-iteration-count: infinite; ... to {-moz-tra ...

problem concerning php table

I am currently in the process of developing a PHP script to generate a table from data stored in a MySQL database, based on the checkboxes selected by the user. However, I have encountered an issue where if certain checkboxes are left unchecked before othe ...

Hiding the author, category, and date information from displaying on WordPress posts

After creating a Wordpress blog site and adding the category widget to the right sidebar as a drop down, I realized that I needed to customize its layout in terms of colors and design. However, I am struggling to find out how it can be done, which .php fil ...

Optimizing the use of .less files in an expansive angularjs application

Currently, I am in the process of developing a large-scale application using AngularJS as a Single Page App. All the html files have been organized under the Views folder as shown here. Views Sample sample.html sampleheader.html ...

Error: CSS and JavaScript files cannot be found

Currently working with an Orchard Asp.net MVC 3 Project. Upon examining the source code in the browser, I notice all the JS and CSS files being referenced/imported. However, clicking on the URL for certain JS files located in the MediaLibrary or Modules f ...

The mobile version of the page has extra white space at the bottom

I have a responsive design that is working well, but I am experiencing an issue on mobile devices where there is white space at the bottom of the page. * { margin: 0; padding: 0; box-sizing: border-box; } html { scroll-behavior: smooth; ...

XML and XSL transformation are two key components in the world

When working with my code, I encountered an issue where I needed to convert the month number into a month name and add AM/PM to the start time. The code that I used did not work as expected. XSL Content enter code here <?xml version="1.0" encoding="UTF ...

Incorporating a divider into a Material-UI MenuItem causes an additional border

I needed a way to separate the MUI MenuItem using a divider, but it resulted in an extra border around the item where the divider was placed. The highlighted section in the image shows the item that has the divider= true setting and the extra border. Is th ...

The Div ID is built utilizing attributes inherited from the preceding element

I'm encountering an issue where I've defined rollover buttons and div ids to manipulate my image positions. However, when I create a new div called Text and add content to it, the rollover buttons also seem to activate? It's as if the code f ...

No animated scrolling occurring

I have been struggling with this problem for a while now and despite having gone through 100 questions, I still can't find a solution as to why my code snippet is failing. Here is the jQuery code I am using: $("#readmore").click(function(event){ ...