HighDots Forums  

Using @print to avoid multiple style sheets

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss Using @print to avoid multiple style sheets in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ed Jay
 
Posts: n/a

Default Using @print to avoid multiple style sheets - 07-01-2008 , 02:35 PM






I do not want to load two style sheets for screen and print media. I'm
having difficulty grasping the use of the @print statement, or its syntax.
Would someone please provide a simple explanation.

For example...

If I have a style sheet specifying media="all," is the following correct
syntax to center text for printing, but not for screen presentation?

..divClass1 {
text-align:left;
}
@print .divClass1 {
text-align:center;
}

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info

Reply With Quote
  #2  
Old   
Joshua Cranmer
 
Posts: n/a

Default Re: Using @print to avoid multiple style sheets - 07-01-2008 , 02:48 PM






Ed Jay wrote:
Quote:
I do not want to load two style sheets for screen and print media. I'm
having difficulty grasping the use of the @print statement, or its syntax.
Would someone please provide a simple explanation.

For example...

If I have a style sheet specifying media="all," is the following correct
syntax to center text for printing, but not for screen presentation?
Corrected syntax:

@media print {
.divClass1 {
text-align: center;
}
}


--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth


Reply With Quote
  #3  
Old   
Ed Jay
 
Posts: n/a

Default Re: Using @print to avoid multiple style sheets - 07-01-2008 , 02:57 PM



Joshua Cranmer wrote:

Quote:
Ed Jay wrote:
I do not want to load two style sheets for screen and print media. I'm
having difficulty grasping the use of the @print statement, or its syntax.
Would someone please provide a simple explanation.

For example...

If I have a style sheet specifying media="all," is the following correct
syntax to center text for printing, but not for screen presentation?

Corrected syntax:

@media print {
.divClass1 {
text-align: center;
}
}
Thanks. I presume this will supercede a previous style for divClass1 in a
media=all sheet, as in the example I gave?

I also presume that I can include multiple declarations within the
@print {..}?

Thanks again.

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info


Reply With Quote
  #4  
Old   
Harlan Messinger
 
Posts: n/a

Default Re: Using @print to avoid multiple style sheets - 07-01-2008 , 03:00 PM



Ed Jay wrote:
Quote:
I do not want to load two style sheets for screen and print media. I'm
having difficulty grasping the use of the @print statement, or its syntax.
Would someone please provide a simple explanation.

For example...

If I have a style sheet specifying media="all," is the following correct
syntax to center text for printing, but not for screen presentation?

.divClass1 {
text-align:left;
}
@print .divClass1 {
text-align:center;
}

In CSS there is no such thing as @print. The correct form for what
you're trying to do is

@media print {
.divClass1 { text-align: center; }
}



Reply With Quote
  #5  
Old   
Ed Jay
 
Posts: n/a

Default Re: Using @print to avoid multiple style sheets - 07-01-2008 , 03:23 PM



Harlan Messinger wrote:

Quote:
Ed Jay wrote:
I do not want to load two style sheets for screen and print media. I'm
having difficulty grasping the use of the @print statement, or its syntax.
Would someone please provide a simple explanation.

For example...

If I have a style sheet specifying media="all," is the following correct
syntax to center text for printing, but not for screen presentation?

.divClass1 {
text-align:left;
}
@print .divClass1 {
text-align:center;
}


In CSS there is no such thing as @print. The correct form for what
you're trying to do is

@media print {
.divClass1 { text-align: center; }
}
Thanks...that explains some weird behavior. :-)

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info


Reply With Quote
  #6  
Old   
Ed Jay
 
Posts: n/a

Default Re: Using @print to avoid multiple style sheets - 07-01-2008 , 05:43 PM



Beauregard T. Shagnasty wrote:

Quote:
Ed Jay wrote:

I do not want to load two style sheets for screen and print media.

Mind listing the reason for that?

I find that a separate print style sheet greatly reduces maintenance.
For one, you don't have to pore through hundreds of lines of screen
styles looking for each print style. The few you probably need would be
easily accessible in one small place.

Download time would be next to nothing.
I thought it might be easier to have everything in one place. But, it's not
working out, so I've abandoned the idea.

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info


Reply With Quote
  #7  
Old   
Bergamot
 
Posts: n/a

Default Re: Using @print to avoid multiple style sheets - 07-01-2008 , 06:14 PM




Beauregard T. Shagnasty wrote:
Quote:
I find that a separate print style sheet greatly reduces maintenance.
Not necessarily. Depends on how the CSS is organized, I think.

