How to set the color of a checkbox

S

Stefan Mueller

With 'background-color' I can set the color of an input box. But how can I
set the color of the inner area of a checkbox?

Stefan
 
M

Mark Parnell

Deciding to do something for the good of humanity, Stefan Mueller
With 'background-color' I can set the color of an input box. But how can I
set the color of the inner area of a checkbox?

The same way, but browsers vary significantly in what they will allow
you to do with styling form elements.
 
J

Jose

The same way, but browsers vary significantly in what they will allow
you to do with styling form elements.

Well put. People think web design is setting the page up to display
"properly", but really, it is asking permission from a slew of browsers
and other display devices, all at the same time, to please do something
you'd like to happen.

Jose
 
S

Stefan Mueller

Does that mean that it's not possible to set the color of the area where the
check is located?
Stefan
 
N

Neredbojias

With neither quill nor qualm, Stefan Mueller quothed:
Does that mean that it's not possible to set the color of the area where the
check is located?

Not if it's in the mail.
 
S

Stefan Mueller

Does that mean that it's not possible to set the color of the area where
Not if it's in the mail.

Sorry, I'm not an English native speaker and therefore I don't understand
your answer. What are you talking about mail?
Is it possible to set the color of the area where the check of a checkbox is
located or is it not possible?

Stefan
 
J

Jonathan N. Little

Stefan said:
Sorry, I'm not an English native speaker and therefore I don't understand
your answer. What are you talking about mail?
Is it possible to set the color of the area where the check of a checkbox is
located or is it not possible?

A joke in response to 'where is the check located': 'The check is in the
mail' is common excuse by deadbeats to their debtors.
 
J

Jose

Sorry, I'm not an English native speaker and therefore I don't understand
your answer. What are you talking about mail?

The word "check" also means a financial instrument, and "the check is in
the mail" means "I've already sent my payment, stop bothering me, you'll
get it shortly.", often used when the check is actually =not= in the mail.

My slavic cousin was going to visit me from overseas and I went to the
airport but he wasn't on the plane. When I called his wife, she told me
that airfare was too expensive so they used the postal service. "The
Czeck is in the mail".

Jose
 
M

Mark Parnell

Deciding to do something for the good of humanity, Stefan Mueller
Sorry, I'm not an English native speaker and therefore I don't understand
your answer. What are you talking about mail?

Don't worry - it's just a result of the American misspelling of cheque.
;-)
Is it possible to set the color of the area where the check of a checkbox is
located or is it not possible?

It depends on the browser. Some browsers may allow you to, some
certainly don't.
 
N

Nik Coughlin

Stefan said:
With 'background-color' I can set the color of an input box. But how
can I set the color of the inner area of a checkbox?

Stefan

There is a very dirty way to do it... I don't know if I should tell you
though, I might get told off, because it's something that you really
shouldn't do for a whole number of useability related reasons that I won't
go into here, though I'm sure the regulars will be quick to point them out
:)

Here's how it works.

You have your normal checkbox, unstyled. You use JavaScript to hide it (so
that it is still on the page but invisible) and use JavaScript to add your
replacement checkbox, which is just a boring old <img>. You then use the
onclick event of the image to switch between two custom images, one for
checked and one for unchecked. At the same time you set the hidden checkbox
to be checked or unchecked. When the form is submitted it gets the value
from your hidden checkbox. If the user doesn't have Javascript enabled then
they just get the normal unstyled checkbox as a fallback.
 
N

Nik Coughlin

Nik said:
You have your normal checkbox, unstyled. You use JavaScript to hide
it (so that it is still on the page but invisible) and use JavaScript
to add your replacement checkbox, which is just a boring old <img>. You
then use the onclick event of the image to switch between two
custom images, one for checked and one for unchecked. At the same
time you set the hidden checkbox to be checked or unchecked. When
the form is submitted it gets the value from your hidden checkbox. If the
user doesn't have Javascript enabled then they just get the
normal unstyled checkbox as a fallback.

http://nrkn.com/customCheck/
 
S

Stefan Mueller

Thanks to all of you for the clarification.
It depends on the browser. Some browsers may allow you to, some
certainly don't.

Hmm, that sounds very bad.
I just would like to make the checkbox purple if someone changes the default
value (check set or not set). For an input box it works fine. I just can
change its background color.

Stefan
 
S

Stefan Mueller

http://nrkn.com/customCheck/

I have a problem with your solution.
If you modify the line
<body onload="document.getElementById( 'check' ).style.display = 'none';">
of your code with
<body onload="document.getElementById( 'check' ).style.display =
'inline';">
then you'll see also the real checkbox.

If you click now on the colored checkbox (image) the real checkbox gets also
checked. But if you press now F5 (browser refresh) the real checkbox remains
checked whereas the colored checkbox gets cleared. Therefore I have an
inconsistency between the real and the colored checkbox.
If you press Shift + F5 then it works.

Does someone know how to fix this problem?
Stefan
 
N

Nik Coughlin

Stefan said:
I have a problem with your solution.
If you modify the line
<body onload="document.getElementById( 'check' ).style.display =
'none';"> of your code with
<body onload="document.getElementById( 'check' ).style.display =
'inline';">
then you'll see also the real checkbox.

If you click now on the colored checkbox (image) the real checkbox
gets also checked. But if you press now F5 (browser refresh) the real
checkbox remains checked whereas the colored checkbox gets cleared.
Therefore I have an inconsistency between the real and the colored
checkbox. If you press Shift + F5 then it works.

Does someone know how to fix this problem?
Stefan

Hi Stefan,

That didn't occur to me. I've updated the example I provided you to show
how to handle this:

http://nrkn.com/customCheck/
 
S

Stefan Mueller

You're right. With your code it works perfect.
I guess 'body onload' does the trick.

Many thanks again
Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top