Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

style change - screen only (not print)

0 views
Skip to first unread message

Mark McDougall

unread,
Nov 20, 2009, 1:55:17 AM11/20/09
to
Hi gurus,

Noobie alert!

I have a document with an accompanying css that specifies the right-margin
of a particular div. It also has a @print section which overrides that
same right-margin setting. Works fine for screen and printer.

Now I've recently added some js that directly modifies marginRight on that
same div on certain events.

Trouble is, for printing the @print section of the css is now seemingly
ignored, and the margins used on the printout are those (last) modified
dynamically in the js. IOW, I would like to have the js modify the
_screen_ view only, *not* the print view.

Any way to do this? I've tried different .css for screen and print, but to
no avail.

I've wondered about setting the style dynamically before printing, but I
can't find any event that is triggered on print either...

Regards,

--
Mark McDougall, Engineer
Virtual Logic Pty Ltd, <http://www.vl.com.au>
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266

David Mark

unread,
Nov 20, 2009, 3:01:07 AM11/20/09
to
On Nov 20, 1:55 am, Mark McDougall <ma...@vl.com.au> wrote:
> Hi gurus,
>
> Noobie alert!
>
> I have a document with an accompanying css that specifies the right-margin
> of a particular div. It also has a @print section which overrides that
> same right-margin setting. Works fine for screen and printer.
>
> Now I've recently added some js that directly modifies marginRight on that
> same div on certain events.
>
> Trouble is, for printing the @print section of the css is now seemingly
> ignored, and the margins used on the printout are those (last) modified
> dynamically in the js. IOW, I would like to have the js modify the
> _screen_ view only, *not* the print view.
>
> Any way to do this? I've tried different .css for screen and print, but to
> no avail.
>
> I've wondered about setting the style dynamically before printing, but I
> can't find any event that is triggered on print either...
>

You are off in the weeds. This is what !important rules are for. In
other words, your print style sheet can override the inline style(s)
set by your script. Ask in a CSS group if you need more information.

Thomas 'PointedEars' Lahn

unread,
Nov 20, 2009, 7:39:21 AM11/20/09
to
Mark McDougall wrote:

> Hi gurus,
>
> Noobie alert! [...]

Here I stopped reading.

<http://www.catb.org/~esr/faqs/smart-questions.html#id382403>

Then I read David's followup and saw my assumptions confirmed.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann

Thomas 'PointedEars' Lahn

unread,
Nov 20, 2009, 8:01:07 AM11/20/09
to
David Mark wrote:

Could you please point me to the place(s) in the CSS 2(.1) Specification
that say(s) `!important' declarations in a document stylesheet would have a
greater specificity than the `style' attribute of an element in a document?
Because I sure cannot find it.

Therefore, I propose the following two alternatives to applying inline
styles with the `style' attribute or property.

A) Add a stylesheet dynamically that uses ID or class selectors, with
`!important' where necessary.

B) (not as compatible) Add a `style' element dynamically that declares the
property values for the screen in a `@media screen' block, or a `link'
element referencing a prepared resource with media="screen" attribute,
with `!important' declarations where necessary.

> Ask in a CSS group if you need more information.

ACK, for the CSS part.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

Mark McDougall

unread,
Nov 20, 2009, 6:11:06 PM11/20/09
to
Thomas 'PointedEars' Lahn wrote:

> Then I read David's followup and saw my assumptions confirmed.

And those assumptions would be... ???

David Mark

unread,
Nov 20, 2009, 6:24:42 PM11/20/09
to
On Nov 20, 8:01 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:

> David Mark wrote:
> > On Nov 20, 1:55 am, Mark McDougall <ma...@vl.com.au> wrote:
> >> Now I've recently added some js that directly modifies marginRight on
> >> that same div on certain events.
>
> >> Trouble is, for printing the @print section of the css is now seemingly
> >> ignored, and the margins used on the printout are those (last) modified
> >> dynamically in the js. IOW, I would like to have the js modify the
> >> _screen_ view only, *not* the print view.
>
> >> Any way to do this? I've tried different .css for screen and print, but
> >> to no avail.
>
> >> I've wondered about setting the style dynamically before printing, but I
> >> can't find any event that is triggered on print either...
>
> > You are off in the weeds.  This is what !important rules are for.  In
> > other words, your print style sheet can override the inline style(s)
> > set by your script.
>
> Could you please point me to the place(s) in the CSS 2(.1) Specification
> that say(s) `!important' declarations in a document stylesheet would have a
> greater specificity than the `style' attribute of an element in a document?  
> Because I sure cannot find it.

That's as maybe. I don't have time to look for it, nor do I know for
sure if it is a normative standard.

>
> Therefore, I propose the following two alternatives to applying inline
> styles with the `style' attribute or property.
>
> A) Add a stylesheet dynamically that uses ID or class selectors, with
>    `!important' where necessary.

Eh, you could. Would be faster if you are changing lots of styles at
once.

>
> B) (not as compatible) Add a `style' element dynamically that declares the
>    property values for the screen in a `@media screen' block, or a `link'
>    element referencing a prepared resource with media="screen" attribute,
>    with `!important' declarations where necessary.

Don't use media="screen". It leaves out projectors, mobile, etc. Use
media="all" and then override with media="print".

Mark McDougall

unread,
Nov 20, 2009, 7:08:22 PM11/20/09
to
David Mark wrote:

>> A) Add a stylesheet dynamically that uses ID or class selectors, with
>> `!important' where necessary.
>
> Eh, you could. Would be faster if you are changing lots of styles at
> once.

Except it doesn't work. Same problem.

