使用媒体查询内联样式 [英] Use media query inline style
本文介绍了使用媒体查询内联样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这听起来很可笑,但是我可以在内联样式中使用css媒体查询吗?原因是我回应PHP的背景,如果设备是视网膜,需要使用视网膜大小的图像。
I know it sounds ridiculous, but can I use a css media query in an inline style? The reason is I'm echoing a background in PHP and need to use a retina size image if the device is retina.
ie:< div style =background:url(normal.png);< - 需要为retina设备添加样式
ie: <div style="background:url(normal.png); <- need to add style for retina device
推荐答案
尽管我知道不在内联样式声明。 em
但是,如果你在PHP内回传,并且真的无法访问样式表,内容< style />
元素与媒体查询和为div使用类。
However, if you're echoing from within PHP and really can't access the stylesheet I would suggest echoing an inline <style />
element with the media query and using a class for the div.
strong>即
i.e.
<style type="text/css">
.bg {
background: url(background.jpg);
}
@media only screen and (max-device-width: 480px) { /* Change to whatever media query you require */
.bg {
background: url(background_highres.jpg);
}
}
</style>
<div class="bg">...</div>
这篇关于使用媒体查询内联样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文