"Enhance Your Design With CSS3 Styling for Labels and

HTML

 <div class="select">
      <div>
        <label for="kitty" class="kitty-label kitty-label-1 l-center">
        </label>
        <input type="checkbox" name="cats" value="1">
        <label>Kitty One</label>
      </div>
      <div class="cly-pam" style="width:50%; float: left">
        <label for="kitty" class="kitty-label kitty-label-2 l-center">
        </label>
        <input type="checkbox" name="cats" value="2">
        <label>Kitty Two</label>
      </div>
    </div>
    <div>

css

label{
  cursor: pointer;
}

    .kitty-label{
      position: relative;
      width: 100%;
      &:hover,
      &:focus,
      &:active{
        border-radius: 6px solid #fff;
      }
    }
    .kitty-label-1{
          display: inline-block;
          background: url(../img/kitty1.png) no-repeat 0 0;
          height: 142px;
          width: 142px;
    }

    .kitty-label-2{
          display: inline-block;
          background: url(../img/kitty2.png) no-repeat 0 0;
          height: 144px;
          width: 144px;
    }

    .select input[type="checkbox"]{
      display: none;
      &:checked + label:before{
        background: url(../img/tick.png) no-repeat;
      }
    }

The labels should have a background image, but there seems to be an issue where the border-radius does not appear behind the images when focused, active, or hovered. Additionally, the kitty images do not have rounded edges. Could using an image in a circle shape or applying CSS3 help achieve this?

Furthermore, the checkbox does not seem to show the tick or any indication of being checked. When clicking on the label (containing the kitty image), the tick does not appear. Can someone provide insight into what might be going wrong here? Any help would be greatly appreciated.

Updated

<div>
    <input type="radio" name="type" value="designer" id="designer">
    <label for="designer" id="designer" class="inline-block testsign" style="background: url(../img/face.png) no-repeat center;">
    </label></div>

CSS

.testsign{
  width: 170px;
  height: 170px;
  border-radius: 100%;
  &:hover,
  &:focus,
  &:active{
     border: 15px solid #f3f3f3;

  }
}

// [type="radio"]:not(:checked),
// [type="radio"]:checked {
//   visibility: hidden;

input[type="radio"]:checked + label:after {
    content:"";
    display: block;
    position: absolute;
    height: 60px;
    width: 60px;
    background: #f0f1f1 url(../img/tick.png) no-repeat center center;
    border-radius: 100%;
    border: 10px solid #fff;
}

An attempt was made using the example provided by @misterMan

I couldn't manage to position the label:after element at the bottom right corner as desired. I tried using top and left properties to position the tick circle, but encountered the issue that when checked, it would always appear in the same position specified by top and left. Is there a way to position the tick circle correctly at the bottom right corner within each label when the radio button is checked?

Another challenge is that when hovering over the label with a border radius and background image, the tick circle (label:after) appears jumpy when the radio button is checked. How can this jumping behavior be prevented? I attempted adding absolute center positioning and relative positioning, but this caused the labels to extend beyond their container. Any insights or assistance would be highly appreciated.

Your help or feedback will be valued.

Answer №1

This solution was crafted with love for you, tailored to your needs. The images have been incorporated as primary content rather than mere decoration 🙂

It's a simple and elegant approach that should fulfill your requirements perfectly. Feel free to give feedback!

Stay Updated!

Check out the latest fiddle update!

HTML Snippet:

<form>
    <input type="checkbox" id="pic1" />
        <label for="pic1">
            <img src="http://www.placehold.it/200" />
        </label>

    <input type="checkbox" id="pic2" />
        <label for="pic2">
            <img src="http://www.placehold.it/200" />
        </label>
</form>

CSS Styling:

