最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to embed SVG image icon in input tag? - Stack Overflow

programmeradmin1浏览0评论

I'm trying to embed 'search.svg' image into textbox in AngularJS as shown in the image below

But I didn't get expected result. It's rendering like shown in the image below

I have tried - My html file

<div class="right-inner-addon pull-left col-lg-4">
    <input type="text" class="form-control input-append" />
    <img role="img" src="img/icons/search.svg" />
</div>

My CSS file

.right-inner-addon {
    position: relative;
}
.right-inner-addon input {
    padding-right: 30px;
}
.right-inner-addon img {
    position: absolute;
    right: 0px;
    padding: 10px 12px;
    pointer-events: none;
}

I'm trying to embed 'search.svg' image into textbox in AngularJS as shown in the image below

But I didn't get expected result. It's rendering like shown in the image below

I have tried - My html file

<div class="right-inner-addon pull-left col-lg-4">
    <input type="text" class="form-control input-append" />
    <img role="img" src="img/icons/search.svg" />
</div>

My CSS file

.right-inner-addon {
    position: relative;
}
.right-inner-addon input {
    padding-right: 30px;
}
.right-inner-addon img {
    position: absolute;
    right: 0px;
    padding: 10px 12px;
    pointer-events: none;
}
Share Improve this question edited May 7, 2014 at 13:33 Ex-iT 1,4772 gold badges12 silver badges20 bronze badges asked May 7, 2014 at 13:19 user2067120user2067120 2673 gold badges6 silver badges18 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Make sure you are setting a top: 0; (or any value that fits your needs) on your .right-inner-addon img.

Here is a quick example.

Sample from my project

.dispensary-search {float: right; position: relative;}
.dispensary-search input { width: 300px; height: 32px; margin: 5px;}
.dispensary-search:before {content: ""; position: absolute; right: 10px; top: 0; bottom: 0; width: 20px; background: url(../images/search.svg) no-repeat right center;}
发布评论

评论列表(0)

  1. 暂无评论