Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css selector to match an element without attribute x [duplicate]

I'm working on a CSS file and find the need to style text input boxes, however, I'm running into problems. I need a simple declaration that matches all these elements:

<input /> <input type='text' /> <input type='password' /> 

... but doesn't match these ones:

<input type='submit' /> <input type='button' /> <input type='image' /> <input type='file' /> <input type='checkbox' /> <input type='radio' /> <input type='reset' /> 

Here's what I would like to do:

input[!type], input[type='text'], input[type='password'] {    /* styles here */ } 

In the above CSS, notice the first selector is input[!type]. What I mean by this is I want to select all input boxes where the type attribute is not specified (because it defaults to text but input[type='text'] doesn't match it). Unfortunately, there is no such selector in the CSS3 spec that I could find.

Does anyone know of a way to accomplish this?

like image 244
Stephen Sorensen Avatar asked Oct 07 '09 18:10

Stephen Sorensen


People also ask

What does the CSS selector a href $= org select?

It matches links with href attributes whose values start with the given string.

How can we select elements with a specified attribute in CSS?

The [attribute|="value"] selector is used to select elements with the specified attribute, whose value can be exactly the specified value, or the specified value followed by a hyphen (-). Note: The value has to be a whole word, either alone, like class="top", or followed by a hyphen( - ), like class="top-text".


2 Answers

:not selector:

input:not([type]), input[type='text'], input[type='password'] {     /* style here */ } 

Support: in Internet Explorer 9 and higher

like image 52
eveliotc Avatar answered Sep 19 '22 05:09

eveliotc


For a more cross-browser solution you could style all inputs the way you want the non-typed, text, and password then another style the overrides that style for radios, checkboxes, etc.

input { border:solid 1px red; }  input[type=radio],  input[type=checkbox],  input[type=submit],  input[type=reset],  input[type=file]        { border:none; } 

- Or -

could whatever part of your code that is generating the non-typed inputs give them a class like .no-type or simply not output at all? Additionally this type of selection could be done with jQuery.

like image 33
Tim Santeford Avatar answered Sep 21 '22 05:09

Tim Santeford