pf » Styling input based on their type with CSS

Styling input based on their type with CSS

web

A few weeks ago I posted how I style forms with CSS. Here's another trick that could be used with that technique.

Suppose your creating a form with a couple text fields and a submit button. Now you want to set the width of the text fields, but you want your submit button to be set to the default size. If you did something like this:

input { width: 200px; }

All input tags would be 200px; we only want input tags with type="text" to be 200px; you can use attribute selectors:

input[type="text"] { width: 200px; }

Attribute selectors are super handy but they don't work in IE6! You may still find them useful, just make sure you test on IE to make sure things still look ok.



Related Entries
6 people found this page useful, what do you think?

Trackback Address: 548/A6AA54B19EACB8FEDECA17816A426F05
On 03/06/2006 at 4:20:30 AM MST Tony Petruzzi wrote:
1
"Attribute selectors are super handy but they don't work in IE6!"

That is why CSS has this thing called classes. Designate a class for the text inputs and one for the button inputs.

On 03/06/2006 at 4:50:34 AM MST Pete Freitag wrote:
2
Tony, I'm aware of classes, but attribute selectors allow you to style specific elements without designating a class. The saved typing is what makes them handy!

On 03/06/2006 at 6:02:57 AM MST Dan G. Switzer, II wrote:
3
Dean Edwards has created a solution for using CSS Selectors in IE6 that he called "IE7" (which isn't the greatest name.)

http://dean.edwards.name/IE7/

This library also fixes other IE6 issues, such as:

* Pure CSS Menus * Complexspiral * Box-Model * Fixed Positioning * Dynamic Pseudo Classes * Rounded Corners * XML * PNG Transparency

On 03/06/2006 at 10:07:13 AM MST Richard@Home wrote:
4
you can use attribute selectors:*

*which doesn't work for 89%-90% for your potential user-base.

Roll on IE7 and automatic update, I say!

On 03/06/2006 at 10:08:15 AM MST Richard@Home wrote:
5
grrr... didn't spot the comments on daughters titchy screen... time to upgrade, I say!

On 02/01/2007 at 9:42:33 AM MST beth wrote:
6
This came in super handy. As for Tony, I don't have access to all the code I'm styling. Our forms are generated dynamically from code by a separate dev team, so this is the only option I have for controlling how a group checkboxes are styled.

On 01/07/2008 at 2:36:49 PM MST Andy wrote:
7
This works in IE7 and Firefox:

<style type="text/css"> INPUT.text { /* text style */ }

INPUT.file { /* file style */ }

INPUT.button { /* button style */ } </style>

I'm under the impression it works under IE6, but not 100% sure as I don't have access to IE6 any more since upgrading.

On 04/02/2008 at 12:21:38 AM MST Rambabu wrote:
8
This not working in IE7 and Firefox:

<style type="text/css"> INPUT.text { /* text style */ }

INPUT.file { /* file style */ }

INPUT.button { /* button style */ } </style>




  



Spell Checker by Foundeo





Subscribe to my RSS Feed: solosub RSS
Tags