The page is dedicated to all those CSS solutions I have found over time
that I never wanted to lose track of. Some really great stuff here,
Enjoy! Below you will see a mixture of both links and code.
/* Firefox Picks Up The !important IE 6 and 7 do not
*/
#FireFux {
width:100px !imporant; width:50px;
}
Selecting a child
tr:nth-child(2n+1) - Represents every odd row of an HTML table
tr:nth-child(odd) - Same
tr:nth-child(2n+0) - Represents every even row of an HTML table */
tr:nth-child(even) - Same
p > span - A span element child of an p element
E:nth-child(n) /* An E element, the n-th child of its parent
div > p:first-child /* Represents the p element that is the first child of a div element
The last P before the note.
The first P inside the note.
ol > li:last-child - Represents a list item li that is the last child
of an ordered list ol.
Drilling down further
tr > td:last-of-type Represents the last data cell td of a table row tr.
p::first-letter { color: green; font-size: 200% } - first letter of each P element will be green with a font size of '+200%'.
div p *[href] - represents an element that (1) has the href attribute set and (2) is inside a p that is itself inside a div:
Selecting an element that contains a class
p.classy - Selects any paragraph element with class classy.
Learn more about selectors at w3.org. See a bunch of great examples on their tests page.
1
2
3
1
2
3
The style: #testy p:nth-child(2) {background-color:#ff0000;
color:#ff0000;}
How to Center an Image with CSS
Set the image to a block level element then do margin auto. Below you will see an image horizontally centered image within a div.
Remove Grey Dotted Border using CSS
Remove the grey dotted border around image links for both IE 8 and Firefox using CSS.
/* No selectors needed - Removes grey dotted border around focused links IE8/FF */
:focus {outline:none;}
::-moz-focus-inner {border:0;}
* The above is a anchor link styled with a background, padding, etc to look like a button
Search icon to an input field
.search {
padding:3px 6px 3px 20px;
width:275px;
font-size:14px;
background-image: url("image/searchinput.gif");
background-position: -2px 3px;
background-repeat: no-repeat;
}
Different States of
a link to be applied to a class:
a.linky, a:hover.linky, a:active.linky, a:visited.linky
{color:FF0000; font-weight:bold;}
OR defining links for an entire page
a:link, a:visited, a:active, a:hover {color: #FF0000;}
OR defining links for a specific DIV ID
#LinkDiv a:link, #LinkDiv a:visited, #LinkDiv a:active, #LinkDiv
a:hoover {color: #FF0000;}
Double
Class:
You can in fact apply two classes to the same element. Thought I would
share since I tried going about this the wrong way. Thanks Josh.
Blah Blah Blah
Multiple Columns with CSS
Easy to implement and cross browser, cross platform compatible.
Make sure that you include <div
style="clear:both;"></div> after your columns so that
subsequent information is displayed below your "table" and not to the
right or left. (Thank
you Maria!)
Positioning of
Background Image - Several Roll Over Type Effects Using CSS (Sprites):
*Using just one image and shifting it around. Click here to view background image.
Content Here.
0 = Vertical
Auto = Horizontal Centering
#CenterMe2 {
width:500px;
margin: 0 auto;
border:1px solid #FF0000;
text-align:left;
}
IE is retarded so you have to use the text-align:center; tag
on the outside div then text-align:left; on the inside div
Method 2:
body {margin:0px; padding:0px;}
#CenterMe {
position:absolute;
left:50%;
width:500px;
margin-top:50px;
margin-left:-250px; /* Set to half width. */
padding:15px;
border:1px dashed #333;
background-color:#eee;
}
body {margin:0px; padding:0px;}
/* You should set body margin and padding 4 browser consistency. */