在 Jade 模板中编写内联 CSS 样式时如何使用 javascript 变量
我正在尝试动态插入 CSS 片段。理想情况下,这是可行的:
style(type='text/css')
#header a#logo { background:url(constants.logo) no-repeat; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
#header a#logo { background-image: url(constants.logo_2x); }
}
不幸的是,constants.logo /字面上/放置在DOM中。有效的方法如下:
!= "<style type='text/css'>"
!= "#header a#logo { background:url('"+constants.logo+"') no-repeat; }"
!= "@media only screen and (-webkit-min-device-pixel-ratio: 1.5) {"
!= " #header a#logo { background-image: url('"+constants.logo_2x+"'); }"
!= "}</style>"
有更好的方法吗?
I'm trying to dynamically insert snippets of CSS. Ideally, this would work:
style(type='text/css')
#header a#logo { background:url(constants.logo) no-repeat; }
@media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
#header a#logo { background-image: url(constants.logo_2x); }
}
Unfortunately, constants.logo is /literally/ placed in the DOM. What does work is the following:
!= "<style type='text/css'>"
!= "#header a#logo { background:url('"+constants.logo+"') no-repeat; }"
!= "@media only screen and (-webkit-min-device-pixel-ratio: 1.5) {"
!= " #header a#logo { background-image: url('"+constants.logo_2x+"'); }"
!= "}</style>"
Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
#{variable}
打印元素文本中的变量。Use
#{variable}
to print a variable within an element's text.