2016-04-11 8 views
0

「img src」をCSSファイルに設定しようとしています。私は使用できるさまざまな方法を研究しましたが、それはまだ機能していません。 ::後にcssを入れたら、Chromeでは動作しませんが、Firefoxではさまざまなスタイルで動作します。あなたがbutton要素にbackground-imageとして画像を設定することができます https://jsfiddle.net/er1txx0z/Firefoxのimg content urlとの非互換性

<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> 
+0

FirefoxはChromeのと同じように、コンテンツプロパティをサポートしていません。 http://stackoverflow.com/questions/12262118/content-url-is-not-working-in-firefox –

+0

なぜ 'img'タグ自体にsrcを設定しないのですか? –

+0

CSSファイルではイメージのSRCを設定できないため、代わりにcontent-urlを使用する必要があります。ホバー上のリンクの画像が違うので、HTMLタグではできません! –

答えて

1

: は、このソリューションについての考えを少し混乱します。 imgタグを使用する必要はありません。

.dcweb_search { 
 
    height: 60px; 
 
    width: 60px; 
 
    position: relative; 
 
    top: -17px; 
 
    background-image: url('https://api.icons8.com/download/c5c8b5ba35e008ea471e9a53c5fa74c03ef6e78c/iOS7/PNG/256/Very_Basic/search-256.png'); 
 
    background-size: 40px 40px; 
 
    background-position: center; 
 
    background-repeat: no-repeat; 
 
}
<label class="control-label"></label> 
 
<br> 
 
<button id="btn1" class="btn btn-warning shadow dcweb_search" disabled="true"> 
 
</button>

+0

私は今までこのソリューションを行ってきましたが、私が持っているアイコンでうまく動作していません。とにかくtnxです:)私はアイコンを変更する必要があります –

関連する問題