【发布时间】:2023-03-06 15:21:01
【问题描述】:
我正在尝试将自定义图像包含为图标,而不是通常情况下来自 Font Awesome 的图像。因此,在我的 HTML 按钮中,我引用了 CSS 类,其中包含我想用作图标的本地图像的背景图像 url。但是,它没有显示在浏览器中。请注意,所有代码都经过全面验证。
HTML:
<div id="search">
<input type="text" class="searchTerm" placeholder="What are you looking for?">
<button type="submit" class="searchButton">
<i class="icon"></i>
</button>
CSS:
.icon {
background: url('../imgs/search-icon.png');
height: 20px;
width: 20px;
}
小提琴:
#search {
width: 100%;
position: relative;
}
.searchTerm {
float: left;
width: 100%;
border: 3px solid #00B4CC;
padding: 5px;
height: 20px;
border-radius: 5px;
outline: none;
color: #9DBFAF;
}
.searchTerm:focus {
color: #00B4CC;
}
.searchButton {
position: absolute;
right: -50px;
width: 40px;
height: 36px;
border: 1px solid #00B4CC;
background: #00B4CC;
text-align: center;
color: #fff;
border-radius: 5px;
cursor: pointer;
font-size: 20px;
}
.icon {
background: url('https://postimg.org/image/bfac47qav/');
}
<div id="search">
<input type="text" class="searchTerm" placeholder="What are you looking for?">
<button type="submit" class="searchButton">
<i class="icon"></i>
</button>
</div>
【问题讨论】:
-
你能不能把它上传给一些在线编辑,至少我们可以看到结构。
-
您是否尝试过指定
background-size,例如:background-size: contain?另外,您能否确认相关图标的文件路径有效? -
我会上传给编辑@PannaDas
-
@mts396 请分享链接
-
@UncaughtTypeError 我可以确认文件路径是正确的。我尝试了 background-size: contains 和其他尺寸,仍然没有出现