Jump to content
  • Announcements

    • boen_robot

      Guidelines and Netiquette   03/28/2017

      Posting Problems:   Having problems posting your topic? Read through this: To join, you agree to our terms and conditions and fill out and submit a registration form. An activation email will be sent to your email adress, so you'll need to verify your account. After that the account has to be validated by one of the moderators. This will mean that it can take up to a day to be activated. A couple of things to remember to ensure approval: Don't use an email address in one of those $2 four character .com domains eg. xyds.com. These will be deleted and the domain added to the banned list. Don't use an email address that is within a domain with a bad reputation for spam. A Google search is run on every email address and email domain. Don't sign up with an email address that doesn't exist, doesn't work or requires the sender to answer a quiz before their email can get to you. Put your country and or state and city in the signup form. Blank forms will go to the botton of the "to do" list. And make sure that your email address and your country match, saying you're from Alabama and using a .ru email address is not going to get you activated. After a membership is activated the first few posts will be monitored. Posting spam or unapproved topics described in the agreement results in an immediate ban. The email provider and the IP addresses associated with the account will be banned and all posts will be deleted. These strict measures have been deemed necessary to hinder spam. Sorry for any inconvenience this causes, but it's not liable to change. If, after reading this, you still can't post and don't understand why, contact one of the Moderators listed here.   Topic Guidelines   Including the following information can expedite an accurate response from board members: Must be a Specific Problem or Question related to web design and development Include Code in Question (wrap with   for small blocks of code and for longer blocks   ) Include Code Author Include Extra Notes/Modifications/Attempts Include web link to page/file when possible Content Guidelines   You may not post, upload, link to, or email any Content that contains, promotes, gives instruction about, or provides prohibited Content. Prohibited Content includes any Content that breaks any local, state, county, national or international law. Prohibited Content also includes: No direct or indirect advertising or websites, forums, products, services No hijacking of posts (do not post your question in someone elses) Content that infringes upon any rights [ex. MP3s and ROMs] (including, but not limited to, copyrights and trademarks) Abusive, threatening, defamatory, racist, or obscene Viruses or any other harmful computer software False Information or libel Spam, chain letters, or Pyramid schemes Gambling or Illicit drugs Terrorism Hacking or cheating for internet/online games Warez, Roms, CD-Keys, Cracks, Passwords, or Serial Numbers Pornography, nudity, or sexual material of any kind Excessive profanity Invasive of privacy or impersonation of any person/entity Hacking materials or information Posting Tips   There are more BBcodes than there are buttons for on the reply menu. To get the full list, click "BB Code Help" underneath the clickable smilie face menu. Use   for small snippets of code Use   for lengthy snippets of code Use   if your snippet is HTML (optional) Use   if your snippet is SQL (optional) Rules of Conduct   Be nice. There's no need for calling someone stupid if they ask an 'easy' question. Keep your avatars and signatures absolutely child friendly. We have a younger audience on this forum. Keep your language appropriate for the same reason above. Do not PM moderators for help on the forum. Post on the topic, or create a new one.   Spam:   Recently, as you have all without doubt noticed, we have had lots of spam and advertisement on the forum. Therefore, we'd like to alert you as to what to do when you have found any of the aforementioned annoying messages: it. Immediately. Give a clear reason, please, if the advertising is not evident. DO NOT POST! Report, let the post stay as is, and we will get to it, meanwhile if you continue to post as normal in the other threads, it won't be on the top so long. Refrain from PMing the member. This won't help at all, as they are most likely spambots anyway. Thank you.       Images in signatures:   After thinking of users on dial-up, we have decided to enforce the following rules regarding signatures. Please pay heed to them. Respecting these rules is respecting the members on this forum with dial-up. Signature rules: No animated images AT ALL. No matter the amount of animation. Maximum image widthxheight: 300x150 Maximum image (file) size: 15kb Use calm colors. Do not use highly contrasting images in your signature, as this can get really annoying when seeing several posts from one member in the same thread. The same prohibited content goes for images as for posts. Lastly, use common sense. No lengthy signatures please. Save us some scrolling. Thank you.       Links in signatures:   Please understand that w3schools.com only exists because of voluntary work and is barely supported by the advertising littered throughout the tutorials and the forum. So, please, stop advertising other sites. DO not post links that drive traffic away from the w3schools domain - especially to a site that offers similar if not identical information. Please help support the site by keeping individuals on it. Thank you. Here are some guidelines as to what you can put in your signature: w3schools links --> allowed w3.org links --> allowed browser links --> allowed html editor links --> allowed personal sites --> allowed tutorial sites competing with w3schools --> NOT allowed sites completely irrelevant to webprogramming and this forum --> NOT allowed   Thanks for understanding, and for taking the time to read this. ~W3Schools Modstaff~
