2017-02-01 30 views
0

画像を画面全体(100%x 100%)に塗る方法は?CSS:画像を画面全体に塗りつぶす

htmlタグで100%の高さのFlex-Boxを使用していますが、何とか動作しません。

html, body { height: 100%; } 
 

 
.background-image { 
 
    background-image: url(http://placehold.it/400x400); 
 
    background-position: center; 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
} 
 

 
.logo { 
 
    display: flex; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
    align-items: center; 
 
}
<section class="background-image"> 
 
    <div class="logo"> 
 
    <h1 class="title">site-title</h1> 
 
    <h2 class="description">site-description</h2> 
 
    </div> 
 
</section>

答えて

0

あなたは、デフォルトではそれだけで、その中の子どものように背が高くなりますから、あまりにも、.background-imageクラスにheight: 100%;を追加する必要があります。うまく

html, body {height:100%;} 
 

 
.background-image { 
 
    background-image: url(http://placehold.it/400x400); 
 
    background-position: center; 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    height: 100%; 
 
} 
 

 
.logo { 
 
    display: flex; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
    align-items: center; 
 
}
<section class="background-image"> 
 
    <div class="logo"> 
 
    <h1 class="title">site-title</h1> 
 
    <h2 class="description">site-description</h2> 
 
    </div> 
 
</section>

+0

、ここでは動作しますが、私のコンピュータ上で私のコードでは、それは... '高さはありません:100%;' '背景image'には何もしません。 – Timo

+0

@Timoは、この行に 'height'の前に奇妙なユニコード文字があるように見えます。' html、body {height:100%; } '。コードをコピーして貼り付けるか、プレーンテキストエディタを使ってコードを編集してみてください。 –

+0

私のCHROMEおよび/またはATOM EDITORで何か問題がありました。 – Timo

関連する問題