Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

CSS back into HTML

by artist (Parson)
on Mar 17, 2004 at 16:39 UTC ( #337396=perlquestion: print w/ replies, xml ) Need Help??
artist has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks
I need to put the CSS data into given HTML file so that CSS files (different for Netscape and IE) are not required anymore. Manually it takes so much time and gets little unclean, so I need some suggestions. I looked at CSS modules on CPAN, but not sure that which module would be useful for this purpose.

Thanks.

Update: I know it is reverse engineering, however it is part of the job. The HTML formatted data is used by some existing perl programs rather than directly displaying in the browser.

Update2: Perhaps I should have mentioned earlier: Any solution which doesn't alter the CSS style format won't work. Becuase I have to put this embeded HTML in the existing perl program as part of the bigger HTML display ie..(using templates for header etc..)

Comment on CSS back into HTML
Re: CSS back into HTML
by halley (Prior) on Mar 17, 2004 at 16:50 UTC
    Sounds like an ugly task.

    (1) HTML cannot express all formatting which CSS can express.
    (2) The output is now hardwired to mix content and presentation. I hope you're not throwing away the clean content files.

    Can you accept style="..." in your HTML tags? Those are still CSS, but without the dependence on external style sheet files.

    If you can accept that, you can probably just accept a <style>...</style> ahead of the body. That should be trivial to piece together. You just replace each stylesheet reference with a style tag.

    --
    [ e d @ h a l l e y . c c ]

Re: CSS back into HTML
by derby (Abbot) on Mar 17, 2004 at 16:51 UTC
    so that CSS files ... are not required anymore

    Out of curiosity, why do you want to do this. From my readings and observations, having the CSS in a seperate file is a big plus. The CSS file will be cached by the browser. The caching can result in significant bandwidth savings. I would be interested in hearing the reasons for bringing it back into the HTML file.

    Thanks.

    -derby
      Another few advantages are centralized presentation definitions -- make a change in one place to update the entire site. importing CSS to the html source seems very very silly to me.


      -Waswas
        I'm not sure I'm interpretting you correctly, but if you're trying to put styling back into the HTML tags, you're not going to be able to keep the browser-specific stuff. Can you give us more information about what your end goal is? There's always more than one way to do it.
Re: CSS back into HTML
by Willard B. Trophy (Hermit) on Mar 17, 2004 at 17:20 UTC

    Unless you are having to support Netscape 4, CSS should be identical for all browsers. Since older browsers constitute less than 1% of the traffic to my sites, I've forgotten all about the browser wars.

    It sounds like you are being asked to do this from above. Now would be a very good idea to suggest some of the strategies put forward by Jeffrey Zeldman on designing with web standards.

    If you are using HTML as a machine-readable data format, how will any presentational style information be used?

    --
    bowling trophy thieves, die!

      "CSS should be identical for all browsers"
      [OT] Oh...I wish. Maybe when it snows in hell. I spend my days building sites with CSS and XHTML (no tables, W3 validated) and the hacks that are necessary to get any given page to work across the board is almost overwhelming. Both Win and Mac IE's are the worst. Mozilla, Netscape and Safari are the best. It's a like defusing a bomb all day long.

      —Brad
      "A little yeast leavens the whole dough."
Re: CSS back into HTML
by CloneArmyCommander (Friar) on Mar 17, 2004 at 17:21 UTC
    It really would be more beneficial for you to keep the external CSS file. It saves so much more time when you want to make a quick update on the appearance of your site. Also, unless I have misunderstood what you are trying to do, CSS is what you will want to stick to if you would like to conform to XHTML standards, because most of the formatting tags (such as the bold, italic, underline, and center tags to name a few) have been dpreciated.
Re: CSS back into HTML
by kutsu (Priest) on Mar 17, 2004 at 17:32 UTC

    If you still can use CSS, just not external, you can embed the style sheet in the head tag.

    <HEAD> <STYLE TYPE="text/css" MEDIA=screen> <!-- BODY { background: url(foo.gif) red; color: black } P EM { background: yellow; color: black } .note { margin-left: 5em; margin-right: 5em } --> </STYLE> </HEAD>

    html help has more information on how to do that.

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

Re: CSS back into HTML
by inman (Curate) on Mar 18, 2004 at 11:52 UTC
    Macromedia Dreamweaver 3 had an option for doing this. I don't have it installed right now so I can't tell you more but the option was there to allow you to produce code for non CSS compliant browsers.
Re: CSS back into HTML
by kutsu (Priest) on Mar 21, 2004 at 22:13 UTC

    After reading your second Update, I wonder if you might be able to use Html::Template, or are using it. If that's so you might look at Re: HTML::Template Tutorial which shows how to include css with Html::Template, the second working on older browsers because of the comments.

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://337396]
Approved by bassplayer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-09-23 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls