1

I am trying to customize my checkbox, the final goal is to look as close as possible to this:

CheckBox

Don't mind the background on Remember me it's just to hide the text of the original label that is on my native language.

Even though it seems a lot different, at first I just wanted to changed the tick sign with a blue square and use the original checkbox view so if I've missed something and it's still the easiest way please provide example.

However I was unable to find an attribute/option to change just that so I dig a little deeper and I decided to use THIS example to achieve my goal.

This is what I achieved on my own - JSFiddel Example but there are two major things I want to add if it's gonna be that way:

  • I don't know why I should get the <label> tag involved but it seems that I can not bypass it, so now I'm not sure what's the best way to add the Remember me text as it was before in between the <label>..</label> tags. Now if i put it there it's messing with the checkbox itself.
  • I want the unchecked box to look more like the original one. now I use solid corol (lightgrey) but it would be nice if it's closer to the original style.

And of course, any changes that will make things look more like the example provided in the question are appreciated. I'm not stuck with this idea but it seems the closest to what I want.

5
  • This topic can come in hand stackoverflow.com/questions/4148499/… Commented Nov 24, 2013 at 12:42
  • Yeah, I checked it already. It seems that I will have to use some custom CSS that's why I provide JSFiddle example. Commented Nov 24, 2013 at 12:47
  • 1
    The fiddle css is good enough IMHO. I'm using barely the same layout. The only difference - I don't use wrap. I basically have two background-image for checked and unchecked state. As for the text - why not use <i> or <span>? Commented Nov 24, 2013 at 12:52
  • I have a little experience with CSS and that's the main reason to post this question again. I find it really hard to believe that the only option is to use tick for the checking without an easy way to change it. And I also hoped someone to explain why I need to involve the label in all this. I use ASP.NET MVC 4 with Razor and even though it's not directly connected to this question there's some auto generated code that I don't want to change if I don't have to. And if I can't use label tag then it seem that after all I'll need to change it. Commented Nov 24, 2013 at 12:59
  • Now that explains a lot. Well I'll wait for an answer with you, but unfortunately as I know you can't do anything else in IE. Commented Nov 24, 2013 at 13:04

1 Answer 1

2

You must use the label, because otherwise you cannot check the checkbox when you click on it.

For the "Remember me", you can add another label, which contains the text. To have it on the same line, you must add display: inline-block to #wrap

<div id="wrap">
    <input type='checkbox' name='thing' value='valuable' id="thing" />
    <label class="mark" for="thing"></label>
</div>
<label for="thing">Remember me</label>
#wrap {
    display: inline-block;
}

To be more like the native checkbox when unchecked, you can use

background: transparent;

To distinguish between the two labels, I used class="mark" for the box.

See modified JSFiddle

This works in Chrom, but at least for Firefox 20

#thing {
    display: none;
}

doesn't work. For Firefox 20, you must use

#thing {
    position: absolute;
    visibility: hidden;
}

to hide the checkbox and take it out of the normal flow.

JSFiddle

Update:

You can also try #thing + label:before to create a checkbox

#thing + label:before
{
    content: "";
    background: transparent;
    height: 9px;
    width: 9px;
    display:inline-block;
    padding: 0 0 0 0px;
    margin-left: 3px;
    margin-bottom: 3px
}
#thing:checked + label:before
{
    background: #0080FF;
}

and put the "Remember me" in the label

<input type='checkbox' name='thing' value='valuable' id="thing"/>
<label for="thing">Remember me</label>

The drawback to this, I cannot find a way to put the box and label on one line.

JSFiddle

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it seems that after all most of the CSS should be changed. I find the need to change the label very inconvenient.
You can use #thing + label:before for the checkbox. Please see updated answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.