【发布时间】:2016-04-11 18:05:17
【问题描述】:
我正在尝试在 css 文件中设置“img src”。我研究了可以使用的不同方法,但它还没有奏效。 如果将 ::after 放在 css 中,则在 Chrome 中不起作用,但在 Firefox 中使用不同的样式。 有点困惑,关于这个解决方案的任何想法: https://jsfiddle.net/er1txx0z/
<label class="control-label"></label>
<button id="btn1" class="btn btn-warning shadow dcweb_search" disabled="true">
<img class="dcweb_search_img" />
</button>
<style>
.dcweb_search{
height: 60px;
width: 60px;
position: relative;
top:-17px
}
.dcweb_search_img{
width:40px;
content:url('https://api.icons8.com/download/c5c8b5ba35e008ea471e9a53c5fa74c03ef6e78c/iOS7/PNG/256/Very_Basic/search-256.png');
}
</style>
【问题讨论】:
-
Firefox 不像 Chrome 那样支持 content 属性。 stackoverflow.com/questions/12262118/…
-
为什么不在
img标签本身中设置src? -
因为在CSS文件中不能设置图片的SRC,必须使用content-url。我无法在 HTML 标记中执行此操作,因为悬停时链接的图像不同!