Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Apply border to all input elements except checkbox

Tags:

css

I have a css class:

input {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
    border: 1px solid #003399;
}

Which works for most of what I want but I now need to have a checkbox that doesn't have this border while the rest of the input elements on the page continue to have the border applied.

I therefore created the additional css class:

input[type="checkbox"] 
{
    border: none;
}

This works fine with FireFox and Chrome but not ie 8, an when I use the Developer Tools in ie to inspect the element I can see both styles have been picked up but it's only when I deselect the check box beside the input style does the border disappear for the check boxes.

This is the default:

enter image description here

And this is what I do to get rid of the border:

enter image description here


1 Answers

Why not just use the :not selector to invert the attribute selector?

input:not([type=checkbox])
{
    border: 1px solid #039;
}

If it is IE8 or before, you should probably use separate rules for the classes where you do want to set the border, as it doesn't support :not (or any of the good stuff).

Edit:

input[type=checkbox]
{
    border: none;
}

works in IE8 if you add a doctype, even the simple <!doctype html>

like image 109
Steven Don Avatar answered Sep 07 '25 23:09

Steven Don