2012-05-01 17 views
1

と実装CSSスプライトこのボタンは、CSSスプライトCSS:入力ボタン画像

<input type="image" src="/images/search-button.png" value="" id="search-button"> 

の前で、私は私の検索フォームのいずれかでCSSスプライトを実装しようとしているとの問題は、私は

を使用した場合ということです
<input id="search-button" class="sprites1" type="submit" value=""> 

このようになります。

enter image description here

あなたは右の画像を見ることができるように、右を見ていないが、それはクリック-ことができます。

その後、私はそれが右に見える

<span id="search-button" class="sprites1"></span> 

enter image description here

てみました!しかし!!私はそれをクリックすることはできません。

私のCSSスプライトコードはここにあります。

私はそれが私が欲しいと私はそれをクリックすることができます見えるように実装する必要がありますか?

.sprites1 { 
     background: url('result.png'); 
    } 
#search-button {background-position: -0px -462px; 

       width:16px; height:16px; float:right; } 

答えて

1

ここでの問題は、ブラウザが要素で使用するデフォルトのCSSです。あなたはそのCSSをリセットしようとする必要があります。私は、多くの場合、次のコードを使用:あなたのinput要素にcssresetbuttonクラスを追加

/* reset css of buttons */ 
.cssresetbutton { 
    border-width: 0px; 
    border-style: none; 
    background: inherit; 
    font: inherit; 
    color: blue; 
    padding: 0px; } 

.cssresetbutton:active { 
    border-width: 0px; 
    border-style: none; 
    background: inherit; 
    outline: 0; 
    box-shadow: none; } 

試して、それが動作するかどうかを確認します。

編集: input [type = submit]要素を使用しないこともできます。例:

<span id="search-button" class="sprites1" onClick="document.getElementById('formid').submit()"></span> 

クリックすると、#formid要素のフォームが送信されます。

+0

クラスを 'sprites1'クラスと一緒に挿入した後で画像が消えるようになりました – Ali

+1

sprites1クラスの前に挿入していますか? class = "cssresetbutton sprites1"のようになります。違いがあります。 – FRD

+0

それは前か後であるべきですか? – Ali