Using @print to avoid multiple style sheets 
July 1st, 2008, 07:45 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 | 
July 1st, 2008, 07:55 PM
| | | | re: Using @print to avoid multiple style sheets
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 | 
July 1st, 2008, 08:05 PM
| | | | re: Using @print to avoid multiple style sheets
Joshua Cranmer wrote: Quote:
>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;
}
>}
| 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 | 
July 1st, 2008, 08:05 PM
| | | | re: Using @print to avoid multiple style sheets
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; }
} | 
July 1st, 2008, 08:25 PM
| | | | re: Using @print to avoid multiple style sheets
Harlan Messinger wrote: Quote:
>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; }
>}
| 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 | 
July 1st, 2008, 10:15 PM
| | | | re: Using @print to avoid multiple style sheets
Ed Jay wrote: Quote: |
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.
--
-bts
-Friends don't let friends drive Windows | 
July 1st, 2008, 10:45 PM
| | | | re: Using @print to avoid multiple style sheets
Beauregard T. Shagnasty wrote: Quote:
>Ed Jay wrote:
> Quote: |
>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 | 
July 1st, 2008, 11:15 PM
| | | | re: Using @print to avoid multiple style sheets
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 | 
July 2nd, 2008, 01:25 AM
| | | | re: Using @print to avoid multiple style sheets
Bergamot wrote: Quote:
>
>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. :)
| 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 | 
July 2nd, 2008, 09:25 PM
| | | | re: Using @print to avoid multiple style sheets
On 07/01/08 11:57 am, Ed Jay wrote: Quote: 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) | 
July 2nd, 2008, 10:45 PM
| | | | re: Using @print to avoid multiple style sheets
Jim Moe wrote: Quote:
>On 07/01/08 11:57 am, Ed Jay wrote: Quote: 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 { ... }".
| 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 |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|