Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a CSS selector for any field that the user types in?

I want to create some common styling for all elements where the user selects (either with a mouse or tapping on in a touch screen) and then inputs text with a cursor. This includes:

  • <input>
  • <input type='text'>
  • <textarea>
  • <input type='password'>
  • <another element that I didn't know existed that you can type into>

As you can see (and other examples probably), due to the <textarea> (which falls in this category) and <input type='submit'> (which doesn't) you can't just select all <input>'s.

Is there a special CSS (pseudo?) selector for this?

like image 954
J-bob Avatar asked Sep 30 '22 09:09

J-bob


2 Answers

Nope, there isn't.

Either you go with lists

input, textarea {...}

or you use a css-preprocessor (e.g. sass) and make yourself a mixin or a function that handles all these types. But you won't get around defining all these elements at some point.

like image 104
hurrtz Avatar answered Oct 02 '22 14:10

hurrtz


I'd use a css class:

<input class="user-input">
<input type='text' class="user-input">
<textarea class="user-input">
<input type='password' class="user-input">

And then you'd style based on that class. While this may not be as automatic as you desire, this provides you th most control and would allow you to avoid styling submit buttons for example.

You could also do the inverse, of course, and have a class "non-user-input" which then would be put on things like the submit button. Then you just target <input>, <textarea> and etc.

This might be more appropriate for your needs.

like image 22
Frank V Avatar answered Oct 02 '22 13:10

Frank V