Understanding CSS

Hi, I have a basic understanding of how to create a website and web pages. However I still don’t fully understand the CSS coding.

Here is an example:

body {
	font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
	background-color: #4E5869;
	margin: 0;
	padding: 0;
	color: #000;
}

/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
	padding: 0;
	margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
	margin-top: 0;	 /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
	padding-right: 15px;
	padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
	border: none;
}

/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
	color:#414958;
	text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:visited {
	color: #4E5869;
	text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
	text-decoration: none;
}

/* ~~ this container surrounds all other divs giving them their percentage-based width ~~ */
.container {
	width: 80%;
	max-width: 1260px;/* a max-width may be desirable to keep this layout from getting too wide on a large monitor. This keeps line length more readable. IE6 does not respect this declaration. */
	min-width: 780px;/* a min-width may be desirable to keep this layout from getting too narrow. This keeps line length more readable in the side columns. IE6 does not respect this declaration. */
	background-color: #FFF;
	margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout. It is not needed if you set the .container's width to 100%. */
}

/* ~~the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo~~ */
.header {
	background-color: #6F7D94;
}

/* ~~ This is the layout information. ~~

1) Padding is only placed on the top and/or bottom of the div. The elements within this div have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.

*/
.content {
	padding: 10px 0;
}

/* ~~ This grouped selector gives the lists in the .content area space ~~ */
.content ul, .content ol {
	padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */
}

/* ~~ The footer ~~ */
.footer {
	padding: 10px 0;
	background-color: #6F7D94;
}

/* ~~ miscellaneous float/clear classes ~~ */
.fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
	float: right;
	margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
	float: left;
	margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
	clear:both;
	height:0;
	font-size: 1px;
	line-height: 0px;
}

I have used Google Chrome developer tools to check the layouts and even with all the notes (code from Dreamweaver template) I still don’t understand. Simply put I am trying to reverse engineer the coding…

I don’t know why “.” are placed on some codes.
I don’t know what “a:” do. (I’m guessing: add-on feature such as underline link when mouse hover)
I don’t know if there is coding order (I’m guessing that there is no order…)

Please help me start coding CSS

That represents a “class” selector. For example, if you want to make a paragraph red, you’d do something like this in HTML:

<p [color="#ff0000"]class="error"[/COLOR]>You made a mistake!</p>

… and then in your CSS, you do this:

.error {color: red;}

The dot + “error” means "apply this rule to the element with the class “error”.

I don’t know what “a:” do. (I’m guessing: add-on feature such as underline link when mouse hover)

That’s one of its uses. For example, if you want links to be red on hover, you’d do this:

a:hover {color: red;}

There is also a:visited, a:focus etc…

I don’t know if there is coding order (I’m guessing that there is no order…)

Not really, although you need to be a bit more specific.

Hi,

The order of links “:” is important and they need to be defined in a specific order.

There is always an order to CSS as the “C” in CSS stands for “Cascading” and styles will cascade through the document depending on their order in the stylesheet. If there are no conflicts then order is not important but that will rarely be the case.

You should read the section in the Sitepoint reference (I wrote this section :)) on the Cascade. It’s hard going but covers important concepts and should be followed up by reading on [URL=“http://reference.sitepoint.com/css/inheritancecascade”]specificity and inheritance. It’s not likely something you will grasp in a day but at least you will be aware of the concepts.

There is also a section on selectors (classnames (.) and ids(#) that you will find useful).

We can’t really teach you the whole of CSS in a single post so you may need to make more general questions and we can clear them up as we go.:slight_smile: