【问题标题】:CSS text isn't correct, image adress won't workCSS 文本不正确,图片地址不起作用
【发布时间】:2017-08-08 03:58:27
【问题描述】:

如何写正确的地址,代码是:

.slide1 {  
    background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371566801_p17tbs0rrjqdt1u4dnk94fe4b63.jpg)no-repeat center;
}

如何从我的资源文件中放置图像?我试过background-image: url("pic1.jpg") - 这是正确的地址 - 但它不起作用。

我所做的是将幻灯片中的图像放入 css 中,然后将简单的 cod 放入 html 中以显示它。

【问题讨论】:

  • 如果您从 .html 文件结构之外的目录/文件夹中提取图像,则必须指定该路径(例如:url(images/pic1.jpg)

标签: html css image text background


【解决方案1】:

您必须传递 width 和 height 才能使其显示。试试这样:

.slide1 {  
    background: url('http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371566801_p17tbs0rrjqdt1u4dnk94fe4b63.jpg') no-repeat center;
    width: 200px;
    height: 200px;
}

编辑: 如果图像位于您的 css 文件所在的同一目录中,只需使用:

background: url('nameOftheFile.jpg') no-repeat center;

这个话题可能对你来说很有趣:How to go up a level in the src path of a URL in HTML?

【讨论】:

  • 我这样做了,如:.slider { max-width: 400px;高度:260px;边距:20px 自动;位置:相对;
  • 我的问题是如何在我的资源文件中写入 img 文件的路径,不像我找到的示例,在线图片。谢谢!
  • @danut 是和你的css在同一目录下的图片文件吗?
  • 不,它在“网站”目录中,索引和所有其他页面都在其中,采用 HTML 格式。我在索引以外的其他页面上使用了那里的图像,我使用的其他图片在 assets/img/..
  • 我会把它们放在那里,谢谢你的帮助,现在我看到了编辑。再次感谢!
猜你喜欢
  • 2016-03-06
  • 2013-04-06
  • 2017-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-28
  • 2011-09-13
  • 2012-09-12
相关资源
最近更新 更多