简体   繁体   English

CSS:响应式背景图片问题

[英]CSS: Responsive, background image issue

I can't get the image to appear, which is bizarre as the div box is there when I highlight elements on the page. 我无法显示图像,这很奇怪,因为当我突出显示页面上的元素时,div框在那里。 Also no issues with validation/inspection. 验证/检查也没有问题。

html: 的HTML:

<div class="mainImage"></div>

css: CSS:

.mainImage {
    text-indent: 100%;
    white-space: nowrap;
    overflow: hidden;
    background-image: url(Images\top.jpg);
    background-repeat: no-repeat;
    width: 100%;
    height: 400px;
}

Attempted: 尝试:

  • Forward slash filepath 正斜杠文件路径
  • Quotes ' and " 引号“和”
  • Both background declarations in the same statement 同一声明中的两个后台声明

The link is correct, tested. 链接正确,经过测试。

Thank you. 谢谢。

.mainImage {
    text-indent: 100%;
    white-space: nowrap;
    overflow: hidden;
    background-image: url('Images/top.jpg');
    background-repeat: no-repeat;
    width: 100%;
    height: 400px;
}

this works for me 这对我有用

你可以试试看

background-image: url("Images/top.jpg");

Where does the Image folder exist? 图像文件夹在哪里? Is it in the same path your HTML file is? 它与HTML文件的路径是否相同? and did you "connect" the css to the html file? 并且您是否将CSS“连接”到html文件? the only attribute that does not work is the image? 唯一不起作用的属性是图像? Did you check that the image is JPG? 您检查图像是否为JPG吗? Maybe try to set some fixed width, maybe give some background color (background-color: red;), then we can find where the problem is... 也许尝试设置一些固定的宽度,也许给一些背景颜色(background-color:red;),那么我们可以找到问题所在。

.mainImage {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
background-image: url('../Images/top.jpg');
background-repeat: no-repeat;
width: 100%;
height: 400px;
}

Put ../ before the path. 将../放在路径之前。

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

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