strong that is a child (not just a descendant) of h1
adjacent sibling selector
h1 + p {margin-top: 0;}
paragraph that immediately follows an h1 element
Class Selector
<p class="warning">This is a warning </p>
Selector
Declaration
*.warning
{font-weight: bold;}
ID Selectors
(can only be used once)
<p id="warning">This is a warning </p>
Selector
Declaration
*#warning
{font-weight: bold;}
Attribute Selectors
h1[class] {color:silver;}
<h1>Hello</h1> /* this would not silver */
<h1 class="blah1">Hello</h1> /* this would silver */
<h1 class="yah2">Hello</h1> /* this would silver */
a[href="http://www.w3.org/"] /* look for exact attribute value */
p[class~="warning}] {font-weight: bold;} /* partial attribute - would work on following */
<p class="urgent warning">Very Important!</p>
*[lang|="en"] {color: white;} /*matches any lang attribute that betgins with 'en'*/
<h1 lang="en">Hello!</h1> /* matches */
<h1 lang="en-us">Hello!</h1> /* matches */
<h1 lang="uk-en">Hello!</h1> /* doesn't */
pseudo-classes
:link - any anchor that is a hyperlink (i.e. has an href attribute) and points to an address that has not been visited.
:visited - any anchor that is a hyperlink to an already visited address
:focus - any element that currently has input focus
:hover - any element which mouse pointer is over
:active - element that has been activated for user input (i.e. hyperlink that user is clcking on during time the mouse button is held down
:first-child - something that is the 1st child of something else (i.e. p:first-child {font-weight: bold;} matches p when it is the first-child of something else
:first-letter
:first-line
:before - h4:before {content: "yada"; color: silver;} - See example linked above
:clamp - The clamp() CSS function clamps a value between an upper and lower bound. clamp() enables selecting a middle value within a range of values between a defined minimum and maximum. It takes three parameters: a minimum value, a preferred value, and a maximum allowed value. The clamp() function can be used anywhere a <length>, <frequency>, <angle>, <time>, <percentage>>, <number>, or <integer> is allowed
Things get inherited. Below the <em> will still be gray
h1 {color: gray;}
<h1>Blah <em>Here</em></h1>
Most box-moddel properties do not get inherited.
Specificity Sorting Rules
For all rules that match a given element:
!important rules trump those that are not. In order:
Reader important declarations
Author important declarations
Author normal declarations
Reader normal declarations
User agent declarations
Higher Specificity has more weight than lower specificity (0,1,0,0 wins over 0,0,1,0).
Later declarations have more weight then prior ones. Imported style sheets are considered to come before all declarations in style sheet that imports them.
Note: Non-CSS hints (i.e. the font element) have specificity of 0 and are treated as if they appear at the beginning of the author's style sheet. They can be oveerridden by author or reader styles, but not by user agent's styles.
Color
17 named colors in CSS2.1 (HTML4.01 + orange)
aqua
black
blue
fuchsia
gray
green
lime
maroon
navy
olive
orange
purple
red
silver
teal white yellow
in something like
h1 {color: rgb(50%, 50%, 50%)}
you can have
rgb(50%, 50%, 50%) or rgb(128, 128, 128) or #808080 or
#567 which is shorthand for
#556677
"web-safe" colorsafe colors that avoid dithering 256-color computer systems. multiples of RGB vlues 20%, 51 or hex-pair value 33.
Length Values
Absolute Length Units - Inches (in), Centimeters (cm), Milimeters (mm), Points (pt), Picas (pc). Traditionally there are 72 points to an inch. A pica is equivalent to 12 points. There's nothing to say that the monitor will have a size and resolution that match up your expected measurements.
Relative Lengths
em - font-size for a font. For example if a font-size is 14 pixels, then 1em = 14 pixels
ex - the height of a lowercase x in the font being used (in points).
px - pixels. Remember that there's nothing to say that a monitor will have a size and resolution that match up your expected measurements. Also, printers commonly re-scale pixel lengths to something more sensible.
Recommendation is to use em and px where appropriate.
vw and vh are length units representing 1% of the viewport size for viewport width (vw) and height (vh), respectively
1 rem equals the font size of the html element (which for most browsers has a default value of 16px).
URLs
@import url(subdir/blah.css);
@import url(http://www.dasite.org/dathings/special/things.css);
body (background: url(http://www.pix.web/picture1.jpg) /* note no space between url and opening parens */
Keywords
none
different from 0
a: visited {text-decoration: none;}
inherit
forced inheritance
#toolbar a {color: inherit;}
Fonts
Generic Font Families
body {font-family: sans-serif;}
Serif - Proportional and have serifs.
Sans-serif - Proportional wihout serifs
Monospace - Non-proportional
Cursive - attempt to emulate human handwriting.
Fantasy - totally different fonts, such as Western, Woodblock, and Klingon.
Specific Font Families
h2 {font-family: Georgia;)
Can list general after specific. This allows general to apply if specific is not available.
h2 {font-famiy: Arial, sans-serif;}
This one goes through all the fonts in order until it gets a match
p {font-family: Times, TimesNR, 'New Century Schoolbook', Georgia, 'New York', serif;} /* use single quotes, not double if necessary*/
Font Weights
Every number corresponds to a weight at least as heavy as the number that precedes it.
strong {font-weight: 700;}
em {font-weight: bold;}
100
see 300
200
see 300
300
If 300 unassigned, given next variant lighter then 400. If no lighter variant available, 300 assigned same variant as 400 (usually "Normal" or "Medium"). Method also used for 200 and 100
400
normal
font variants labeled "Normal", "Regular", "Roman", "Book"
 
500
font variants labled "Medium
If unassigned, given same font weight as 400
600
if unassigned, given next variant darker then 400. If no darker varieant is assigned, then given same variant as 500. Method also used for 700, 800, 900
700
bold
See 600
800
See 600
900
See 600
bolder
selects lowest number that corresponds to font weight darker than what was inherited
ligher
selects highest number that corresponds to font weight lighter than what was inherited
Font Size
xx-small, x-small, small, medium, larg, x-large, xx-large, - 1.5 scalling factor in CSS1, 1.0-1.2 scalling factor in CSS2
smaller, larger - same scaling factor as above
<length>, <percentage>
inherit
set to em square relationship
Percentages and Sizes
body {font-size: 15px;}
p {font-size: 12px;}
em {font-size: 120%;}
strong {font-size: 135%;}
small, .fnote {font-size: 75%;}
italic - separate font face, small changes made to structure of each letter to account for altered appearance.
oblique - simply slanted version of normal upright text
inherit
p {font-style: normal;}
em {font-style: oblique;}
i {font-style:italic;}
Variations
small-caps, normal, inherit
An example of smallcaps (NOT LARGE CAPS)
Font property
Can be used to group all other properties
h1 {font: normal bold italic 30px sans-serif;} last 2 values must be font-size and font-family in that order
Line Height
Separate from font-size. Added to font-size value, with a forward slash
h2 {font: bold itaclic 200%/1.2 Verdana, Helvetica, Arial, sans-serif};
System Fonts
button {font: caption;}
button: caption; font-size: 2em;}
caption
font used for captioned controls, such as buttons
icon
font used to label icons
menu
font used in dropdown menu and menu lists
message-box
font used in dialog boxes
small-caption
font used for labeling small controls
status-bar
font use din window status bards
Indenting
p {text-indent: 3em;}
p {text-indent: -4em; padding-left: 4em;}
When in the course of human events, it becomes necessary to try to remember the Gettysburg address, sometimes one must go to the book, and look it up. Sometimes one has a good memory, but sometimes not. A third line....
p {text-indent: 10%;} /* percentages calculate on parent element's width */
Horizontal Alignment
left, center, right, justify, inherit
p {text-align: right;}
Vertical Alignment
line-height includes content-area (which is usually font size) plus leading area (half on top and half on bottom
line-height value is inherited from parent
p.cl2 {font-size: 10 px; line-height: 14px;}; /* extra leading area - 2px above and 2px below */
none, underline, overline, line-through, blink, inherit
text-decoration is not inherited. State everything explicitly in child elements.
p.overlined {text-decoration: overline;}
<p style="width: 200px; padding: 10px; margin: 20px; border: 1px solid grey; background-color: silver"> - visible element box is 220px (add padding left and right). Margins extend another 20px
Horizontal Properties
margin-left
border-left
padding-left
width
padding-right
border-right
margin-right
only width, margin-left, and margin-right can be set to
auto. Everything else has to be set or takes default value of zero. Auto means use length required to make element boxes width equal to parent element's width (even if a negative number results).
<p style="width: 200px; margin-left: auto; margin-right: auto; margin-top: 0; border: 1px solid grey; background-color: silver"> - right and left auto center's the element in it's parent. 'text-align' only applies to inline content of block-level element
text-align
This most excellent paragraph assumes the style text-align: left;
This most excellent paragraph assumes the style text-align: right;
This most excellent paragraph assumes the style text-align: center;
This most excellent paragraph assumes the style text-align: justify;
only height, margin-top, and margin-bottom can be set to auto. Everything else has to be set or takes default value of zero. Auto means - use length required to make element boxes width equal to parent element's width (even if a negative number results).
If height is not tall enough for text, browser is supposed to provide means of viewing all content without increasing height of element box. Scrollbars are an option.
If height is not tall enough for text, browser is supposed to provide means of viewing all content without increasing height of element box. Scrollbars are an option.
By default; block-level auto-height, normal-flow element with block-level (only) children only goes to top or bottom border. If you put in padding or borders then this changes to outer margin edges.
The initial div with a paragraph that just rambles on, but demonstrates a pretty cool look punching out of it's parents. Things just keep going and then hopefully soon, something punches out. Very soon that is. Do we have enough text yet?
When man looks for a quote, it should stand out. Remember that great things are said in a manner that catches the eye.
Ongoing original ideas are captured in the original paragraph. There is nothing that is punched out, it is merely rambling text with nothing much to say. It is true that often you want to say something, but you are really just setting up the next element
Look at me! I'm important in what I say! At least I think I am as I am presented this way. It's not too hard to comprehend why I'm like this.
List Items
Can be inline or outside of content depending on value of list-style-position
Inline Elements
Anonymous text - string of characters not contained within an inline element. For <p>I'm <em>so</em> happy!</p>
"I'm" and " happy!" are anonymous text.
By default, things are generally vertical-aligned at the bottom of the inline-box.
Thus, demonstrating style="vertical-align: top"
When in
the course
of
human
events,
it becomes
necessary
vertical-align
vertical-align can take the following keywords:
top
bottom
text-top
text-bottom
middle
super - (distance not specified and may vary by user agent)
sub - (distance not specified and may vary by user agent)
<percentage>
line-height
Best way to keep line-height for different size fonts from overlapping is to set line-height; 1. This becomes a scaling factor.
This is a paragraph with a 14px font and a line-height of 1. Now we add a font that's 250% bigger, just to show how the line-height scales.
Hey look - it's a span with box properties - in particular a border...
This is a paragraph of font-size: 15px; line-height: 1em;. And now we have span with background: #999; padding-top: 3px; padding-bottom: 3px;" that overlaps things. Especially, if we have a paragraph that continues on.
Inline replaced elements
Like img's. They pretty much respond based on their bounding box as you would expect. Bottom of box is vertical-aligned to the baseline.
inline-block - formatted within a line as a replaced element. Bottom of inline-block element will rest on baseline of text line by default, and will not line-break itself.
div#navigation a {display: block;}
<div id="navigation">
<a href="first.html">first on the list</a>
<a href="second.html">second...</a>
<a href="third.html">and so on.</a>
</div>
own - well, that's the challenge of it all - thinking on your own.
When in the course of human events, it becomes necessary for one people to sometimes think on their
inline-block paragraph doesn't seem to show up correctly in firefox or ie
<p style="border: 1px dotted; display: inline-block; width: 6em; text-align: center;">
own - well, that's the challenge of it all -
another test couple of words
thinking on your own.
Run-in Elements
And here we have the run-in element which makes block-level elements an inline part of the following element. Hopefully it works in the browser or UA you are using.
border-style
Also border-top-style, border-right-style, border-bottom-style, border-left-style.
none
hidden - same as none but used for tables and border-conflict resolution
dotted
dashed
solid
double
groove
ridge
<a style="border-style: outset; text-decoration: none;" href="http://www.w3c.org"> could yield a raised button W3C
shorthand is T R B L again.
border-style: solid dashed dotted none -
A very short paragraph with only a couple of lines, and not much else, just a couple of lines that run on and on. Now we're really done. Really.
border-width
Also border-top-width, border-right-width, border-bottom-width, border-left-width.
thin
medium
thick
<length>
inherit
ADD PADDING TO OTHER A LINKS BESIDES HOVER
border-color
Also border-top-color, border-right-color, border-bottom-color, border-left-color.
<color>
transparent
inherit
Transparent borders
Border with no style has no width. Invisible border can be created with color value transparent. This might not work correctly IE.
border-top, border-right, border-bottom, border-left let you shortcut color style and width. For example h3 {border-bottom: thick solid gray; text-decoration:none;} will get you -
This is an h3 with a border
border
Global border settings can be shorted handed. For example, h3 {border: thick silver solid; text-decoration:none;}
will get you:
h3 style with a global border
Note you can override a global setting with a particular setting i.e. border-left after a border setting.
When you apply borders to inline elements line height doesn't change, so you may get overlapping. Left and right will displace text around them to make way however.
Padding
TRLFis shortcut order
Also padding-top, padding-right, padding-bottom, padding-left.
<length>
<percentage>
h2 {padding: 10px 0.25em 3ex 3cm; background: silver; border: 1px solid black;}
will get you
An h3 with irregular padding
When you apply padding to inline elements left and right sides push text aside, however it is not applied to the right and left side of each line. Line height isn't changed of course, but since padding does extend the background, and is
You can
visible, it ends up overlapping the lines that come before.
Padding (in this case - background: green; padding: 1em;) is supposed to work with replaced elements such as but sometimes has issues. More importantly form elements can be represented differently with padding.
Color notes
#navbar a {color: yellow;} - All links in the #navbar will be yellow
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
The text next to here. And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
Note that background images are not inherited by default
It's a good idea to put in a background color in addition to the image, in case the image fails to load for some reason, or has some transparency built into it.
The text next to here. And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background.When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background.When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background.
background-position
[<percentage> | <length>] | left | center | right
[<percentage> | <length>] | top | center | bottom
background-position: left center;
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
p {background-position: right top;}
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
background-position: 25% 0%;
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
background-position: 0% 75%;
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
background-position: 75% 75%;
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
If you supply only one value it is assumed to be the horizontal value. Vertical is then assumed to be 50%
background-position: 20px 30px;
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
background-position: -20% -20%; (with bigger image)
Consider staying away from % values. They line up the percentage alignment point of the image with the percentage alignment point of the block. If things are different sizes, you will get different alignments.
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
background-position: center center; background-repeat: repeat-y;
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
background-position: center center; background-repeat: repeat;
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
background-position: left top; background-repeat: repeat;
And here's a paragraph of words that make up sentences. Funny how it works that way. Of course if it didn't work that way, we wouldn't be able to speak modern languages.
background-attachment
scroll - scrolls and is placed relative to content - this is the default value
fixed - scrolls and is placed relative to window - click
here or
here for examples. A great example is here. This effect could be used for watermarking, and should print correctly, as each printed page becomes a viewport.
inherit
background
Can take all more detailed background keywords in one thing (like font properties). For example:
body {background: white url(smiley-small.png) top left repeat-y fixed;}
Keywords can go in any order, accept that the 2 values for background-position (top left) have to be together (and sometimes in horizontal first, then vertical).
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up.
Mary, Mary, quite contrary, how does your garden grow. All, wild and free, it's plain to see, that I have no roses to sow.
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up.
You must always declare a width in a nonreplaced element, or it will tend to the minimum it can be (i.e. 1 character wide).
'A floated element's containing block is the nearest block-level ancestor element'. (quoted from Eric Meyer's CSS book).
1When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have 2enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up.
1When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. 2Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. 3Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up.
1When in the course of 2human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up.
When in the course of human events, it becomes necessary12345 to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background. When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up.
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background.
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background.
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background.
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up.
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background.
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background.
A Fractured Title
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up. AAA will sometimes call to the rescue, if you call them soon enough. Hopefully we have enough text to show the smiley in the background.
When in the course of human events, it becomes necessary to keep typing something that might just mean something, well then things get messed up.
A H3 heading.
This is an unfloated paragraph the contents of which should flow past the floated image which precedes it in the document.
In this case, the floated image has been set to float left, and it has it's topand left margins of -15px. This will cause it to actually float up and out of it's parent element, which is the DIV that enclosed the image and these paragraphs.
clear
Clear one of more sides of floated elements so that text doesn't flow past it.
left
right
both
none
inherit
This is an unfloated paragraph the ontens of which should flow past the floated image which precedes it in the document.
An h4 title
In this case, the h3 title has a clear: left; in it's stytle
Define where element boxes appear relative to where they would normally appear,, or relevent to parent element, another element, or browser window.
Please note that the descriptions below are paraphrased pretty closely to what is in Eric Meyer's book.
static - generated as normal.
relative - element box offset some distance. Elements retains shape it would have if it were not positioned, and space that element would ordinarily ocuppy is preserved.
absolute - element's box is removed from flow of document and positioned with respect to containing block. Original space that would have been occupied in normal document flow is closed up. Most commonly used for DHTML.
fixed - like absolute, but containing block is browser viewport. It does not scroll at all with the window, but appears to overlay it. IE6 doesn't support this.
In order to force the container block local - make it position: relative (or maybe one of the other ones) which will make all the elements inside of it use it as the containing block.
content edge of nearest block-level, table cell, or inline-block ancestor box
non-root
absolute
ancestor with position value other then static
ancestor - block-level - containing block is element's padding edge
ancestor - inline-level - containing block is cotent edge of ancestor.
ancestor - none - containing block is initial containing block
top, right, bottom, left
<length>
<percentage>
auto - note that auto is different than 0. It puts the position where it should be if there was a normal flow. If there is a conflict with left, right, and width - right is ignored and put to auto. If top, bottom, and height conflict - bottom is ignored and put to auto.
See the squares on the page. More stuff about absolutely nothing, in order to show that the text goes under the positioned square. Not like a float. A float would wrap around the box, while this does not. Some of this text should be covered.
See the squares on the page. More stuff about absolutely nothing, in order to show that the text goes under the positioned square. Not like a float. A float would wrap around the box, while this does not. Some of this text should be covered.
Not if I see you first. Hello. Not if I see you first. Hello. Not if I see you first. Hello. Not if I see you first. Hello. Not if I see you first. Hello. Not if I see you first. Hello.
Not if I see you first. Hello. Not if I see you first. Hello. Not if I see you first. Hello. Not if I see you first. Hello. Not if I see you first. Hello. Not if I see you first. Hello.
<html>
<head>
<style>
img {
position: absolute;
left: 0px;
top: 0px;
z-index: -1;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<img src="img_tree.png">
<p>Because the image has a z-index of -1, it will be placed behind the text.</p>
</body>
</html>
object-fit -position
used with <img> | <video>
object-fit
fill -resized to fill given dimension
contain -keeps aspect ratio
cover -keeps aspect ratio, clipping overflow
scale-down -smallest version of none or contain
none -not resized
object-position
xy coords e.g. object-position: 5px 10%;
Tables
Table Display Values
table
block-level table - like HTML element table.
inline-table
rectangular block that generates an inline box. No real close HTML element
table-row
like HTML element tr
table-row-group
an element that groups one or more rows. HTML equivalent is tbody
table-header-group
like table-row-group but always displayed before all other rows and row groups, and after any top captions. Printed, header rows may be repeated at top of each page. HTML equivalent is thead
table-footer-group
like table-header-group but at bottom. HTML equivalent is tfoot
table-column
declares an element that describes a column of cells. Usually not rendered. HTML equivalent is col
table-colomn-group
groups one or more columns. Usually not rendered. HTML equivalent is colgroup
table-cell
represents a single cell in a table. HTML elements thtd are expamples of table-cell elements.
In CSS, columns and column groups can only accept 4 properties:
border - can be set only when prperty border-collapse has value of collapse
background - will be visible only in cells where both the cell and its row have transparent backgrounds
width - defines minimium width
visibility - collapse causes none of the cells in the column to be rendered. According to the Meyer book 'A declaration of any value for visibility other then hidden for a column or column group is ignored.
caption-side
elements with display value table-caption (i.e. <caption> elements) can indicate that they should be displayed on:
top
bottom
Table Layers
Tables are displayed in layers.
Table
Column Groups
Columns
Row groups
Rows
Cells
For Example...
<table style="background: #333333;">
<caption style="color: green; caption-side: bottom;">table of colors</caption>
<colgroup>
<col><col style="background: #555555;"><col style="background: #555555;">
<colgroup>
<tr><td colspan=3>1st row - table color</td></tr>
<tr>
<td>table color</td>
<td>column color</td>
<td style="background: #AAAAAA;">cell color</td>
</tr>
<tr>
<td>table color</td>
<td>column color</td>
<td>column color</td>
</tr>
<tr style="background: #888888;">
<td>row color</td>
<td>row color</td>
<td style="background: #AAAAAA;">cell color</td>
</tr>
</table>
note that this does not always work cleanly (i.e. IE6). Use DIVs inside TDs or THs and set width (remember to take into account border and padding).
Click here for an example of table-layout and width.
Height
height: <height>
Alignment
vertical-align
top
bottom
middle
baseline (aligned with baseline of row; in the case of row-spanning cells - aligned with baseline of first row it spans; quoting Cascading Style Sheets The Definitive Guide by Eric A. Meyer (2nd edition) - "A row's baseline is defined by 'the lowest initial cell baseline (that is, the baseline of the first line of text) out of all it's cells").
<td style="border: 1px solid; background: silver; padding: 0; vertical-align: top; height: 10em;">
<div style="border: 1px dashed gray; background: white;">
The contents of this cell are top-aligned.
</div>
</td>
<td style="border: 1px solid; background: silver; padding: 0; vertical-align: middle;">
<div style="border: 1px dashed gray; background: white;">
The contents of this cell are top-aligned.
</div>
</td>
<td style="border: 1px solid; background: silver; padding: 0; vertical-align: bottom;">
<div style="border: 1px dashed gray; background: white;">
The contents of this cell are top-aligned.
</div>
</td>
#navigation
{width:100%; height:20px; background-color:#999;}
#navigation ul
{margin:0px; padding:0px 0px 0px 2px;}
#navigation ul li
{display:inline; height:20px; float:left;
list-style:none; margin-left:5px; width: 85px; position: relative;}
#navigation ul li a
{color:#fff; text-decoration:none;}
#navigation li a:hover
{color:#fff; text-decoration: none;}
/* sub menu */
#navigation ul li ul
{margin:0px; padding:0px; display:none; position: absolute; left: -2px;
top: 20px; background-color: #999;}
#navigation ul li:hover ul
{display:block; width: 90px;}
#navigation ul li ul li
{list-style:none; display:list-item; height: 15px; margin: 0px 3px 8px 3px;}
#navigation ul li ul li a
{color:#fff;; text-decoration: none;}
#navigation ul li ul li a:hover
{color:#000;; text-decoration: none; background-color: #fff;}
.chartlist li {
position: relative; (element box offset some position, retain original space)
display: block; (changing this also removes the bullets)
border: 1px solid aqua; (border put in to outline element)
}
.chartlist .count {
display: block;
position: absolute; (parent element li is relative. it becomes containing block)
(remove from flow of doc, pos with respect to containing block)
(original flow closes up)
top: 0;
right: 0;
margin: 0 0.3em;
text-align: right;
color: #999;
font-weight: bold;
font-size: 0.875em;
border: 1px solid orange; (border put in to outline element)
}
.chartlist li a {
display: block; (block takes up the entire line (within the li))
(pushes the .index span down)
position: relative; (element box offset some pos, retain original space)
(if this were absolute, space would close up,
and .index span would be next to the a element)
padding: 0.4em 4.5em 0.4em 0.5em;
z-index: 2; (raise it so it will always be visible)
border: 1px solid purple; (border put in to outline element)
}
<ul class="chartlist">
<li>
<a href="/fruits/apples/">Apples</a>
<span class="count">420</span>
<span class="index" style="width: 42%;">(42%)</span> (width style doesn't do anything for
spans (until we style it later))
</li>
<li>
<a href="/fruits/bananas/"> »
Bananas</a>
<span class="count">280</span>
<span class="index" style="width: 28%;">(28%)</span>
</li>
<li>
<a href="/fruits/cherries/"> »
Cherries</a>
<span class="count">200</span>
<span class="index" style="width: 20%;">(20%)</span>
</li>
<li>
<a href="/fruits/dates/">Dates</a>
<span class="count">100</span>
<span class="index" style="width: 10%;">(10%)</span>
</li>
</ul>
.chartlist .index {
display: block; (block normally takes up the entire line (within the li?)
we have set width so it does not)
position: absolute; (remove from flow of doc, pos with respect to containing block (li?))
(original flow closes up)
top: 0; (we're moving it up to the top of the containing block)
left: 0;
height: 100%; (set the width to 100% to fill the entire containing block (li?) with
the background color)
background: #B8E4F5;
text-indent: -9999px; (hide the actual percentage value (e.g. (42%)),
value still in for graceful degradation
overflow: hidden; (cuts off overflow text outside of containing block (li?)
may not be needed?)
}
.chartlist3 {
float: left; (have other elements flow around this if they exist)
border-top: 1px solid #EEE; (remove the other borders; style a dividing line)
width: 15em; (set the width so it is smaller on the page)
}
.chartlist3 li {
position: relative;
display: block;
border-bottom: 1px solid #EEE; (remove the other borders; style a dividing line)
_zoom: 1; (deal with the haslayout bug in IE)
}
.chartlist3 li a {
display: block;
padding: 0.4em 4.5em 0.4em 0.5em;
position: relative;
z-index: 2;
}
.chartlist3 .count { (the number to the right)
display: block;
position: absolute;
top: 0;
right: 0;
margin: 0 0.3em;
text-align: right;
color: #999;
font-weight: bold;
font-size: 0.875em;
line-height: 2em;
}
.chartlist3 .index3 { (the span percentage width)
display: block;
position: absolute;
top: 0;
left: 0;
height: 100%;
background: #B8E4F5;
text-indent: -9999px;
overflow: hidden;
line-height: 2em;
}
.chartlist3 li:hover { (add the hover with a background; now the entire <a element
background: #EFEFEF; (which is css'ed to a block element) hover highlights)
}
.timeline {
font-size: 0.75em;
height: 10em;
}
.timeline li {
display: block; (lose the bullet among other things)
height: 8em; (the height of the bar)
width: 1.5em; (the width of the bar)
position: relative; (set up for sub-elements)
float: left; (float it left so the next bar can be directly to the right)
margin: 0 0.1em;
border: 1px solid black; (just to outline the element)
}
.timeline li a {
display: block; (change the <a to be a block element)
height: 100%; (have it fill the entire containing element (li?)
now the entire block will be clickable)
}
<ul class="timeline">
<li>
<a href="/2007/dec/1/" title="December 1, 2007: 40">
<span class="label">1</span>
<span class="count" style="height: 40%">(40)</span>
</a>
</li>
<li>
<a href="/2007/dec/2/" title="December 2, 2007: 100">
<span class="label">2</span>
<span class="count" style="height: 100%">(100)</span>
</a>
</li>
<li>
<a href="/2007/dec/3/" title="December 3, 2007: 80">
<span class="label">3</span>
<span class="count" style="height: 80%">(80)</span>
</a>
</li>
<li>
<a href="/2007/dec/4/" title="December 4, 2007: 60">
<span class="label">4</span>
<span class="count" style="height: 60%">(60)</span>
</a>
</li>
</ul>
.timeline li .label {
display: block; (change from inline to block)
position: absolute; (remove from flow of doc, pos with respect to containing block (li?))
(original flow closes up)
bottom: -2em; (move it 2em below the container (li?))
line-height: 2em;
left: 0;
width: 100%; (make sure the width fills the container)
text-align: center;
border: 1px solid orange; (temporary border so we can see position)
}
When in the course of human events, it becomes necessary for one people under God do something absolutely fabulous. It becomes to do something absolutely special. Then it truly doesn't matter. a is the first letter in the alphabet B is the second season a third C is the third not season is the third but D is the fourth
Comma separated list
li.csv:not(:last-child):after{content: ','}
}
one
two
three
four
box-sizing
//The box-sizing property allows us to include the padding and border in an element's total width and height.
//If you set box-sizing: border-box; on an element, padding and border are included in the width and height:
If the browser window is 600px or smaller, the background color will be
@media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
img width and max-width
//responsive image...scales up and down
img {
width: 100%;
height: auto;
}
//img will scale down but will never scale larger than orig size...
img {
max-width: 100%;
height: auto;
}
//The box-sizing property allows us to include the padding and border in an element's total width and height.
//If you set box-sizing: border-box; on an element, padding and border are included in the width and height: