A CSS comment begins with /*, and ends with */ (C-style)
h1[class] {color: yellow;} - selects any h1 element with a class attribute
img[alt] {border: 3px solid red;} - selects any img with an alt attribute
*[title] {font-weight: bold;} - selects any element that has a title attribute
a[href="http://php.net"][title="home"] {font-size: 300%} - selects any anchor with those specific href and title
p[class~="warning"] {font-weight: bold} - same as p.warning {font-weight: bold}
img[title~="Figure"] {border: 1px solid black} - selects any img with Figure in the title
[foo^="bar"] - selects any element with attribute foo whose value begins with bar
[foo$="bar"] - selects any element with attribute foo whose value ends with bar
[foo*="bar"] - selects any element with attribute foo whose value contains bar
[lang|="en"] - selects any element with lang attribute = en or begins with en-
h2, p {color:gray;}
Suppose you have:
tr.sidebar {background: blue;}
tr.main {background: white;}
Both blocks have links
tr.sidebar a:link {color: white;}
tr.main a:link {color: blue;}
Now links in the sidebar are white and links in the main block are blue
Any a:link, no matter how deeply nested will be selected. This is not true of child selectors
ul > em {color:red;} will only be selected at a nesting level of 1
h1 + p {color:red;} selects a p which follows an h1 if the h1 shares a parent with the p. i.e. a body parent
* {color:gray;}
This makes every single element in the document gray
h1 {font: 18px Helvetica; color: purple; background: aqua;}
h1, h2, h3, h4, h4, h6 {color: gray; background: white; padding: 0.5em;}
*.warning {font-weight: bold;}
<p class="warning">
(* is universal selector, . is class selector)
.warning {font-weight: bold;}
<p class="warning">
(* can be ommited)
p.warning {font-weight: bold;}
<p class="warning">
.warning.urgent {background: red;}
(class attribute must contain both warning and urgent to match)
<p class="warning urgent">...
Preceeded by an octothorpe (#) instead of a period (.)
Each ID value can only be used once within a document
*#first-para {font-weight: bold;}
<p id="first-para">
#first-para {font-weight: bold;}
(* can be ommited)
Based on state. i.e. links can be visited or not.
:link :visited :hover :active :focus :first-child
All pseudo-class and pseudo-element keyword are preceded by a colon.
Pseudo-classes can be combined in the same selector
a:link:hover {color: red;}
a:visited:hover {color: maroon}
makes unvisited links red when they're hovered but visited links maroon when they're hovered
p:first-letter {color: red;}
p:first-line {text-decoration: underline}
NOTE: Only certain properties are permitted on first-letter and first-line
h1:before {content: "**"; color: silver;} - inserts the generated content
body:after {content: " The end.";} - inserts the generated content
top right bottom left
top left/right bottom
top/bottom left/right
all four
Border shortcut:
size style color
style must be present
Only width and margin can be set to auto
If both margins are set to auto, they are set equal
If one margin and width are set to auto, that margin is reduced to zero
If all three are set to auto, both margins are reduced to zero
Borders cannot have percentage widths
If an auto-height, block-level, normal-flow element has only block-level children, the topmost child's margin and the bottommost child's margin will stick out past the parent containing block element unless that element has either top/bottom padding or top/bottom borders.Adding just a 1px border or 1px of padding is sufficient to cause the height to expand and contain the child's margin. (a border will show, padding will take the color of the element)
![]() |
This site best viewed with a browser |
| Warning: This is a Debian centric site | |
| Many thanks to Debra and Ian Murdock for making Debian possible | |
| First created Apr 22, 2008 ~ Last revised June 13, 2010 |