2017-11-06 10 views
1

いいえ、要素が特定の幅に達したときに@mediaタグを使用して写真を置き換えようとしていますが、元々100%に設定されていましたが、私はそれが応答性の問題を引き起こす可能性があるので、私はそれを最大幅と最小幅に変更したと読んだが、ここではコードは変更されていない。@media with width:100%

注:私は幅を変更していない要素が問題

body,html { 
 
    margin: 0; 
 
    height: 100%; 
 
} 
 

 
@media only screen and (min-width: 768px) and (max-width: 1920px) { 
 
    
 
    .container { 
 
    min-width: 768px; 
 
    max-width: 1920px; 
 
    height: 100%; 
 
    background-image: url('https://images.pexels.com/photos/214519/pexels-photo-214519.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb'); 
 
    background-position: center center; 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    }; 
 
}; 
 
@media only screen and (min-width: 300px) and (max-width: 767px) { 
 
    .container { 
 
    min-width: 300px; 
 
    max-width: 767px; 
 
    height: 100%; 
 
    background-image: url('https://images.pexels.com/photos/159146/train-cargo-bow-river-banff-159146.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb'); 
 
    background-position: center center; 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    }; 
 
};
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <link href="style.css" type="text/css" rel="stylesheet" /> 
 
     <meta name="viewport" content="width=device-width" /> 
 
    </head> 
 
    
 
    <body> 
 
<div class="container"></div> 
 
    </body> 
 
</html>
だとは思わないので、私はChromeと.container上の要素を検査使って要素の幅を確認がダウンスケール上767pxに達しました。

+1

メディアシュは、画面サイズのため、いない要素のためのものであるMaxwells.c @ –

+0

のサイズはい、それは本当だしかし目標は、誰かがiPhoneを使っていると言うために、彼らは「X」イメージを持つことになりますですデスクトップ上の誰かが「y」イメージを読み込むでしょう。私は画面サイズを検出してCSSを編集する方法としてメディアを使用しています。 – bignate132

+0

'only screen'ではなく' screen'を設定しようとしています。そして、最小/最大幅を使用する必要はありません.100%を使用できます。 –

答えて

0

だ問題は(のみ}を使用し、};を使用していない)、あなたの終値のブラケットです。

また、最小幅と最大幅の両方を指定する必要はありません。

body,html { 
 
    margin: 0; 
 
    height: 100%; 
 
} 
 

 
@media (min-width: 768px){ 
 
    
 
    .container { 
 
    min-width: 768px; 
 
    max-width: 1920px; 
 
    height: 100%; 
 
    background-image: url('https://images.pexels.com/photos/214519/pexels-photo-214519.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb'); 
 
    background-position: center center; 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    } 
 
} 
 

 
@media (max-width: 767px) { 
 
    .container { 
 
    min-width: 300px; 
 
    max-width: 767px; 
 
    height: 100%; 
 
    background-image: url('https://images.pexels.com/photos/159146/train-cargo-bow-river-banff-159146.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb'); 
 
    background-position: center center; 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    } 
 
}
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <link href="style.css" type="text/css" rel="stylesheet" /> 
 
     <meta name="viewport" content="width=device-width" /> 
 
    </head> 
 
    
 
    <body> 
 
<div class="container"></div> 
 
    </body> 
 
</html>

+0

興味深いことに、フィードバックに感謝します。乾杯 – bignate132

0

不思議なことに、私はそれを理解しました。何かの理由でこの質問Multiple CSS @media conditions don't seem to be workingの解決策は、私がすでにそれを試したにもかかわらず、それを修正しました。ここでは、コード

body,html { 
 
    margin: 0; 
 
    height: 100%; 
 
} 
 
.container{ 
 
    width: 100%; 
 
    height: 100%; 
 
    background-color: black; 
 
} 
 
@media screen and (min-width: 300px) and (max-width: 1000px){ 
 
    .container { 
 
     background-image: url('https://images.pexels.com/photos/7882/light-bulb-light-old.jpg?w=1260&h=750&auto=compress&cs=tinysrgb'); 
 
     background-position: center center; 
 
     background-size: cover; 
 
     background-repeat: no-repeat; 
 
    } 
 
} 
 
@media screen and (min-width: 1001px) and (max-width: 1920px){ 
 
    .container{ 
 
     background-image: url('https://images.pexels.com/photos/531321/pexels-photo-531321.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb'); 
 
     background-position: left center; 
 
     background-size: cover; 
 
     background-repeat: no-repeat; 
 
    } 
 
}
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
    <link href="style.css" type="text/css" rel="stylesheet" /> 
 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
 
    </head> 
 
    
 
    <body> 
 
<div class="container"></div> 
 
    </body> 
 
</html> 
 

 

 
<!-- since I created this in a full screen browser you have to make your broswer window pretty big to get it to change but it does work -->

関連する問題