简体   繁体   English

symfony2 + assetic:使用{%javascripts%}时如何将CSS限制为打印

[英]symfony2 + assetic : how to restrict a css to a print when using {% javascripts %}

In my symfony 2 application, I have : 在我的symfony 2应用程序中,我有:

<link href="{{ asset('stylesheets/backend/plugins/fullcalendar/fullcalendar.print.css') }}" rel='stylesheet' media='print'>

I also have a vendor css file which modifies it and needs to be placed after. 我也有一个供应商的css文件,可以对其进行修改,需要在其后放置。 This one is included in my {% stylesheets %} block : 这个包含在我的{%stylesheets%}块中:

{% stylesheets
    'stylesheets/backend/style.css'

    filter='?yui_css, cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

Now the thing is if I put the css for print in the stylesheets block, I lose the media=print argument and things get messed. 现在的问题是,如果我将要打印的css放在样式表块中,则会丢失media = print参数,结果会变得一团糟。

How can I include a css into a stylesheets block and restric its usage to a print media query ? 如何将CSS包含在样式表块中,并将其用法限制在印刷媒体查询中?

Thanks a lot 非常感谢

There are a couple of ways to approach this: 有两种方法可以解决此问题:

1) You could separate your print-specific stylesheet into a new stylesheets block (you can have as many of these as you need), and simply add the media='print' attribute to the <link> element. 1)您可以将特定于打印的样式表分成一个新的stylesheets块(可以根据需要添加多个stylesheets块),然后只需将media='print'属性添加到<link>元素。

It would look something like this: 它看起来像这样:

{% stylesheets
    'foo.css'
    'bar.css'

    filter='?yui_css, cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

{% stylesheets
    'vendor_stylesheet_with_print_styles.css'

    filter='?yui_css, cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}" media="print" />
{% endstylesheets %}

2) If you don't need to support IE8 , you can use a media query inside the CSS file that needs to modify it: 2)如果不需要支持IE8 ,则可以在需要修改它的CSS文件中使用媒体查询:

@media print {
    ... styles go here ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM