CSS 条件@Import 问题
我有一个 HTML 文件,其中包含以下代码;
<html>
<head>
<LINK media="all" href="css/desktop.css" type="text/css" rel="stylesheet">
</head>
<body>
<span class="ipad_text">DESKTOP RED; iPad GREEN</span>
<br />
<span class="ipad_text2">DESKTOP BLACK; iPad BLUE</span>
<br />
<span class="ipad_only">iPad ONLY SHOW</span>
<br />
<span class="ipad_only2">iPad ONLY 2</span>
</body>
</html>
css文件夹下还有2个CSS文件(desktop.css和ipad.css); 在desktop.css中,我有
@import "ipad.css";
.ipad_text{
font:42px arial bold;
color: red;
}
.ipad_text2{
font:22px verdana bold;
color: black;
}
.ipad_only{
display:none;
}
在ipad.css中,我有
@media only screen and (device-width:768px)
{
.ipad_text{
font:32px arial bold;
color: green;
}
.ipad_text2{
font:22px verdana bold;
color: blue;
}
.ipad_only{
display:block;
}
.ipad_only2{
color: red;
font:52px arial bold;
}
}
现在由于某些原因,这不起作用。如果我将ipad.css中的代码剪切/粘贴到desktop.css文件下,如下所示,页面将正确显示在台式机和 iPad 上...我做错了什么?我希望 2 个 CSS 驻留在单独的文件中...请帮助我。
以下作品完美
@import "ipad.css";
.ipad_text{
font:42px arial bold;
color: red;
}
.ipad_text2{
font:22px verdana bold;
color: black;
}
.ipad_only{
display:none;
}
@media only screen and (device-width:768px)
{
.ipad_text{
font:32px arial bold;
color: green;
}
.ipad_text2{
font:22px verdana bold;
color: blue;
}
.ipad_only{
display:block;
}
.ipad_only2{
color: red;
font:52px arial bold;
}
}
I have a HTML file which has the following code;
<html>
<head>
<LINK media="all" href="css/desktop.css" type="text/css" rel="stylesheet">
</head>
<body>
<span class="ipad_text">DESKTOP RED; iPad GREEN</span>
<br />
<span class="ipad_text2">DESKTOP BLACK; iPad BLUE</span>
<br />
<span class="ipad_only">iPad ONLY SHOW</span>
<br />
<span class="ipad_only2">iPad ONLY 2</span>
</body>
</html>
Also there are 2 CSS files under css folder (desktop.css and ipad.css);
In desktop.css, I have
@import "ipad.css";
.ipad_text{
font:42px arial bold;
color: red;
}
.ipad_text2{
font:22px verdana bold;
color: black;
}
.ipad_only{
display:none;
}
And in ipad.css, I have
@media only screen and (device-width:768px)
{
.ipad_text{
font:32px arial bold;
color: green;
}
.ipad_text2{
font:22px verdana bold;
color: blue;
}
.ipad_only{
display:block;
}
.ipad_only2{
color: red;
font:52px arial bold;
}
}
Now for some reasons, this is not working..If I cut/paste the code from ipad.css under the desktop.css file as follows, the page displays correctly in both desktop and iPad...What I am doing wrong? I want the 2 CSS to reside in separate files...Please help me.
Following works perfectly
@import "ipad.css";
.ipad_text{
font:42px arial bold;
color: red;
}
.ipad_text2{
font:22px verdana bold;
color: black;
}
.ipad_only{
display:none;
}
@media only screen and (device-width:768px)
{
.ipad_text{
font:32px arial bold;
color: green;
}
.ipad_text2{
font:22px verdana bold;
color: blue;
}
.ipad_only{
display:block;
}
.ipad_only2{
color: red;
font:52px arial bold;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像我在之前的回答中所说。 ..
...因为您的非 iPad 样式适用于所有媒体,包括 iPad 上的 Mobile Safari。由于您的非 iPad 样式位于条件
@import
之后,因此无论是否导入,它们都会覆盖您的样式。这是正常的级联行为。Like I said in my previous answer...
... because your non-iPad styles apply to all media, including Mobile Safari on iPad. Since your non-iPad styles come after your conditional
@import
, they'll override your styles whether they get imported or not. This is normal cascading behavior.