2016-08-03 10 views
2

背景画像をページ全体に広げたいと思っています。これは、私がページに追加する可能性のある他のコントロール/要素の上に置かれていることを除いて、必要に応じて機能します。私は、ページ全体にまたがってテキスト/イメージを追加するだけでなく、イメージをバックグラウンドとして持つことができるようにするために何を変更するのですか?これは現在の構文です:HTML画像が他のコントロールの上に表示される

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<style type="text/css"> 
    html {height:100%;} 
    body {height:100%; margin:0; padding:0;} 
    #bg {position:fixed; top:0; left:0; width:100%; height:100%;} 
    #content {position:relative; z-index:1;} 
</style> 
<center> 
    <div> 
    <font size="90" color="red">Today Is November 3<sup>rd</sup> 2015</font> 
    </div> 
</center> 
</head> 

<body> 
<div id="bg"><img src="C:\KittyKat.jpg" width="100%" height="100%" alt="1stDay" /> 
<font size="30" color="red">Pic 1</font><br>  
<img src="C:\1jpg" alt="" style="width:450px;height:500px;"> 
</body> 
</html> 
+0

その後は、 'C使用する必要があります:' body'または 'div' –

+0

@SyamPillaiの背景画像として\ KittyKat.jpg'を - 私はあなたをフォローしていません。ちょうどhtml/cssを学ぶので、すべての構文/手順を確認してください。 –

+0

''要素は廃止され、廃止されました。実際のコードでは使用しないでください。 –

答えて

3

を使用してDIVの背景として画像を作る私はテストそれのためのデモ映像を使用。ここに作業コード: z-index: -1;#bgに追加するだけです。

html {height:100%;} 
 
    body {height:100%; margin:0; padding:0;} 
 
    #bg {position:fixed; top:0; left:0; width:100%;z-index:-1; height:100%;} 
 
    #content {position:relative; z-index:10;}
<center> 
 
    <div> 
 
    <font size="90" color="red">Today Is November 3<sup>rd</sup> 2015</font> 
 
    </div> 
 
</center> 
 

 
<body> 
 
<div id="bg"> 
 
<img src="https://www2.palomar.edu/pages/testwritingstrategies/files/2015/02/online-test-fotolia_60995176.jpg" width="100%" height="100%" alt="1stDay" /> 
 
</div> 
 
<font size="30" color="red">Pic 1</font><br>  
 
<img src="http://authentic-scandinavia.com/system/images/tours/photos/155/thumbnail.jpg?1370424008" alt="" style="width:450px;height:500px;">

+0

それはそれを得ました!ありがとうございました –

2

私はz-indexを使用します。要素の順序を変更することができます。だから、z-index: 1;を持つ要素は、z-index: 0;

<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<style type="text/css"> 
 
    html {height:100%;} 
 
    body {height:100%; margin:0; padding:0;} 
 
    #bg {position:fixed; top:0; left:0; width:100%; height:100%;} 
 
    #backgroundImage{z-index: -1;} 
 
    #content {position:relative; z-index:1;} 
 
</style> 
 
<center> 
 
    <div> 
 
    <font size="90" color="red">Today Is November 3<sup>rd</sup> 2015</font> 
 
    </div> 
 
</center> 
 
</head> 
 

 
<body> 
 
<div id="bg"><img src="C:\KittyKat.jpg" id="backgroundImage" width="100%" height="100%" alt="1stDay" /> 
 
<font size="30" color="red">Pic 1</font><br>  
 
<img src="C:\1jpg" alt="" style="width:450px;height:500px;"> 
 
</body> 
 
</html>

+0

これはまだdivタグの何かをカバーする背景画像を持っています....画像とテキストPic 1は隠されています –

+0

次に、Zインデックスを置く: 1; CSSの画像に直接スタイルを適用します。 z-indexを追加するために投稿を編集しました:-1; divの代わりに背景画像に追加します。 – Taylor

+0

同じ結果です。背景画像なし。 –

2

代わりの要素として画像を置くことで要素の前に表示されるあなたはdiv要素の背景画像のプロパティを設定しようとしましたか?それはあなたが探している効果を提供するはずです。次のルールをCSSファイルに追加します。

#bg { 
    background-image: url("C:\KittyKat.jpg"); 
    width:100vw; 
    height:100vh; 
} 
+0

他の要素や属性は表示されますが、背景イメージは表示されません。 –

+0

@RedLightGreenLightあなたのニーズを満たすように編集された答え。 –

2

CSS

<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<style type="text/css"> 
 
    html {height:100%;} 
 
    body {height:100%; margin:0; padding:0;} 
 
    #bg { 
 
    position:fixed; 
 
    width:100vw; 
 
    height:100vh; 
 
    background: url('C:\KittyKat.jpg'); 
 
    background-size: cover; 
 
    } 
 
    #content {position:relative; z-index:1;} 
 
</style> 
 
<center> 
 
    <div> 
 
    <font size="90" color="red">Today Is November 3<sup>rd</sup> 2015</font> 
 
    </div> 
 
</center> 
 
</head> 
 

 
<body> 
 
<div id="bg"></div> 
 
<font size="30" color="red">Pic 1</font><br>  
 
<img src="C:\1jpg" alt="" style="width:450px;height:500px;"> 
 
</body> 
 
</html>

+0

これは本文のテキスト/イメージを表示しますが、実際には背景イメージを表示しません。 –

+0

編集した背景画像がまだ私のページに表示されていなくても。 –

関連する問題