tags:

views:

46

answers:

2

I've got a table that has some input (type="text") boxes in it, and I want these to show as normal text when printing. I have set up a media="print" stylesheet with

input { border-style: none; }

in it, and this removes the border so the content just looks like text, but the input is still pushing the width of the column to its actual width (not surprisingly) so I get unnecessary empty space and column widths. Is there a funky way to somehow either set the input's width to its content size using CSS, or some other way to fix this?

Someone on another forums suggested using a print button which creates client side scripting to physically change the page markup, but unfortunately that's not really practical due to the complexity and dynamic nature of the page.

I'm pretty sure this can't be done, but I thought I'd ask.....

Cheers MH

A: 

Nope, I don't think this can be done without some scripting. But the scripting would be really easy to achieve with a Framework like Jquery:

  • For each input element, you would create a <span> next to it and give it a class that is hidden in the media="screen" stylesheet, and visible in media="print".

  • The input element itself would get a class that works the other way round, visible in screen and hidden in print.

  • Each input element would get a change event that updates the neighboring span.

I don't have the JQuery routine yet to pull this out of my sleeve, and not the time to put it together right now, but it is definitely solvable and still quite unobtrusive - no need to execute any scripting when the user starts printing.

I bet if you re-tag the question or ask a new one, one of our resident JQuery gurus will take a look at it :)

Pekka
Thanks for the suggestion - I'm using (and fairly competent with) JQuery, but there are a whole load of dynamically created inputs so putting this in would complicate the (already complex) code quite a bit, so I wanted to avoid that if possible, hence my thoughts on doing this with CSS - it's not perfect at the moment, but it's not too bad.
Mad Halfling
Thanks, I can do that myself but it would be a bit of a beast and the tradeoff for functionality vs the extra testing isn't worth it (I know it sounds like it wouldn't be that complex, but this page is turning into a bit of a monster, hehe). Thanks very much for the suggestion though, maybe it will help someone else
Mad Halfling
A: 
input { border-style: none; display: inline}

?

graphicdivine
nice thinking, but it doesn't work.
henasraf
Yes, I've tried that and it doesn't work (at least under IE8) - the textboxes still reserve their space on the page and don't collapse to fit their content text (thanks, anyway, for the suggestion)
Mad Halfling