Customizing Checkbox using CSS (additional assistance required)

I am currently working on implementing Checkbox Four with a custom design. You can check out the example I found on this website:

My goal is to enhance this checkbox by incorporating red colored text 'N' when it's unchecked, and blue colored text 'Y' when it's checked.

Here's the code snippet that I've put together so far:

input[type=checkbox] 
{
    visibility: hidden;
} 


.checkboxFour 
{
    width: 40px;
    height: 40px;
    background: #ddd;
    margin: -30px 160px;

    border-radius: 100%;
    position: relative;
    -webkit-box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
    -moz-box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
    box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}

.checkboxFour label 
{
    display: block;
    width: 30px;
    height: 30px;
    border-radius: 100px;

    -webkit-transition: all .5s ease;
    -moz-transition: all .5s ease;
    -o-transition: all .5s ease;
    -ms-transition: all .5s ease;
    transition: all .5s ease;
    cursor: pointer;
    position: absolute;
    top: 5px;
    left: 5px;
    z-index: 1;

    background: #333;

    -webkit-box-shadow:inset 0px 1px 3px rgba(0,0,0,0.5);
    -moz-box-shadow:inset 0px 1px 3px rgba(0,0,0,0.5);
    box-shadow:inset 0px 1px 3px rgba(0,0,0,0.5);
}

.checkboxFour input[type=checkbox]:checked + label {
    background: #CC0000;
}

Answer №1

If you want to achieve this effect using psuedo-elements, you can try something like the following:

.checkboxFour label:before {
    content: 'N';
    color: red;
    display: block;
    padding: 5px;
    text-align: center;
}

.checkboxFour input[type="checkbox"]:checked + label:before {
    content: 'Y';
    color: blue;
}

Check out this JSFiddle link for an example.

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

What could be causing the CSS to not display properly on specific routes?

I'm facing an issue where CSS seems to be working fine for certain routes with node.js & express, but not for others. It's puzzling because the HTML file links to the same CSS file in both cases. For instance, CSS works perfectly for the route " ...

"Is there a way to extract text enclosed within HTML tags, such as <div>text</div>, with Selenium using C#

How can I extract the text 'True' from within the HTML tags <div>text</div> using Selenium and C#? <div type='data' id='OfferInCart' style='display:none;'>True</div> I have attempted to retr ...

accordion menu: stuck in my list like a trapped diver due to the overflow

I need assistance with creating a side menu. Here is the current code I have: function opensubmenus() { $('#submenus').css("display", "block"); } #menus { overflow-y: scroll; width: 150px; background-color: blue; } #submenus { backgr ...

Tips on sending parameters from a PHP script to a Javascript file

I am struggling with my new journey into the world of JavaScript. I have been attempting to pass a parameter from a PHP file to a JavaScript file, but for some reason, it's just not working. Here's the code snippet: The JavaScript file is named ...

Utilizing Dojo widgets in Xpages

I'm having trouble applying CSS to certain dojo elements within my Xpage. Here is the CSS style sheet I am using: .formFields { color: rgb(5, 56, 107); font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-variant: nor ...

Add a new row to the table when a dropdown option is selected, and remove the row when deleted. Ensure that the row is only added

Here is my specific requirement: I need a table with a default row containing a dropdown menu in the first column. When an option is selected from the dropdown, a new table row should be added with the same content as the main row and a delete button for ...

What is the simplest method for finding the position of a child element in relation to its parent?

My HTML markup is structured similarly to this: <div id="parentElement"> <div class="child"></div> <div class="child"></div> <div class="child"></div> <div class="child"></div> </div ...

"Content in DIV just peeking out from the edge of

After coming across a helpful piece of HTML and jQuery code in response to another question, I've been using it successfully with one small issue. The code allows divs to show and hide, which works perfectly unless the div is positioned near the bott ...

Can a border-bottom be made the same size as a class it is not linked to in CSS?

Can I set a border-bottom to match the size of a separate class? For example, I want a border-bottom at the bottom of each <section> tag. However, since the sections span the full width of the screen, the border-bottom inherits that width. Each < ...

Error message appears when attempting to duplicate vertices in a THREE.Geometry object: 'Vector is not defined'

I am attempting to dynamically add new faces to a mesh, but I keep encountering a console warning: THREE.BufferAttribute.copyVector3sArray(): vector is undefined Despite the warning, this example successfully generates a single triangle that is a repli ...

Using AngularJS to iterate over items in a list and display tag attributes

Can someone help me understand how to utilize item from ng-repeat within the same tag where I am declaring ng-repeat? In a hypothetical template language, this is what I want: {% for item in items %} <li data-theme="{{ item.dataTheme }}">{{ it ...

Tips for creating a fixed footer that adjusts with a flexible wrapper

Feeling incredibly stressed, I embarked on a quest to find the perfect sticky footer. After searching Google for what seemed like an eternity, I came across multiple tutorials recommending the use of min-height:100%. However, this approach caused the wrap ...

trouble centering elements in bootstrap

It appears that when I try to center this image, it is slightly off-center to the right on the page. What could be causing this? It seems like there might be a margin added to the left of the image. <head> <meta charset="utf-8"> ...

How can I save the indexed directory to a variable using Node.js?

What is the best way to index a directory in nodeJS and save it as a variable? I haven't made any attempts yet, so I'm not sure where to start with the code. ...

Discovering elements that are shallower than a chosen selector

I'm currently developing a jQuery plugin designed to facilitate the management of form collections. This plugin is intended to incorporate buttons for adding, removing, moving up, and moving down within the collection. In every collection's r ...

Send the value of a JavaScript variable to a PHP file upon calling a JavaScript function

When a script button is clicked, a javascript function runs. The function looks like this: //script function oyCrosswordFooter.prototype.update = function(){ var buf = ""; if (!this.puzz.started){ buf += "Game has not ...

Develop interactive div elements with the help of JavaScript/jQuery

Exploring dynamic div creation using javascript or jquery and looking for guidance. <div id="clickable"> <button class="start">Default</button> <button class="random">Randon</button> <button class="gradient"> ...

What is preventing my code from being recognized as a valid XML file?

Encountering an error indicating that this code snippet is not valid within an XSL file. This is the only feedback provided by the document system. While this code is a part of a larger document, I decided to isolate the issue to determine if it lies in ...

The HTML5 Websocket Script functions smoothly on Ubuntu but encounters issues on both Win7 and WinXP operating systems

I recently set up lemmingzshadow / php-websocket on my Windows 7 machine, following simple steps: Unzipped the files into my htdocs folder. Ran server.php from the command line. Accessed the file /client/status.html from a Websockets-compatible browser. ...

What is the best method for obtaining the precise text within the href attribute of an anchor tag?

Using selenium, I am retrieving the href attribute which belongs to my web elements known as "lLinks". String url = lLinks.getAttrbute("href"); In case the href within my 'a' tag is a relative path such as <a href='/home'>Home&l ...