tags:

views:

35

answers:

4

I have a div called "divContainer" inside which i have few input elements like textboxes,radio buttons et.. How can i define the style for then in the CSS ? I wanna mention styles for elements inside this purticular div.not for the entire form.

Ex: For textboxes i need width as 150px; For Radio buttons i need width of 20px;

+2  A: 

You can define style rules which only apply to specific elements inside your div with id divContainer like this:

#divContainer input { ... }
#divContainer input[type="radio"] { ... }
#divContainer input[type="text"] { ... }
/* etc */
David Underhill
Good point Mike; I've revised the code sample to use CSS3 selectors. Thanks.
David Underhill
If you aren't using CSS3, you should include the javascript here to make this work: http://www.dustindiaz.com/input-element-css-woes-are-over/
Mike
+1  A: 

Like this.

.divContainer input[type="text"] {
  width:150px;
}
.divContainer input[type="radio"] {
  width:20px;
}
no
This isn't necessarily backwards compatible with browsers that don't support CSS3
Mike
http://www.quirksmode.org/css/contents.html works all the way back to IE 6, good enough for most people.
Austin Fitzpatrick
+1  A: 

When you say "called" I'm going to assume you mean an ID tag.

To make it cross-brower, I wouldn't suggest using the CSS3 [], although it is an option. This being said, give each of your textboxes a class like "tb" and the radio button "rb".

Then:

#divContainer .tb { width: 150px }
#divContainer .rb { width: 20px }

This assumes you are using the same classes elsewhere, if not, this will suffice:

.tb { width: 150px }
.rb { width: 20px }

As @David mentioned, to access anything within the division itself:

#divContainer [element] { ... }

Where [element] is whatever HTML element you need.

Kerry
+1  A: 

CSS 3

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

CSS2 add a class "text" to the text inputs then in your css

.divContainer.text{
    width:150px;
}
BioBuckyBall
You can use the javascript linked above to eliminate adding classes.
Mike
true, but then you may get 'screen pop' as the javascript is evaluated and makes changes to the css. For style changes involving dimensions, I personally like to avoid using js on them where possible. But thats me :)
BioBuckyBall
`.divContainer.text` should be `.divContainer input.text`
zvonimir