Example:
p ~ ol {border: solid 1px black;}
The General Sibling Selector is ignored by IE6
Chetan Crasta's XHTML, HTML and CSS Notes
p ~ ol {border: solid 1px black;}
h1 + p {background-color:green;}
div > p
#main p
ul li img
<img src="image.gif" alt="product" />
, you can use the following selector - [alt]
. This would select any element in the document with the img attribute. To only select img elements that have the alt attribute, you would use the element name with the attribute selector - img[alt]
.img[alt="button"]
.
Some attribute values have spaces in them. Such attributes can be selected by their partial attribute value. For example, the following XHTML element - <img src="images/rose.gif" alt="picture of the rose in sunlight" />
can be selected using the following CSS selector - [alt~="rose"]
.[src|="image"]
will select the following elements <img src="image-1.gif" alt="a rose">
<img src="image-2.gif" alt="a tulip">
a[href^="ftp:"]
will match all links that refer to FTP sites.img[src$="gif"]
.img[alt*="rose"]
will match <img src="image.jpg" alt="picture of a rose in a vase">
IE6 does not support Attribute Selectors.
IE7 does not support stand-alone Attribute Selectors - example: [alt]
will not work in IE7 but img[alt] will.
<p class="last_para">
. The class selector is simply the name of the class prefixed with a period (.). The class selector of the example above is .last_para
. Here is a CSS rule that uses a class selector:.last_para {background-color: gray;}
p.last_para {background-color: gray;}
<div class="main first observation">
.first.observation {font-color:red;}
<div id="nav_bar">
. The ID selector is just the name of the ID prefixed with the pound symbol (#). The ID selector in the above example is #nav_bar
. Here is a CSS rule that uses an ID selector:#nav_bar {float:right;}
div#nav_bar {float:right;}
p, div {background:#000000;}
.
The asterisk (*) is called the universal selector. The universal selector matches all the elements of a document.
h1, p {color:#000000;background:#ffffff}
p {color:red}
/* this is your comment */
. You can even have CSS comments in inline styles - <h1 style="color:blue;/* a comment */">
<link rel="alternate stylesheet" href="styles.css" type="text/css" title="serif font" />
<link rel="alternate stylesheet" href="style.css" title="serif font" media="screen" />
<link rel="alternate stylesheet" href="compactstyle.css" title="serif font" media="handheld" />
Note that all the style sheets referenced by the link tag are downloaded by the browser when the page is displayed even though all of them may not be used. This can add significant latency to the display of the page.
<link rel="stylesheet" type="text/css" href="styles.css" media="screen, print" />
<style type="text/css">
@import url(styles.css) screen, projection;
</style>
<style type="text/css">
@import url(styles/sheet1.css) screen, print;
p {font:62.5%}
</style>
<style type="text/css">
p
{
font-size: 1.6em;
}
</style>
An inline-level element is always contained in block-level elements. An inline-level element generates a box within a line of text. When the element box reaches the right margin, it breaks and continues from the left of the next line.
<p>This is a paragraph.</p>
<ol>
<li>Super item</a>
<ul class="sub">
<li><a href="sub1.html">Sub-item 1</a></li>
<li><a href="sub2.html">Sub-item 2</a></li>
<li><a href="sub3.htm">Sub-item 3</a></li>
</ul>
</li>
<li>Item 2
<ol>
<li>Sub-item1</li>
<li>Sub-item 2</li>
<li>Sub-item 3</li>
</ol>
</li>
<li>
<table border="border"><tr><td>row1item1</td><td>row1Item2</td></tr><tr><td>row2Item1</td><td>row2item2</td></tr></table>
</li>
</ol>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<ul>
<li>Item 1
<ul>
<li>Sub-item 1</li>
<li>Sub-item 2</li>
<li>Sub-item 3</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<link rel="stylesheet" href="alltags.css" type="text/css" />
pre
element is rendered exactly as it is in the HTML document, ignoring normal HTML whitespace and line wrapping rules. The text is rendered in monospace font.
Use this tag when you want the text to appear exactly the way it was entered in the document, or when you want the columns and rows of characters to always lineup in a particular way.
Tab stops are defined at every eighth character position but using tabs is unreliable. Therefore, it is better to use spaces to lineup characters.pre
element can contain any inline elements but not block-level elements. All special characters must be substituted with entity equivalents (example: < , > etc.).
<p>There are many inline content tags like <samp>kbd</samp>.</p>
<p>Enter the following text at the command prompt: <kbd>ping -n 1 -l 0 www.yourserver.com</kbd></p>
The acronym
element is a phrase element. This means that it is an inline element that adds semantic information to strings of text.
This tag is used to indicate that the enclosed text is an acronym. An acronym is a word made up of the the initial letters of a phrase - for example, HTML.
Just like the abbr
element, Firefox and Opera render the acronym with a dotted underline, IE7 and Safari render them normally.
The title attribute is useful here because it can contain the expanded form of the acronym. This expanded form will then be displayed when the user hovers the mouse over the acronym.
Example: <acronym title="internet service provider">ISP</acronym>
The abbr
element is a phrase element. This means that it is an inline element that adds semantic information to strings of text.
This tag is used to indicate that the enclosed text is an abbreviation. Firefox and Opera render the abbreviation text with a dotted underline, but IE7 and Safari don't.
Note: An abbreviation is a shortened form of a word or phrase. Whereas an acronym is a word formed of the first letters of a phrase. Example: OPEC
title attribute
The title attribute can contain the expanded form of the abbreviation.
Example: <abbr title="modulator-demodulator">modem</abbr>
When the mouse hovers over the abbreviation, the browser displays the expanded form as a tool-tip.
<title>The Page Name</title>
<h1><!-- This is a comment -->This is an h1 tag</h1>