Quote:
For one, you don't have to pore through hundreds of lines of screen
styles looking for each print style.
The problem with that is some styles I often want for both screen and
print. That means either duplicating them in the print stylesheet, or
loading 2 stylesheets. Too much trouble for me to keep that stuff
straight. Besides, I never intermix screen only and print rules.

I prefer to use 1 stylesheet and section it off by media type. I've been
doing it this way for so long I know exactly where to look for certain
rules.

@media screen, projection, print {
global rules like heading fonts, floating images, etc.
}
@media screen, projection {
screen only rules like navigation, background images, etc.
}
@media print {
print only rules, like display:none for navigation, etc.
}

I suppose you could stick handheld in there, too, but I don't bother. If
they get info sans CSS, that's fine with me.

Quote:
Download time would be next to nothing.
It is. IIRC, at least some browsers retrieve all stylesheets whether
they need them or not, then apply the applicable rules depending on what
the user requests. It's fewer server calls putting them into 1 external
stylesheet.

If your CSS is huge, however, then you should rethink a few things. KISS
comes to mind.

--
Berg


Reply With Quote
  #8  
Old   
Ed Jay
 
Posts: n/a

Default Re: Using @print to avoid multiple style sheets - 07-01-2008 , 08:14 PM



Bergamot wrote:

Quote:
Beauregard T. Shagnasty wrote:

I find that a separate print style sheet greatly reduces maintenance.

Not necessarily. Depends on how the CSS is organized, I think.

For one, you don't have to pore through hundreds of lines of screen
styles looking for each print style.

The problem with that is some styles I often want for both screen and
print. That means either duplicating them in the print stylesheet, or
loading 2 stylesheets. Too much trouble for me to keep that stuff
straight. Besides, I never intermix screen only and print rules.

I prefer to use 1 stylesheet and section it off by media type. I've been
doing it this way for so long I know exactly where to look for certain
rules.

@media screen, projection, print {
global rules like heading fonts, floating images, etc.
}
@media screen, projection {
screen only rules like navigation, background images, etc.
}
@media print {
print only rules, like display:none for navigation, etc.
}

I suppose you could stick handheld in there, too, but I don't bother. If
they get info sans CSS, that's fine with me.

Download time would be next to nothing.

It is. IIRC, at least some browsers retrieve all stylesheets whether
they need them or not, then apply the applicable rules depending on what
the user requests. It's fewer server calls putting them into 1 external
stylesheet.

If your CSS is huge, however, then you should rethink a few things. KISS
comes to mind.
My intended scheme was based on organization as well. I only write for
screen and print media. My style sheets are alphabetically organized, and I
was considering adding the media print definitions immediately following the
individual screen styles. Unfortunately, that doesn't seem feasible, or at
least make a lot of sense, because it appears that styles for each media
have to be grouped under a media type, such as you have done. That doesn't
accomplish what I wanted to do.

I quaffed a beer and took a nap instead.

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info


Reply With Quote
  #9  
Old   
Jim Moe
 
Posts: n/a

Default Re: Using @print to avoid multiple style sheets - 07-02-2008 , 04:20 PM



On 07/01/08 11:57 am, Ed Jay wrote:
Quote:
Corrected syntax:

@media print {
.divClass1 {
text-align: center;
}
}
Thanks. I presume this will supercede a previous style for divClass1 in a
media=all sheet, as in the example I gave?

Only if it comes after the stylesheet for divClass1.

Quote:
I also presume that I can include multiple declarations within the
@print {..}?

You mean "@media print { ... }"?
Yes. It is like any other style ruleset, just restricted to print media.
The normal ruleset has an implied "@media all { ... }".

--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)


Reply With Quote
  #10  
Old   
Ed Jay
 
Posts: n/a

Default Re: Using @print to avoid multiple style sheets - 07-02-2008 , 05:43 PM



Jim Moe wrote:

Quote:
On 07/01/08 11:57 am, Ed Jay wrote:

Corrected syntax:

@media print {
.divClass1 {
text-align: center;
}
}
Thanks. I presume this will supercede a previous style for divClass1 in a
media=all sheet, as in the example I gave?

Only if it comes after the stylesheet for divClass1.

I also presume that I can include multiple declarations within the
@print {..}?

You mean "@media print { ... }"?
Yes. It is like any other style ruleset, just restricted to print media.
The normal ruleset has an implied "@media all { ... }".
Thanks, Jim.

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.