Newbie question re: CSS

R

Rob Ireland

Hey there all!

I'm just starting to learn CSS, in preparation for my new web site,
and I'm trying to figure out how to reference a CSS element in a
(HTML) web page.
I've found several web sites that explain the basic concept of how
they work, and some of the common syntax, but I can't seem to find any
reference to how to link specific Style elements in the HTML code to the
CSS.
Does anyone know of a site that will 'walk me through' this process?


Thanx in advance :)
 
A

Adrienne

Gazing into my crystal ball I observed Rob Ireland
Hey there all!

I'm just starting to learn CSS, in preparation for my new web site,
and I'm trying to figure out how to reference a CSS element in a
(HTML) web page.
I've found several web sites that explain the basic concept of how
they work, and some of the common syntax, but I can't seem to find any
reference to how to link specific Style elements in the HTML code to the
CSS.
Does anyone know of a site that will 'walk me through' this process?


Thanx in advance :)

External:
<link rel="stylesheet" type="text/css" href="mystylesheet.css">

On the page:
<head>
<style type="text/css">
....
</style>
</head>

Inline style:
<p style="text-indent:1em">...</p>

http://www.w3schools.com is a good place to start.
 
E

Ed

Adrienne said:
Gazing into my crystal ball I observed Rob Ireland
<[email protected]> writing in @news20.bellglobal.com:
There are three basic things you can do with CSS. First, you can
redefine HTML tags:

P {color: #CCC}

Then, the contents of your <p> tags will show up gray. No further
intervention is necessary.

Secondly, you can define classes. These are styles that can be
refferenced using class="whatever":

..content {background: #000}

In your html: <td class="content"> will make the cell background black.

Finally, you can use IDs. These work very much like classes, but
generally are used if you have one of that particular element per page.

#navbar a:hover {color: #F00}

In your HTML: <td id="navbar"> will make the links show red when you
hover over them with your mouse.

Hope this helps.
 
R

rf

Er, G'day.

You don't. You do it the other way round. A CSS rule (what you might think
of as a style) "selects" the HTML elements to which it applies.

Very heavy going but by far the best place is the CSS specifications
themselves.

http://www.w3.org/TR/REC-CSS2/

and specifically the chapter about selectors:

http://www.w3.org/TR/REC-CSS2/selector.html
There are three basic things you can do with CSS. First, you can
redefine HTML tags:

Nope. One does not "redefine HTML tags", one "selects HTML elements to which
this style rule applies".
P {color: #CCC}

Then, the contents of your <p> tags
elements

will show up gray. No further
intervention is necessary.

Secondly, you can define classes. These are styles that can be
refferenced using class="whatever":

Nope. Once again it is the other way round. . The HTML element does not
"reference" the CSS. HTML knows nothing at all about CSS. CSS does, however,
know about HTML.

A class attribute (a series of words) is specified for the HTML element. The
CSS rule selects HTML elements who have a specific value somewhere in their
class attribute.

In fact the selector
p.content
is really only a shorthand way of writing the more general attribute
selector
p[class~=content]
(note the ~ in there)

One could just as readily select elements that have a title attribute of
exactly "jim":

p[title=jim]

Even more generally one can, for example, specify an elements class
attribute like
class="copyright unimportant"
and have different CSS rules that select that element:

..copyright {background-color: black; color: white}
..unimportant {font-size: 95%}

The important thing is that the CSS rules are selecting the HTML elements.
.content {background: #000}

In your html: <td class="content"> will make the cell background black.

Finally, you can use IDs. These work very much like classes, but
generally are used if you have one of that particular element per page.

#navbar a:hover {color: #F00}

In your HTML: <td id="navbar"> will make the links show red when you
hover over them with your mouse.

<grin>You should not be using tables for layout</grin>

Hope that helps :)

Cheers
Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top