Forum Moderators: not2easy

Message Too Old, No Replies

Inlining CSS into the body and using the <!-- and -->

Do I need to use it? Can anyone please help me?

         

frenzy77

1:07 pm on May 5, 2004 (gmt 0)

10+ Year Member


Hello everyone:)
I'm new here.

I have a couple of questions regarding inlining CSS
into the body of a page and using the
<!--
and -->

(for hideing the CSS from browsers that
do not support it.)

Q. 1. Do you need to include them when
inlining CSS into a page for each individual selector,
and declaration?(to hide it from browsers that do not support it)

Ex. <p style="font-family: verdana; color: red;">

Q. 2. If needed, how do you do it for this example?
Please explain and show an example if it is needed to
do this.

Q. 3. If it was needed, is this the right way for
each individual selector and declaration on a page?

Ex.
<!--
<p style="font-family: verdana; color: red;">
--></p>

****This is just a guess.

Q. 4. Will it display properly without it? How will it display in browsers that do not support it? Will it look ok?

I hope you don't need them when inlining CSS into
the body of a page. I'm new to CSS and inlining and they might be dumb questions but
I want the text to display properly on my pages.

Can anyone please help me?
Please address each question.

Thank you to all:)

frenzy77

encyclo

1:13 pm on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must not use comments when placing inline styles in a <foo style="whatever;"> block, as this will mean that no browser will read them.

As for using comments for a style block between a <style type="text/css"> and </style> tags, it is not usually necessary, but you may want to do so if you have an abnormally-high number of visitors using very ancient browsers (read Netscape 2).

If you are using XHTML rather than HTML, then you should never use comments to hide styles.

DrDoc

2:53 pm on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Excellent explanation, encyclo! :)

sonjay

2:25 am on May 6, 2004 (gmt 0)

10+ Year Member



You got your answer about how to do the inline styles -- but keep in mind that in general it's good practice to put your styles into an external style sheet that you link to, as opposed to using inline styles. It makes it much easier to use consistent styles across all pages of your site. My practice is to never use an inline unless I'm absolutely positive I will never need to use that style anywhere else in the entire site.

For example, if you envision that you might want a red Verdana paragraph anywhere else in your entire site -- and particularly if you'll want that red Verdana paragraph in a lot of places -- use an external style sheet. Create a class in your style sheet called, oh, let's call it .redver Then in your paragraph you put <p class="redver"> And everywhere in your entire site you can use <p class="redver"> and you'll get exactly that same style, every time.

Suppose later on you decide that all red Verdana paragraphs should also be bold..... With inline styles, you have to find every instance of <p style="font-family: verdana; color: red;">, everywhere in your site, and change it. With a linked stylesheet you just add font-weight:bold to your style declaration for redver.

Using CSS is better than littering your pages with font tags, but using lots of inline styles really isn't much, if any, improvement over font tags.