Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / CSS / July 2008



Tip: Looking for answers? Try searching our database.

Using @print to avoid multiple style sheets

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed Jay - 01 Jul 2008 19:35 GMT
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;
}

Signature

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

Joshua Cranmer - 01 Jul 2008 19:48 GMT
> 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.
[quoted text clipped - 4 lines]
> 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;
  }
}

Signature

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

Ed Jay - 01 Jul 2008 19:57 GMT
>> 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.
[quoted text clipped - 12 lines]
>   }
>}
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.

Signature

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

Jim Moe - 02 Jul 2008 21:20 GMT
>>Corrected syntax:
>>
[quoted text clipped - 5 lines]
> 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 { ... }".

Signature

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

Ed Jay - 02 Jul 2008 22:43 GMT
>>>Corrected syntax:
>>>
[quoted text clipped - 14 lines]
>  Yes. It is like any other style ruleset, just restricted to print media.
>  The normal ruleset has an implied "@media all { ... }".

Thanks, Jim.

Signature

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

Harlan Messinger - 01 Jul 2008 20:00 GMT
> 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.
[quoted text clipped - 11 lines]
> 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; }
}
Ed Jay - 01 Jul 2008 20:23 GMT
>> 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.
[quoted text clipped - 18 lines]
>    .divClass1 { text-align: center; }
>}

Thanks...that explains some weird behavior. :-)

Signature

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

Beauregard T. Shagnasty - 01 Jul 2008 22:09 GMT
> 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.

Signature

  -bts
  -Friends don't let friends drive Windows

Ed Jay - 01 Jul 2008 22:43 GMT
>> I do not want to load two style sheets for screen and print media.
>
[quoted text clipped - 6 lines]
>
>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.

Signature

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

Bergamot - 01 Jul 2008 23:14 GMT
> 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. :)

Signature

Berg

Ed Jay - 02 Jul 2008 01:14 GMT
>> I find that a separate print style sheet greatly reduces maintenance.
>
[quoted text clipped - 34 lines]
>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.

Signature

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.