使用Sprite图像搜索框​​输入按钮

时间:2012-03-29 09:06:42

标签: html css input search-box

编辑:您可以看到搜索框live here

在我解释之前,让我告诉你我正在使用的代码:

HTML

<div class="SiteSearch">
    <form action="/search" id="searchform" method="get">
        <input x-webkit-speech="" autocomplete="off" type="text" id="gText" name="q" id="q" onblur="if (this.value == '') {this.value = 'Search';}" onfocus="if (this.value == 'Search') {this.value = '';}" value ='' "search" placeholder="Search.."/>
        <input type="submit" id="gBtn"/>
    </form>
</div>

CSS

#Head .SiteSearch {
  top: 12px;
  right: 0;
}

#Head .SiteSearch {
  float: right;
  position: relative;
}

input#gText {
  float: left;
  width: 225px;
  height: 23px;
  line-height: 24px;
  text-indent: 5px;
  font-family: arial,sans-serif;
  font-size: 1em;
  color: #333;
  background: white;
  border: solid 1px #D9D9D9;
  border-top: solid 1px silver;
  border-right: none;
  vertical-align: middle;
  -webkit-appearance: none;
  -webkit-border-radius: 0px;
}

#searchform #gBtn {
  background-image: url('search.png');
  width: 31px;
  height: 27px;
}

#gBtn {
  vertical-align: middle;
  cursor: pointer;
  width: 40px;
  height: 31px;
  line-height: 100%;
  padding: 0;
  font-size: 0;
  text-indent: -999px;
  color: transparent;
  background-position: 0 0;
  border: none;
  -webkit-appearance: none;
  -webkit-border-radius: 0px;
}

input#gBtn:hover {
  background-position: 31px 0;
  border: none;
}

这就是搜索框在IE7与IE8 / IE9上的显示方式:

ImgurImgur

如上所示,输入按钮图像未显示在IE7中。我该如何解决这个问题?

感谢任何帮助。谢谢!

2 个答案:

答案 0 :(得分:1)

我通过修改CSS代码来修复它:

#Head .SiteSearch {
  top: 12px;
  right: 0;
}

#Head .SiteSearch {
  float: right;
  position: relative;
}

input#gText {
  float: left;
  width: 225px;
  height: 23px;
  line-height: 24px;
  text-indent: 5px;
  font-family: arial,sans-serif;
  font-size: 1em;
  color: #333;
  background: white;
  border: solid 1px #D9D9D9;
  border-top: solid 1px silver;
  border-right: none;
  vertical-align: middle;
  -webkit-appearance: none;
  -webkit-border-radius: 0px;
}

/* REMOVED THIS PIECE
  #searchform #gBtn {
  background-image: url('search.png');
  width: 31px;
  height: 27px;
}*/

#gBtn {
  vertical-align: middle;
  cursor: pointer;
  width: 40px;
  height: 31px;
  line-height: 100%;
  padding: 0;
  font-size: 0;
  text-indent: -999px;
  color: transparent;
  background-image: url('search.png'); /* ADDED */
  background-position: 0 0;
  border: none;
  -webkit-appearance: none;
  -webkit-border-radius: 0px;
}

input#gBtn:hover {
  background-image: url('search.png'); /* ADDED - BUT OPTIONAL */
  background-position: 31px 0;
  border: none;
}

答案 1 :(得分:0)

background按钮中写下ackground-image而不是b #gBtn。可能是那个工作