Gnapponico

Custom Checkbox & Radio without labels

Recommended Posts

Hi! I'm new to W3C School forum, even if I read meny things about CSS in the main website.
I'm trying to customize checkbox and radio inputs...
I read many tutorials concerning input customization and I successfully customized buttons, password, text, etc and select, textbox, etc...
My problem is the compatibility with browsers. I'm trying to develop a web-app (asp.net) in which I customized everything.
Checkbox and Radio buttons are my "bête noire": I can't make them run on FireFox and iExplorer.
I choose the "sprite" method, avoiding the use of labels, because my web-app can't use labels.
So, this is the CSS code I'm currently using:
input[type='checkbox'], input[type='radio']{         background-image: url('http://s28.postimg.org/oggskkn6x/controls.png');    background-repeat: no-repeat;   width: 16px;   height: 16px;   margin: 0;   padding: 0;   -moz-appearance: none; /* not working */   -webkit-appearance: none;   -ms-appearance: none; /*not working */   -o-appearance: none;   appearance: none;}/* not checked */input[type='radio']{background-position: -32px 0; }/* checked */input[type='radio']:checked { background-position: -48px 0;}input[type='checkbox']:checked { background-position: -16px 0; }input[type='checkbox']:hover:checked, input[type='checkbox']:focus:checked { background-position: -16px -16px; }input[type='radio']:hover:checked,input[type='radio']:focus:checked { background-position: -48px -16px; }/* focus */input[type='checkbox']:hover,input[type='checkbox']:focus { background-position: 0 -16px; }input[type='radio']:hover,input[type='radio']:focus { background-position: -32px -16px; }/* active */input[type='checkbox']:active { background-position: 0 -48px; }input[type='radio']:active { background-position: -32px -48px; }input[type='checkbox']:active:checked { background-position: -16px -48px; }input[type='radio']:active:checked { background-position: -48px -48px; }/* disabled */input[type='checkbox']:disabled { background-position: 0 -32px; }input[type='radio']:disabled { background-position: -32px -32px; }input[type='checkbox']:disabled:checked { background-position: -16px -32px; }input[type='radio']:disabled:checked{ background-position: -48px -32px; }input[type='checkbox']:hover:disabled,input[type='checkbox']:focus:disabled { background-position: 0 -32px; }input[type='radio']:hover:disabled ,input[type='radio']:focus:disabled { background-position: -32px -32px; }input[type='checkbox']:hover:disabled:checked ,input[type='checkbox']:focus:disabled:checked { background-position: -16px -32px; }input[type='radio']:hover:disabled:checked,input[type='radio']:focus:disabled:checked { background-position: -48px -32px; }
Here, a JSFiddle in order to have a look on how it works:
If you open it on Opera, Safari or Chrome everything works great (as expected) but, if you use iExplorer (v. 10/11) or Firefox...not!
How can I make it work on Firefox, without lables and java?
Just to summarize, this is the result I obtain on iExplorer (IE), FireFox (FF), Opera (O), Chrome ( C), and Safari (S):
checkbox.png
I can accept IE isn't working, but FireFox...how can I hide the default input style?
Any ideas? Can anyone help me in finding the right solution?
Thanks in advance!
Nick

Share this post


Link to post
Share on other sites

What if you create a holding container around checkbox, add checkbox and a container to hold background image, and make checkbox opacity to 0 and make sure it is above background image container

