Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS for elements ONLY under a specific id

Tags:

css

I have a div element that has an id and this div contains a set of inputs and labels. I ONLY want to style the inputs inside this specific div but .. the following styles everything (global) instead of keeping the scope inside #ParentDiv

#ParentDiv label,input { display: inline; } 

Also, is it possible to do this type of thing with valid css in IE6/7?

like image 293
Toran Billups Avatar asked Jan 16 '09 19:01

Toran Billups


People also ask

How do I target a specific ID in CSS?

CSS ID selector To use an ID selector in CSS, you simply write a hashtag (#) followed by the ID of the element. Then put the style properties you want to apply to the element in brackets.

Can you make a ID selector particular to an element type?

You can create a selector that will target specific elements with the class applied.

How can we select an element with a specific class in CSS?

The .class selector selects elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify that only specific HTML elements should be affected by a class.

How do I apply CSS to all elements except one?

Approach: Use the :not(selector), also known as negation pseudo-class which takes a simple selector as an argument and allows you to style all the elements except the element specified by the selector.


1 Answers

you need this:

#ParentDiv label, #ParentDiv input { display: inline; } 

A comma indicates a new selector statement.

Often, so that I remember what each of the selectors is, and to make it easier to see what elements are being selected at a glance, I will alphabetize and break the selectors on two separate lines like so:

#ParentDiv input, #ParentDiv label {     display: inline; } 

Also, this should work just fine in IE 6/7/8, and is valid according to w3c.

like image 134
cdeszaq Avatar answered Sep 22 '22 13:09

cdeszaq