views:

28

answers:

3

Hi,

I'm looking to alter the way my asp .net webpage is output to the browser depending on the css media type being used.

Although the css is generally taking care of the differences in appearance between screen and print mode I would also like to make some minor adjustments to the markup when print mode is required. I would simply be dropping a floated section down below its sibling rather than as a 2 col approach which is to used during screen layout in the browser.

A: 

This is not possible. No browser exposes this information in a way that will let you change markup on the server side (i.e. before sending to the browser).

The browser can determine what CSS to use according to what it is going to do with that page (print, display, read...), but you can't know which it will be.

Consider changing your markup so it will work well with both screen and print css.

Another option is to create a print link that will link to a print optimized version of the page.

Oded
@Oded: Thanks, I was aware that changing the markup was a possibility but given the mechanism to determine the css media type I would have been implementing a very small and convenient change using it. Thanks for clarifying that this is not possible.
Brian Scott
A: 

Not a very nice method, but you could just add in the floated section down below its sibling and hide this section in the Screen CSS file. Then in the Print CSS file you could show this hidden section and hide the other one which you do not then want in the print page.

This would cause your page to have extra html, but depending on what this floated section is, it could be an option.

Tim B James
A: 

If your markup is written in that order in order to float your column, but the actual format of the document makes more sense a different way round, you need to fix your markup and your screen CSS.

MNarkup shouldn't be dependant on CSS. Mark up your document first so that it makes sense without the CSS - which, reading between the lines, is the way you want it to display for print. Once you've done that, style the column layout based on that source order.

Chris Cox