Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS:Defining Styles for input elements inside a div

Tags:

css

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;

like image 768
Shyju Avatar asked Jul 21 '10 23:07

Shyju


People also ask

How do you target an input inside a div?

to add inputs inside the div. to select the div with querySelector . And then we call divElement. querySelectorAll with a selector string that selects input, select, checkbox, and textarea elements.

Can you put a style tag inside a div?

In HTML5, a <style> tag is allowed to appear under anything in <body> or <head> . Mostly you are not allowed to put blocking elements into inline elements but meta elements like style, script, meta may appear wherever you want.

How do I style a div element in CSS?

The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute. Any sort of content can be put inside the <div> tag!


2 Answers

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 */ 
like image 143
David Underhill Avatar answered Nov 11 '22 06:11

David Underhill


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; } 
like image 40
µBio Avatar answered Nov 11 '22 05:11

µBio