Forum Moderators: not2easy

Message Too Old, No Replies

Why does the first command not work in this external style sheet?

         

Baxter30

2:37 am on Dec 2, 2008 (gmt 0)

10+ Year Member



I'm very new to css, just begining to learn the basics. I have constructed this simple external style sheet but for some strange reason which ever command I place first does not work.

<style type="text/css">

h1 {
color:red;
background-color:blue;
font-weight:bold;
}

h3 {
color:blue;
font-weight:bold;
}

</style>

Any idea why?

encyclo

2:56 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<style type="text/css"> 

If the above is included in the external stylesheet, then remove it - the stylesheet should contain CSS only, no HTML. Same goes for the closing

</style>
tag.

Baxter30

3:18 am on Dec 2, 2008 (gmt 0)

10+ Year Member



OH, well thats emberassing. Like I said im new.

Thanks a lot man.

swa66

9:28 am on Dec 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



well thats emberassing

Don't be. Many of us tried things like that over the years, both by accident and by ignorance.

From an education viewpoint the reason why it fails is that the "

<style type="text/css">
" is being considered part of the first multi-line (together with the "
h1
") selector. Since it's syntax is off, the entire entry isn't going to be used.

To find these errors the CSS validator [jigsaw.w3.org] helps a lot. Whenever you have errors like this, check your CSS (and html [validator.w3.org]) .

Baxter30

8:30 pm on Dec 3, 2008 (gmt 0)

10+ Year Member



The syntax does seem to be much more important in these newer codes.
I miss good old fashion HTML were everything is much more forgiving.

Thanks for recomending the validator. I'll probly be useing it a lot in future ventures.

swa66

2:09 am on Dec 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It actually is rather forgiving. it mostly not understanding your first selector and not finding a match for whatever it made of it. (remember that line breaks are allowed in there)

Basically is sees:


<style type="text/css"> h1 {
color:red;
background-color:blue;
font-weight:bold;
}

It won't find a h1 with a parent that resembles to anything like that, hence the rule doesn't get used.