English 中文(简体)
试图获取基于屏幕分辨率的不同背景图像以显示?
原标题:Trying to get different background images to show based on screen resolution?

我正遇到一个问题。 我正试图根据屏幕分辨率加载不同的图像, 但我尝试了下面的代码, 它并没有加载背景。 我有一个 Cs 和 jquery 设置, 且背景没有显示 。 我不知道我哪里出错了?

@media (min-width:800px) { .w800 { background-image: url(images/DCBG800.png);                      @media (min-width:1024px) { .w1024 { background-image: url(images/DCBG1024.png);
@media (min-width:1152px) { .w1152 { background-image: url(images/DCBG1152.png);
@media (min-width:1280px) { .w1280 { background-image: url(images/DCBG1280.png);
@media (min-width:1360px) { .w1360 { background-image: url(images/DCBG1360.png);
@media (min-width:1366px) { .w1366 { background-image: url(images/DCBG1366.png);
@media (min-width:1600px) { .w1600 { background-image: url(images/DCBG1600.png);
}

   <script type="text/javascript">
   function setImageClass() {
switch(true) {
    case($(window).width()>1600): $("body").removeClass("w800 w1024 w1152 w1280 w1360 w1366").addClass("w1600");
    break;
    case($(window).width()>1366): $("body").removeClass("w800 w1024 w1152 w1280 w1360 w1600").addClass("w1366");
    break;
    case($(window).width()>1360): $("body").removeClass("w800 w1024 w1152 w1280 w1366 w1600").addClass("w1360");
    break;
    case($(window).width()>1280): $("body").removeClass("w800 w1024 w1152 w1360 w1366 w1600").addClass("w1280");
    break;
    case($(window).width()>1152): $("body").removeClass("w800 w1024 w1280 w1360 w1366 w1600").addClass("w1152");
    break;
    case($(window).width()>1024): $("body").removeClass("w800 w1152 w1280 w1360 w1366 w1600").addClass("w600");
    break;
    default: $("body").removeClass("w1024 w1152 w1280 w1360 w1366 w1600").addClass("w800");
    break;
}
   }

    $(document).ready(function() {
setImageClass();
    });

    $(window).resize(function() {
setImageClass();
    });
问题回答

您没有在 CSS 示例中关闭任何卷轴括号 。 此外, 请尝试删除“ body” (即现在的正文) 上的所有分类, 并将背景图像 cs 规则直接应用到“ body” 元素选择器, 例如 :

@media (min-width:800px) { 
   body {
       background-image: url(images/DCBG800.png); 
   }
}

我希望这有帮助,

Lukx 卢克





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签