> Don't use media="screen". It leaves out projectors, mobile, etc. Use
> media="all" and then override with media="print".

FWIW this is for an in-house application that will only ever be used on a
"screen". However, I see your point.

I was wondering whether or not it was possible to write the js in such a
way as to affect only the "screen" margin, but it would seem not. So,
ultimately, this is a css problem - no?

Mark McDougall

unread,
Nov 20, 2009, 7:17:28 PM11/20/09
to
Mark McDougall wrote:

> Except it doesn't work. Same problem.

Apologies, I stand corrected. I neglected to remove the media=print
sytlesheet from the head.

This does work! Thankyou!

David Mark

unread,
Nov 20, 2009, 8:09:46 PM11/20/09
to
On Nov 20, 7:17 pm, Mark McDougall <ma...@vl.com.au> wrote:
> Mark McDougall wrote:
> > Except it doesn't work. Same problem.
>
> Apologies, I stand corrected. I neglected to remove the media=print
> sytlesheet from the head.

I don't follow?

>
> This does work! Thankyou!

The !important trick? You bet. I've used it for ages in handheld and
print media style sheets (for just this purpose).

Thomas 'PointedEars' Lahn

unread,
Nov 20, 2009, 11:06:59 PM11/20/09
to
Mark McDougall wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Then I read David's followup and saw my assumptions confirmed.
>
> And those assumptions would be... ???

(If you need to ask that question, you are in the target group because the
explanation was given in the very same posting.)

FWIW: The assumption that people who resort to groveling are usually doing
so in order to hide that they have not done their homework, thus are usually
not worth investing (my) time in.

Mark McDougall

unread,
Nov 21, 2009, 11:56:30 PM11/21/09
to
David Mark wrote:

> I don't follow?

Sorry. I had added a 2nd stylesheet with media="print", but was changing
the original stylesheet and not seeing the changes in the printed version.
After removing the "print" stylesheet and changing the media on the
original back to "all" it worked.

Mark McDougall

unread,
Nov 22, 2009, 12:23:45 AM11/22/09
to
Thomas 'PointedEars' Lahn wrote:

> FWIW: The assumption that people who resort to groveling are usually doing
> so in order to hide that they have not done their homework, thus are usually
> not worth investing (my) time in.

I was not "grovelling" (note spelling) as you are so fond of putting it
(no doubt because it strokes your ego to think some of us may be throwing
ourselves at your feet begging for enlightenment). I was merely alerting
readers/respondents that my question may either be trivial to answer or my
underlying premise may have been way off base.

(And FWIW, I'm really not that interested in anyone's opinion on How To
Ask Questions... so I'm not sure why you felt it necessary to post that?)

As for not doing my "homework"; you have of course absolutely no evidence
on which to base that accusation. For the record, I've been cutting my
teeth on HTML, CSS, Ruby, Rails and, most recently Javascript with the aid
of textbooks, online references and example code for months and this is
the first time I've resorting to posting a question on any subject.

And since you're also so fond of pushing netiquette, how about this one...
If you don't have anything _constructive_ to say, STFU.

Unfortunately, smug, presumptuous, rude & sad little men are all too
common in this profession... "I'm not worthy! I'm not worthy!"

Mark McDougall

unread,
Nov 22, 2009, 12:46:07 AM11/22/09
to

<http://redwing.hutman.net/~mreed/warriorshtm/xenophobe.htm>

Reminds me of someone... can't quite place who???

LOL!

optimistx

unread,
Nov 22, 2009, 3:13:02 AM11/22/09
to
Mark McDougall wrote:
> I was not "grovelling" (note spelling) as you are so fond of putting
> it (no doubt because it strokes your ego to think some of us may be
> throwing ourselves at your feet begging for enlightenment).

If you are interested and still upset, google 'Asperger syndrome symptoms'.

Evertjan.

unread,
Nov 22, 2009, 4:21:00 AM11/22/09
to
Mark McDougall wrote on 22 nov 2009 in comp.lang.javascript:

> (And FWIW, I'm really not that interested in anyone's opinion on How To
> Ask Questions... so I'm not sure why you felt it necessary to post that?)

I think you do not understand usenet.

Posting should never be directed to the individual [only],
that's what email is for.

PE does not need to guess what you are interested in,
when he wants to post, as long as it is on topic.

Netiquette and the NG-FAQ are always on topic.
"How To Ask Questions" definitly is part of those.

Usenet is not a paid helpdask.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Mark McDougall

unread,
Nov 22, 2009, 4:58:25 AM11/22/09
to
Evertjan. wrote:

> I think you do not understand usenet.

ROTFL!

Mark McDougall

unread,
Nov 22, 2009, 5:07:55 AM11/22/09
to
Evertjan. wrote:

> Usenet is not a paid helpdask.

NFI. No where did I demand any answers from anyone. All I presumed is that
I would be treated with some semblance of respect, not with dismissive
condescension.

Sigh. I guess if I've decided to mess with kiddie-script languages I can
only expect to have to deal with, kiddies... :(

Evertjan.

unread,
Nov 22, 2009, 11:22:56 AM11/22/09
to
Mark McDougall wrote on 22 nov 2009 in comp.lang.javascript:

> Evertjan. wrote:
>
>> Usenet is not a paid helpdask.
>
> NFI. No where did I demand any answers from anyone. All I presumed is
> that I would be treated with some semblance of respect, not with
> dismissive condescension.

And you find you were wrong in that presumption?

> Sigh. I guess if I've decided to mess with kiddie-script languages I
> can only expect to have to deal with, kiddies... :(


> Mark McDougall, Engineer

Indeed,
Engineers should not mess with such profane languages.

0 new messages