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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

switching style sheets

Status
Not open for further replies.

cajchris

Programmer
Oct 13, 2005
57
GB
I am implementing a web site where there are 'print this page' links on each page, and when clicked it will show the same page again only with certain things removed, ie images, styles etc. there will be another CSS file that will be used for this print view, but I am wanting to know how would you switch between CSS files for this to work.

regards
cajchris
 
You can change the media that the style sheet applies to. So you can have a normal stylesheet, and then (afterward in source order) a print stylesheet that makes some things invisible etc. Both can be on the same page at the same time... if you view the site in a regular browser you still see all the normal things, if you print the page, then the print stylesheet comes into effect.

This means you can get rid of the whole "pop up the print page in a new window" idea!

Some further explainations:

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
hmm i was just thinking. the default style sheet doesnt have references to the links of background images and list style images, as these images are bound when the editor is making a page.

i am using an application called infoglue which allows pages to be developed based on components. so the developer of a web site can make a web page and bind images from external locations to the page. so essentially switching style sheets wouldnt make the images disappear.

any ideas how i would get round this?

regards,
cajchris
 
Just give all the links (that you don't want to print) the same class and then set up a style in your print stylesheet that doesn't print this class. Easy [smile]

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
here is a snippet from my home page:

<span id="HyperLink" title="nominet Home Page" style="background-image: url('/infoglueDeliverWorking/digitalAssets/51_Logo_New_Nominet_Main.gif')">

now when the printable page is being viewed i wouldnt want the background image to be there. however this has been coded like this using infoglue:

<span id="HyperLink" title="nominet Home Page" style="background-image: url('$logoImage')">

where $logoImage is a velocity variable that has been set by the web developer when creating this home page.

so simply having an empty class in the print CSS called HyperLink wont remove the image as it is not coming from the original CSS
 
This will solve that problem...
Code:
span#HyperLink {
  background-image:none;
}
And if you used a class for all such links (instead of unique IDs), then you would be able to have one such style (rather than many that match each ID) in your CSS.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
this doesnt seem to work as the background image in question now appears but with no style reference as i removed all properties from the HyperLink entry and put in none for the background image but the image still appeared.
 
Make sure you have the print style sheet after and other stylesheets (or styles) on the page... and to avoid specificity issues, you can use !important in your css to ensure the item doesn't display.

Looking again at the replies, I reckon the following is what you want...
Code:
span#HyperLink {
  display:none !important;
}

Same as before, it'd be better if you used a class to reduce the amount of declarations you'd have to do. Still, if it's dynamic then it's not a worry :)

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
i now have a new problem. while

span#HyperLink {
display:none !important;
}

does ensure the background image doesnt appear, it also now results in the text that is on top of the area covered by the background image also doesnt appear. which is not the result i am after, as everything else should still remain there

regards
cajchris
 
Then don't hide it, but just remove the background:
Code:
span#HyperLink {
  background: transparent !important;
}
 
cheers Vragabond much appreciated

regards
cajchris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top