Forum Moderators: not2easy

Message Too Old, No Replies

Styling Includes (ASP)

Is it possible to style included files?

         

webworker us

6:12 pm on Jun 21, 2005 (gmt 0)

10+ Year Member



I'm working on a new Intranet page for our company, and I wasn't sure if it was possible or not to use CSS on the site's included files. What happens is the departments update their portions of the site in Word (sigh) and then its all brought together with ASP.

Thanks

createErrorMsg

6:34 pm on Jun 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



webworker, welcome to WebmasterWorld!

If the ASP output is HTML code, containing HTML tags, you absolutely can use CSS to style it. CSS's only requirements are (a) a way to get the CSS to the browser for parsing (beit inline with the content, internal between <style></style> tags in the <head> of the document, or external brought in via a <link> tag in the <head> of the document) and (b) HTML tags to "hook" the CSS onto. A helpful addition to this is the ability to add certain attributes to the HTML, called IDs and CLASSes, which are invaluable for targeting styles to particular elements, but even if your ASP code doesn't allow for this, you can still style the generic elements in the output HTML.

Please feel free to post any particular questions regarding how to do this. If you do, be sure to include some information about the OUTPUT HTML. That HTML code is the key to getting CSS involved.

cEM

g1smd

11:39 am on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you make your pages out of headings paragraphs, lists, tables and forms, then just a few lines of CSS in an external stylesheet can be used to style the entire site all to the same style.

There are no need for class names except on the few structures that are going to have a different style to the rest of the page (e.g. navigation and footer would likely have a smaller text size).

This makes the CSS very easy, and the HTML coding for the page very light too.

If you are using multiple nested divs and spans, and many class names and IDs then you are likely doing it in a very inefficient way.

webworker us

12:19 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Pretty much what I have is a quick ASP page to call the department's pages together. Its literally a title then include, title include. I'm definatly looking for the easiest way to do it. (Other projects have taken over for a bit).

zackattack

12:23 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



The client I work for most of the time, uses include for main parts of the site like the navigation. I can still style the content as it is output as HTML

ZA

katana_one

12:31 pm on Jun 24, 2005 (gmt 0)

10+ Year Member




the departments update their portions of the site in Word (sigh)

This might be your biggest hurdle to overcome. If they are creating HTML pages exported from Word, then any styles applied in that HTML will take precedence over your CSS.

g1smd

1:06 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you can get them to CODE the page using <hx> heading tags and <p> paragraph tags (and lists, where appropriate), and supply it to you as a TEXT file, you can then use includes to integrate it into the main page template, and you use your external CSS to style that content too. It needs a modular approach; and the content supplier to be just that: a content supplier - just supply the actual text with semantic markup but WITHOUT any styling.

webworker us

2:01 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



No, as much as I wish I could get them to code the pages, they insist on using Word. I was hoping I could override their poor choices of font with some style sheets, but if not, I guess I'll just live with it.

g1smd

2:06 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Tell them that YOU insist that they add NO STYLING AT ALL.

What does!IMPORTANT (http://www.w3.org/TR/REC-CSS2/cascade.html) do for you when used with CSS?

createErrorMsg

3:55 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



they insist on using Word

This is a major bummer. When you export or save Word content into a web format, it carries a bunch of garbage MSO tags with it. Unfortunately, because of the way specificity calculations [w3.org] work, those inline MSO styles may override your internal or external CSS.

!important [w3.org] won't be any help, since it's purpose is to establish precedence between competing user and author styles. This isn't a battle between users and authors, but one between content-creators and a knowledgable webmaster. :(

The main problem is that Word adds that MSo code (usually a classname) which then conflicts with, and often overrides your site wide, less specific, CSS. So one option might be to program the ASP (I don't work with ASP but I've heard it is very similar to PHP. I know PHP would be able to do this.) to strip out MS's classes and inline code, in order to let your external styles take the fore.

For example, say they write the following in Word, then upload it to the site as a web page....

I love Microsoft.

Cut and pasted into another web application, it simply shows up as text with out the italics. Saved as a web page in Word, the resulting html looks like this...

<p class=MsoNormal>I love <i>Microsoft</i>. </p>

...which is fine except for the class=MsoNormal, which gets this styling in the head...

p.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}

If your stylesheet has a <p> style declaration with any of the above properties in it, it will be overrode by the above style block because the class name gives the MS style a specificity 10 times higher than your plain type selector. However, if your ASP could sweep through the code looking for class names with MSO in them, and then delete those class names before including the file, it would put your P type selector back into play.

The trick is figuring out how to make the ASP do that. A good place to start (if you need the help) might be the NET and ASP Forum [webmasterworld.com].

cEM

katana_one

12:45 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



if your ASP could sweep through the code looking for class names with MSO in them, and then delete those class names before including the file,

I'm no programmer, but wouldn't it be easier to strip out the <style> rules from the head of the document? With the style rules removed, all of the class="msoStyle" declarations become meaningless. Sure, idealy you would want to strip out these class declarations as well, but stripping out the styles from the document head might be a good "quick fix" while developing more thorough code to strip out all the class declarations.

createErrorMsg

7:33 pm on Jun 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



wouldn't it be easier to strip out the <style> rules from the head of the document

Yes. But then the code would still be full of junked-up, useless MSO class tags, and that just makes me feel sad. ;)

But in practice, yes. Yours would be a much simpler solution.

cEM

webworker us

8:57 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Thanks for all the suggestions guys. I guess I'll end up coding a function to strip out the headings. I wish there was a "better" way, but I guess its what I get for having users of Word.