css content in the stylesheet? (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets



Message


mtfm -> css content in the stylesheet? (1/9/2007 19:19:05)

OK, I have a (dumb) question. I know it is probably not possible, but I'm going to ask anyway.


I have a website with several alternate stylesheets set up, one for printing. I'd like to insert a snippet of code saying "this page was printed on..." onto each page whenever it is printed. I was wondering if I could insert that code into the stylesheet.

I know this is heresy, since the whole point is to seperate style and content and this would be muddying things up-- but each page in the site already has a "last modified on" date, and inserting the code into the page itself will mess up that date. That date is as important if not more so than the printed date....








womble -> RE: css content in the stylesheet? (1/9/2007 19:28:57)

The only way I can think to do it is to put both on the page but then use the stylesheets to control which is visible/printed, for example you could something like:

On the normal screen stylesheet:

#modifieddate { whatever styles }
#printeddate { display: none; }

...and then on the print stylesheet:

#modifieddate { display: none; }
#printeddate { whatever styles }




mtfm -> RE: css content in the stylesheet? (1/9/2007 19:33:20)

yeah, that's about what I came up with. But as I say I don't want to modify the pages themselves (and mess up the modified dates). That's why I want to do it entirely within the stylesheets and not touch the pages themselves.

As I say I expect this is not possible-- but have been surprised before. [:)]




womble -> RE: css content in the stylesheet? (1/9/2007 20:08:23)

As far as I'm aware, the only thing you can put in stylesheets is styles (although I did read something recently about process CSS as PHP - can't remember in what context though so that's not much help! [:D])

What do you mean "mess up the modified dates"? What are you using to get the modified date - JavaScript/PHP/ASP?

Whatever you're using for the modified date, you'd use a separate function for the printed date, basically the current date -

date() in PHP,

... in JS you could use:
<p>Date printed: 
<script type="text/javascript">
<!--
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)
//-->
</script>
</p>


And in ASP: <%=month(date)%>/<%=day(date)%>/<%=year(date)%>




rubyaim -> RE: css content in the stylesheet? (1/9/2007 21:00:51)

mtfm, do you mean that if the pages are edited to include the printed date, the modified date will change, and not be a true reflection of the content modification?

Like Womble, I can't see how you would do this without using script, but it's an interesting question.

A workaround might be to add a note using :after to warn users to check the modification date - see code below (view it with FF or Opera). AFAIK this will not work in IE, so it is probably not very useful at all in the real world, but it is fun to play with [:D]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>Body after print test</title>

<style type="text/css">

@media print {

body:after {
    content: "Please note the modified date of this document.";
    display: block;
    margin-top: 2em;
    text-align: right;
    font-weight: bold;
}
}

</style>

</head>

<body>

<h1>Print Preview this page.</h1>

<p>This is a test.  Look to the lower right of this paragraph on print preview.</p>
</body>

</html>



FWIW, I think the default printer setting on browsers will include the date printed in the footer, so the print date will show unless a user has removed this. Most users don't change these settings.




womble -> RE: css content in the stylesheet? (1/10/2007 5:27:09)


quote:

ORIGINAL: rubyaim

mtfm, do you mean that if the pages are edited to include the printed date, the modified date will change, and not be a true reflection of the content modification?



Ah! I see what you mean! I'd not thought of that! [img]http://ecanus.net/smileys/duh.gif[/img]





jaybee -> RE: css content in the stylesheet? (1/10/2007 8:23:46)

I understand it is possible to put javascript in the css file. DOn't ask me how though, I've only tried it once for a hack for IE and it doesn't validate so I took it out.




Donkey -> RE: css content in the stylesheet? (1/10/2007 11:29:35)

Why not put the cgi code for today's date into an include which is put inside a div on all pages. Then hide the div on all style sheets except the print one.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.078125