<!DOCTYPE html><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <meta name="viewport" id="viewport" content="target-densitydpi=high-dpi,initial-scale=1.0,user-scalable=no" />        <title>Document Title</title>        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>        <script  type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>        <script type="text/javascript">        </script>        <style type="text/css">            input[type='checkbox'], input[type='radio']{                background-image: url('http://s28.postimg.org/oggskkn6x/controls.png');                background-repeat: no-repeat;                margin: 0;                padding: 0;                -moz-appearance: none; /* not working */                -webkit-appearance: none;                -ms-appearance: none; /*not working */                -o-appearance: none;                appearance: none;            }            .checkbox_outer {position:relative; float: left; margin-right: 5px;}            input[type='checkbox'] + span {position:absolute; top:0; left:0; right:0; bottom:0; background-image: url('http://s28.postimg.org/oggskkn6x/controls.png'); background-repeat: no-repeat;}            input[type='checkbox'] {background:none; opacity:0;}            input[type='checkbox'], input[type='radio'], .checkbox_outer {                height: 16px;                width: 16px;                position: relative;                z-index: 10;            }            /* not checked */            input[type='radio']{background-position: -32px 0; }            /* checked */            input[type='radio']:checked { background-position: -48px 0;}            input[type='checkbox']:checked { background-position: -16px 0; }            input[type='checkbox']:hover:checked,            input[type='checkbox']:focus:checked { background-position: -16px -16px; }            input[type='radio']:hover:checked,            input[type='radio']:focus:checked { background-position: -48px -16px; }            /* focus */            input[type='checkbox']:hover,            input[type='checkbox']:focus { background-position: 0 -16px; }            input[type='radio']:hover,            input[type='radio']:focus { background-position: -32px -16px; }            /* active */            input[type='checkbox']:active { background-position: 0 -48px; }            input[type='radio']:active { background-position: -32px -48px; }            input[type='checkbox']:active:checked { background-position: -16px -48px; }            input[type='radio']:active:checked { background-position: -48px -48px; }            /* disabled */            input[type='checkbox']:disabled { background-position: 0 -32px; }            input[type='radio']:disabled { background-position: -32px -32px; }            input[type='checkbox']:disabled:checked { background-position: -16px -32px; }            input[type='radio']:disabled:checked{ background-position: -48px -32px; }            input[type='checkbox']:hover:disabled,            input[type='checkbox']:focus:disabled { background-position: 0 -32px; }            input[type='radio']:hover:disabled ,            input[type='radio']:focus:disabled { background-position: -32px -32px; }            input[type='checkbox']:hover:disabled:checked ,            input[type='checkbox']:focus:disabled:checked { background-position: -16px -32px; }            input[type='radio']:hover:disabled:checked,            input[type='radio']:focus:disabled:checked { background-position: -48px -32px; }            input[type='checkbox']:checked + span{ background-position: -16px 0; }            input[type='checkbox']:hover:checked + span,            input[type='checkbox']:focus:checked { background-position: -16px -16px; }            input[type='checkbox']:hover + span,            input[type='checkbox']:focus + span { background-position: 0 -16px; }            input[type='checkbox']:active + span { background-position: 0 -48px; }            input[type='checkbox']:active:checked + span { background-position: -16px -48px; }            input[type='checkbox']:disabled + span{ background-position: 0 -32px; }            input[type='checkbox']:disabled:checked + span { background-position: -16px -32px; }            input[type='checkbox']:hover:disabled + span,            input[type='checkbox']:focus:disabled + span { background-position: 0 -32px; }            input[type='checkbox']:hover:disabled:checked + span ,            input[type='checkbox']:focus:disabled:checked + span { background-position: -16px -32px; }        </style>    </head>    <body>        <div class="checkbox_outer"><input id="ID1" type="checkbox" name="NAME1"><span></span></div> Empty, not checked & enabled<br />        <div class="checkbox_outer"><input id="ID2" type="checkbox" name="NAME2" checked="checked"><span></span></div>  Checked<br />        <div class="checkbox_outer"><input id="ID3" type="checkbox" name="NAME3" disabled="disabled"><span></span></div>  Empty, not checked & disabled<br />        <div class="checkbox_outer"> <input id="ID4" type="checkbox" name="NAME4" checked="checked" disabled="disabled"><span></span></div>  Checked & disabled<br /><br /><br />        <strong>Of course, it works well with radio input. It works only with Opera, Safari and Chrome</strong><br /><br />        <input id="ID5" type="radio" name="NAME5" checked> Checked<br />        <input id="ID5" type="radio" name="NAME5"> Not checked<br />        <input id="ID6" type="radio" name="NAME6" checked disabled> Checked & disabled<br />        <input id="ID6" type="radio" name="NAME6" disabled> Not checked & disabled<br />        <br />Here it's how it looks like on iEplorer (IE), Firefox (FF) and the others:<br />    <center><img src="http://s9.postimg.org/825sxesnj/checkbox.png" width="50%"></img></center></body></html>

It may mean extra html coding but it works in all browsers, I think.

Edited by dsonesuk

Share this post


Link to post
Share on other sites

Wooow...It seems to work great!

But...only for checkbox...

I tried for radiobutton and...it doesn't work :facepalm:

 

I'll spend some days in "extra coding" my C# code... :umnik2:

 

thank you sooooooomuch!

Edited by Gnapponico

Share this post


Link to post
Share on other sites

Ok...ok... It was my fault!

I forgot something...

 

this is the result:

 

CSS:

input[type='checkbox'], input[type='radio'] {background:none; opacity:0;}.checkbox_outer {position:relative; float: left; margin-right: 5px;}input[type='checkbox'] + span, input[type='radio'] + span {position:absolute; top:0; left:0; right:0; bottom:0; background-image: url('http://s28.postimg.org/oggskkn6x/controls.png'); background-repeat: no-repeat;}input[type='checkbox'], input[type='radio'], .checkbox_outer { height: 16px; width: 16px; position: relative; z-index: 10;}/*Checkbox*/input[type='checkbox']:checked + span{ background-position: -16px 0; }input[type='checkbox']:hover:checked + span,input[type='checkbox']:focus:checked { background-position: -16px -16px; }input[type='checkbox']:hover + span,input[type='checkbox']:focus + span { background-position: 0 -16px; }input[type='checkbox']:active + span { background-position: 0 -48px; }input[type='checkbox']:active:checked + span { background-position: -16px -48px; }input[type='checkbox']:disabled + span{ background-position: 0 -32px; }input[type='checkbox']:disabled:checked + span { background-position: -16px -32px; }input[type='checkbox']:hover:disabled + span,input[type='checkbox']:focus:disabled + span { background-position: 0 -32px; }input[type='checkbox']:hover:disabled:checked + span ,input[type='checkbox']:focus:disabled:checked + span { background-position: -16px -32px; }/*Radiobutton*/input[type='radio']+span {background-position: -32px 0; }input[type='radio']:checked + span{ background-position: -48px 0; }input[type='radio']:hover:checked + span,input[type='radio']:focus:checked { background-position: -48px -16px; }input[type='radio']:hover + span,input[type='radio']:focus + span { background-position: -32px -16px; }input[type='radio']:active + span { background-position: -32px -48px; }input[type='radio']:active:checked + span { background-position: -48px -48px; }input[type='radio']:disabled + span{ background-position: -32px -32px; }input[type='radio']:disabled:checked + span { background-position: -48px -32px; }input[type='radio']:hover:disabled + span,input[type='radio']:focus:disabled + span { background-position: -32px -32px; }input[type='radio']:hover:disabled:checked + span ,input[type='radio']:focus:disabled:checked + span { background-position: -48px -32px; } 

HTML:

<strong>Checkboxes</strong> <br />       <div class="checkbox_outer"><input id="ID1" type="checkbox" name="NAME1"><span></span></div> Empty, not checked & enabled<br /><div class="checkbox_outer"><input id="ID2" type="checkbox" name="NAME2" checked="checked"><span></span></div>  Checked<br /><div class="checkbox_outer"><input id="ID3" type="checkbox" name="NAME3" disabled="disabled"><span></span></div>  Empty, not checked & disabled<br /><div class="checkbox_outer"> <input id="ID4" type="checkbox" name="NAME4" checked="checked" disabled="disabled"><span></span></div>  Checked & disabled<br /><br /><br /><strong>Radio buttons </strong><br /><div class="checkbox_outer"> <input id="ID5" type="radio" name="NAME5" checked><span></span></div> Checked<br /><div class="checkbox_outer"> <input id="ID5" type="radio" name="NAME5"><span></span></div> Not checked<br /><div class="checkbox_outer"> <input id="ID6" type="radio" name="NAME6" checked disabled><span> </span></div>Checked & disabled<br /><div class="checkbox_outer"> <input id="ID6" type="radio" name="NAME6" disabled><span></span></div> Not checked & disabled<br />

the result here:

 

http://jsfiddle.net/vPe4y/1/

 

Now...some questions:

1) if input control is "disabled", the "focus" or "hover" action is disabled...why?

2) if I check something (i.e. I click con radiobutton or a checkbox) and I stand with the pointer on it or around without clicking anything at all, I can't see the result...I've to click outside the input area to see the result...why? Everything works great on Safari only... :|

 

Anyway...dsonesuk...You teached me something new! thanks!

Edited by Gnapponico

Share this post


Link to post
Share on other sites

:good: yes...better...

but...what did you change? only the order of this? :umnik2:

input[type='checkbox']:active:checked + span { background-position: -16px -48px; }
Edited by Gnapponico

Share this post


Link to post
Share on other sites

some of input selectors did not have span, and pseudo hover etc have to be in specific order

 

link

visted

hover

active

 

LoVe - HAte

 

active was taken precedence over hover.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×