Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the "box" of a checkbox in css

Tags:

html

css

I am trying to remove the actual box of a checkbox field, and just make the text clickable. How can I do this with JS and css? I started using buttons, but I switched to checkboxes because the "state" of the box is easier to find out than a button. But now that I am polishing up the page with css for better formatting and layout, The boxes are getting in the way, and I would prefer just for the text to be clickable without a box present.

like image 578
chris Frisina Avatar asked Jun 17 '12 03:06

chris Frisina


People also ask

How do you remove a border from a checkbox?

You can remove that by unselecting the "highlight existing form fields" function at the top of your document. If you are talking about the actual outline of the "box" part of a checkbox, you can bring up the field properties, then go to the Appearance tab and set both border color and fill color to transparent.

How do I stylize a checkbox in CSS?

Use the :checked pseudo-class, which helps to see when the checkbox is checked. Style the label with the width, height, background, margin, and border-radius properties. Set the position to "relative". Style the "checkbox-example" class by setting the display to "block" and specifying the width and height properties.

How do you make a transparent background on a checkbox?

In short, you can't. How a checkbox is rendered is dependent on browser and (if the browser allows it - and most don't) OS settings. The only option you have is to hide the checkbox and use separate, style-able elements to display "it" the way you want.

How do you change the shape of a check box?

To change size, color, or border style of the check box, select the Use a style to format text typed into the empty control box, and then click New Style. Under Formatting, select a font size for the check box. In the Color list, select a color. To select a different border, select Format > Border.


1 Answers

You can just hide it with CSS using display: none;

HTML

<input type="checkbox" name="a" id="a" value="a" /><label for="a">asdf</label>​

CSS

/* for all inputs of type checkbox */
input[type="checkbox"]  {
   display: none;
}

/* for just the single element by id */ 
#a {
    display: none; 
    /* visibility: hidden      works too */
}​

See here for difference between visibility:hidden and display:none.

DEMO

like image 187
sachleen Avatar answered Sep 21 '22 06:09

sachleen