[issue6670] Printing the 'The Python Tutorial'

brimac report at bugs.python.org
Wed Oct 7 15:11:44 CEST 2009


brimac <brimac at bcs.org> added the comment:

Hi Ezio

Many thanks for all your effort with this problem.
Thanks also for the full explanation and link.
I'm not sure what happens now. Will somebody fix it?
I think it's important for Python's image because
it might be the first page a new user tries to print.

brimac

2009/10/6 Ezio Melotti <report at bugs.python.org>

>
> Ezio Melotti <ezio.melotti at gmail.com> added the comment:
>
> To fix this problem is enough to add an !important to the margin: 0;
> rule in the @media print {} at the end of basic.css (line 408).
>
> I'll try to explain why the !important is necessary.
> In default.css @import url("basic.css"); (correctly) appears at the
> beginning, and imports the rules from basic.css, including the @media
> print {}. A few lines later, in default.css, there's the rule
> div.bodywrapper { margin: 0 0 0 230px; }, and with no @media specified
> it defaults on 'all'.
>
> In default.css we then end up with something equivalent to:
>
> /* This is defined in basic.css and imported
>   at the beginning of default.css */
> @media print {
>    /* some rules omitted for clarity */
>    div.bodywrapper { margin: 0; }
> }
>
> /* This is defined later in default.css */
> @media all { /* This is implicit */
>    div.bodywrapper { margin: 0 0 0 230px; }
> }
>
> When the file is printed both the rules are applied, because 'all' also
> includes 'print'.
> Since both the media have the same priority (i.e. the specific @media
> print does NOT have higher priority than the implicit @media all) and
> both the rules have the same priority too, the latter wins.
> The !important is then needed to raise the priority of the first rule.
>
> Note that adding the !important is not a really good solution IMHO: the
> problem could appear again if other rules with the same priority of the
> ones in @media print {} are specified elsewhere.
> A good solution would be to move the print rules after the normal ones,
> so in case the print media is used these rules will have higher priority.
> The @import can only appear at the beginning of a file so the two
> possible solutions are:
>
> 1) put the rules with media all in, for example, all.css and the ones
> with media print in print.css and then, in default.css, write only:
> @import url('all.css');
> @import url('print.css') print;
>
> 2) like 1) but importing the print.css separately using <link> in the
> html pages:
> <link href="default.css" type="text/css" rel="stylesheet">
> <link href="print.css" type="text/css" rel="stylesheet" media="print">
>
> A third solution might be to specify the media of the normal rules to
> 'screen', but some rules are probably common to both the media.
>
> More information here: http://www.w3.org/TR/CSS2/cascade.html
>
> ----------
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <http://bugs.python.org/issue6670>
> _______________________________________
>

----------
Added file: http://bugs.python.org/file15069/unnamed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6670>
_______________________________________
-------------- next part --------------
Hi Ezio<br><br>Many thanks for all your effort with this problem.<br>Thanks also for the full explanation and link.<br>I&#39;m not sure what happens now. Will somebody fix it?<br>I think it&#39;s important for Python&#39;s image because<br>
it might be the first page a new user tries to print.<br><br>brimac<br><br><br><div class="gmail_quote">2009/10/6 Ezio Melotti <span dir="ltr">&lt;<a href="mailto:report at bugs.python.org">report at bugs.python.org</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im"><br>
Ezio Melotti &lt;<a href="mailto:ezio.melotti at gmail.com">ezio.melotti at gmail.com</a>&gt; added the comment:<br>
<br>
</div>To fix this problem is enough to add an !important to the margin: 0;<br>
rule in the @media print {} at the end of basic.css (line 408).<br>
<br>
I&#39;ll try to explain why the !important is necessary.<br>
In default.css @import url(&quot;basic.css&quot;); (correctly) appears at the<br>
beginning, and imports the rules from basic.css, including the @media<br>
print {}. A few lines later, in default.css, there&#39;s the rule<br>
div.bodywrapper { margin: 0 0 0 230px; }, and with no @media specified<br>
it defaults on &#39;all&#39;.<br>
<br>
In default.css we then end up with something equivalent to:<br>
<br>
/* This is defined in basic.css and imported<br>
   at the beginning of default.css */<br>
@media print {<br>
    /* some rules omitted for clarity */<br>
    div.bodywrapper { margin: 0; }<br>
}<br>
<br>
/* This is defined later in default.css */<br>
@media all { /* This is implicit */<br>
    div.bodywrapper { margin: 0 0 0 230px; }<br>
}<br>
<br>
When the file is printed both the rules are applied, because &#39;all&#39; also<br>
includes &#39;print&#39;.<br>
Since both the media have the same priority (i.e. the specific @media<br>
print does NOT have higher priority than the implicit @media all) and<br>
both the rules have the same priority too, the latter wins.<br>
The !important is then needed to raise the priority of the first rule.<br>
<br>
Note that adding the !important is not a really good solution IMHO: the<br>
problem could appear again if other rules with the same priority of the<br>
ones in @media print {} are specified elsewhere.<br>
A good solution would be to move the print rules after the normal ones,<br>
so in case the print media is used these rules will have higher priority.<br>
The @import can only appear at the beginning of a file so the two<br>
possible solutions are:<br>
<br>
1) put the rules with media all in, for example, all.css and the ones<br>
with media print in print.css and then, in default.css, write only:<br>
@import url(&#39;all.css&#39;);<br>
@import url(&#39;print.css&#39;) print;<br>
<br>
2) like 1) but importing the print.css separately using &lt;link&gt; in the<br>
html pages:<br>
&lt;link href=&quot;default.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;&gt;<br>
&lt;link href=&quot;print.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot; media=&quot;print&quot;&gt;<br>
<br>
A third solution might be to specify the media of the normal rules to<br>
&#39;screen&#39;, but some rules are probably common to both the media.<br>
<br>
More information here: <a href="http://www.w3.org/TR/CSS2/cascade.html" target="_blank">http://www.w3.org/TR/CSS2/cascade.html</a><br>
<br>
----------<br>
<div><div></div><div class="h5"><br>
_______________________________________<br>
Python tracker &lt;<a href="mailto:report at bugs.python.org">report at bugs.python.org</a>&gt;<br>
&lt;<a href="http://bugs.python.org/issue6670" target="_blank">http://bugs.python.org/issue6670</a>&gt;<br>
_______________________________________<br>
</div></div></blockquote></div><br>


More information about the Python-bugs-list mailing list