CSS Commands for Internet Explorer 7

There are plenty of CSS commands available that you can use for I.E 7.0. These are not really new because many other browsers have already supported them for decades. HTML itself is good enough but these CSS commands give you added control over HTML components.

slide 1 of 6

Child Selector

Child selector has been used by web developers to hide many different CSS commands (tags) from Internet Explorer. This technique is only possible in I.E 6. Since IE 7 recognizes the child selector, the same is not possible with this version. You might have a question –What actually the child selector is? Let’s find out with an example:

<div> <p> <span> Your text </span> </p> </div>

In this example, the <div> has a child <p> and <span> is grand-child of <div>. The content in the <span> tag can be made green by using this CSS pattern:

div span {color: green;}

The above code will make the text in <span> green when the <span> tag is nested inside a <div>. Similarly, <span> tag could become a child, grand-child or great grand-child of <div> tag.

Similarly, rules can be assigned to every HTML tag that is a child of another tag. Let us understand it further - for example, you want to assign a top margin to the first <div> tag and not to others. Without using a child selector, we’ll be pushed to assign an id or a class to the <div> tag and then reference that id or class in the CSS command.

slide 2 of 6

Hiding Commands From IE Using The Child Selector

People have actually used this selector in order to prevent Internet explorer from seeing CSS commands. Just by putting html>body beside CSS commands, Internet Explorer will disregard these.

Take an example of this code:

html>body .func {your CSS commands ;}

This will work because <body> is a child of <html> tag and it can not be a grandchild of <html>. For Internet Explorer 7.0, you also have to insert a blank comment tag right after the ‘>’ sign. This empty tag will not be understood by I.E and will be ignored.

html>/**/body .func {Your CSS commands;}

slide 3 of 6

CSS Commands for IE 7.0: Adjacent Selector, First-Child Pseudo Class And MoreAdjacent selector is a very useful CSS selector that lets you reference HTML elements that are next to some other element. I.E 7 supports a number of pseudo classes. One of these is the first child pseudo class that allows you to layout the very first HTML element in a different way in a given section.

slide 4 of 6

Adjacent Selector

This is a very helpful CSS selector that lets you reference the HTML element that is next to some other element. Let’s have a look at this example of an adjacent selector:

blockquote+p { margin-top: 0; }

This CSS code tells that all paragraphs that go before a quote will not have a margin. This useful code comes in use when you may wish to always mention the person leaving the quote in a specific paragraph after the quote. This code is useful also when you want to eliminate the spaces between the quote and paragraph.

You can also use adjacent selector with horizontal lists when you may wish to arrange the very first item a little different than all other items in your list. Here’s another example that assigns a right border to every navigation item, excluding the first one.

li+li { border-right: 2px solid black;}

The above code will add a left-border to any ‘li’ (excluding the first one) that follows another ‘li’.

slide 5 of 6

First-Child Pseudo Class

There are also some pseudo classes that IE 7 supports. One of these classes is the first child pseudo class that allows you to layout the very first HTML element in a different way in a given section. Say, for instance, you wanted that your first paragraph to not contain a top margin, you can use this command:

p:first-child {margin-top: 0;}

Here is another example in which the selector matches the very first li element in lists.

li:first-child { color:blue; }

slide 6 of 6

Conclusion

Internet Explorer 7.0 supports quite a few new CSS commands and also fixes many CSS bugs. By using CSS commands, you have more control over your HTML and it makes your job easy. It is expected that more CSS commands will be created soon that will help developers add extra functionality to their HTML work.