body {
    margin: 0;
}
input[type=checkbox] {
    display: none;
}
label {
    position: relative;
    display: block;
    width: 200px;
    cursor: pointer;
    float: left;
    margin: 10px 0 10px 10px;
}
input[type=checkbox] + label img:hover {
    -webkit-border-radius: 100px;
    -moz-border-radius: 100px;
    border-radius: 100px;
}
input[type=checkbox]:checked + label img {
    -webkit-border-radius: 50px;
    -moz-border-radius: 50px;
    border-radius: 50px;
}
input[type=checkbox]:checked + label img:hover {
    -webkit-border-radius: 100px;
    -moz-border-radius: 100px;
    border-radius: 100px;
}
input[type=checkbox]:checked + label:after {
    content:"";
    display: block;
    position: absolute;
    bottom: 10px;
    right: 10px;
    height: 50px;
    width: 50px;
    background: url(http://i.imgur.com/i7379jf.png) no-repeat right bottom;
    background-size: 50px;
}
input[type=checkbox]:checked + label:hover:after {


}

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

Is there a lack of a feature for automatically shifting to the next input element in dynamically-created HTML?

I have a JavaScript function that is triggered when a user clicks a button: htmlstring = ''+ '<div class="input_holder">'+ '<div class="as_input_holder"><input tabindex="1" class="as_input form-control-sm ...

Floating container leads to delays

My goal is to create a div that changes when I hover over it. However, when I move my mouse into the div, there seems to be some lagging and the content does not appear clearly. Below is the HTML and CSS code I have used: .unshow-txt:hover, .unshow-txt: ...

"PxToRem: A handy PostCSS plugin for converting pixel units

As a beginner in the world of Node.js and post processors for CSS, I recently took the time to install the following tools after going through multiple articles: Node.js (including npm) Gulp PostCSS Pxtorem (a PostCSS plugin for Gulp) My goal is to util ...

What is the process for setting up a bootstrap grid with a single column at the top and two columns

Can anyone help me figure out how to rearrange a bootstrap grid from three columns on desktop to one column above and two below on mobile? I've attempted multiple methods, but haven't had any luck... https://i.stack.imgur.com/oY2VU.png ...

Is it possible to include a hidden default option that provides a description for my `select` tag?

Can someone help me create a description for the select tag that won't show up in the drop-down options? I remember seeing this done somewhere, but I can't recall where. Any suggestions? This is what I am trying to achieve: <fieldset> ...

Vue 2 does not properly transition the initial element when using the `mode=out-in` attribute

In my Vue project, I am using version 2.6.14 and trying to toggle between two buttons by utilizing v-if and v-else. Despite wrapping everything in a transition element, the first button doesn't transition smoothly, neither when appearing nor disappear ...

Fade in and out of div elements upon clicking on an # anchor

I have been attempting to create a function where different divs fade in and out when clicking on an image with an <a href>. Unfortunately, I have not been successful in getting it to work despite several attempts. Here is the code that I am using: ...

Facing a node.js installation issue on Windows 10 while using Visual Studio Code (VS

Issue encountered while trying to execute "DownloadString" with one argument: Unable to establish a secure connection due to SSL/TLS channel creation failure. At line:1 char:1 + iex ((New-Object System.Net.WebClient).DownloadString('https ...

Add the bannercode snippet found on a webpage

I am currently facing an issue with appending a banner code to the end of a URL. The scenario is as follows: An individual receives an email with a link to a website (SITE1), where the URL includes a banner code, such as www.site1.com?banner=helloworld O ...

Obtain specific text from elements on a website

How can I extract a text-only content from a td tag like 'Zubr Polish Lager 6%'? <td width="35%">Amber Storm Scotch Ale 6% <br/>SIZE/LIFE: 330ml <b>CASE</b> <br/>UOS ...

Applying CSS styles exclusively to a div element and not its before pseudo-class

So I'm working on an HTML page with a div that looks like this: <div class="get-this"> blah blah </div> I've added a before pseudo-element to the div and now I want to apply a CSS style specifically to the div, not including the pse ...

Update email address depending on the option chosen from the dropdown menu

My contact form includes the following fields: Name Email Number Department Message The "Department" field is a drop-down selection with seven options: Audio Engineering Graphic Design Music Production Photography Videography Web Development Other I ...

Having difficulties with the edit function in JavaScript To Do Application

After creating an edit button to modify a task, it functions properly for the initial task I create. However, when attempting to edit subsequent tasks, the edit function defaults back to modifying the input of the first task instead. With each new ta ...

Transfer file content by dragging and dropping it onto a TextArea when an anchor tag is dropped

Within my application, there are 2 textareas with corresponding code implementing "dragover" and "drop" listeners for each one: // for dragover handleDragOver : function (evt) { var self = this; evt.preventDefault(); console.log ( ...

Unconventional arrangement of gaps for radio buttons

Hey there, I've been searching for solutions on various platforms but haven't found any luck so far. These are the questions I've looked into: Radio buttons and label to display in same line Documentation on <FIELDSE ...

Customizing external elements with React's inline styling feature

Trying to use React to style elements generated by a third-party library has been a challenge. In the snippet below, I was able to achieve the desired styling using CSS, but now I am looking to accomplish the same using JavaScript. This way, users can defi ...

What is the best way to iteratively fade in data from a MySQL database one by one?

How can I load data from a MySQL database and display it one by one with a fade-in effect? Let's say I have a total of 40 images stored in the database. First, I want to display each image like this: <li class="img" style=" list-style: none; flo ...

What is the secret to aligning two elements flawlessly?

I'm currently working on completing a theme and I've hit a roadblock. I am trying to add header support, but it's causing issues with my layout. Everything was running smoothly until I inserted this line of code: <img src="<?php heade ...

Adding plain HTML using jQuery can be done using the `.after()` and `.before()` methods

I have encountered a situation where I need to insert closing tags before an HTML element and then reopen it with the proper tags. The code snippet I am using is as follows: tag.before("</div></div>"); and then re-open it by adding proper tag ...

Finding the webpage URL where a form element is located

Suppose I have two pages called a.php and b.php, each with a form-tag. Both of these forms have the same action attribute set to c.php. Is there a way to determine in c.php which form (from either page a or b) triggered its submission? Using a hidden inpu ...