Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same css for viewing on screen and printing

Status
Not open for further replies.

Pichdude

Programmer
Aug 24, 2005
66
SE
Hi, is it possible to, in the same css, specify different styles for the same object depending on if it's shown on the screen or printed?

E.g. a button should be green on the screen but not shown at all when the same page is printed.

Regards

Pichdude
 
Read up on the @meda rules. Here's a quick example:
Code:
@media screen {
   #mybutton {
      background: green;
   }
}
@media print {
   #mybutton {
      display: none;
   }
}
 
It might be more manageble for you to specify different media style sheets within your html. Like so:

Code:
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/screen.css" />
<link rel="stylesheet" type="text/css" media="print" href="stylesheets/print.css" />

Then you just have to set up your different styles in 2 different files. Makes large sets of style rules easier to manage.

Foamcow Heavy Industries - Web design and ranting
Target Marketing Communications - Advertising, Direct Marketing and Public Relations
I wonder what possesses people to make those animated gifs. Do you just get up in the morning and think, "You know what web design r
 
Thanks!

As I see it this is not supported for Mozilla. Any tips there?
 
I suggest you follow Foamcow's advice and use different stylesheets. There is no fully supported solution that allows use of @meda.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Find a better source for your statements? This has been supported in Mozilla (and also all major browsers) for a while now. I have been using it extensively on my websites.
 
People need to draw a line on what compatibility they want to support. In this instance you are not going to get a solution that works with every browser that ever was made at any version for any operating system. So define what level of compatibility you want.

Are you going to be satisfied with 95% support of your visitors? 98%? These figures are easily achieved by defining support for modern browsers (that includes IE6, Firefox, Netscape 7+, Opera 7+, Safari as a core collection and often includes IE55 as well). All these browsers, for instance, support @media.

So, what browsers are you actively concerned about?

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
-> BabyJeff: You are absolutely right. The demands of what I am doing is:

IE 6.x: 100% working, 100% layout
Mozilla Firefox 1.x: 100% working, 50% layout

So it is accepted if everything does not look perfect in Firefox, but it is nice if it do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top