CSSで背景画像を指定して、スマホで見ると背景が途中で切れて(ずれて)表示される
.container
の幅を width:100%
にして、background:url(bg.jpg) top center no-repeat
のように背景画像を指定します。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>CSS</title>
<style type="text/css">
body { margin:0; padding:0; }
.container {
width:100%;
height:1278px;
background:url(bg.jpg) top center no-repeat;
}
.inner {
width:960px;
background:yellow;
margin:0 auto;
}
</style>
</head>
<body>
<div class="container">
<div class="inner">ここは、inner エリアです。</div>
</div>
</body>
</html>
PCでは問題なく、背景画像が表示されます。
スマホだと背景が途中で切れて(ずれて)表示されます。
min-width
を指定すれば解決します。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>CSS</title>
<style type="text/css">
body { margin:0; padding:0; }
.container {
width:100%;
+ min-width:960px;
height:1278px;
background:url(bg.jpg) top center no-repeat;
}
.inner {
width:960px;
background:yellow;
margin:0 auto;
}
</style>
</head>
<body>
<div class="container">
<div class="inner">ここは、inner エリアです。</div>
</div>
</body>
</html>
Author And Source
この問題について(CSSで背景画像を指定して、スマホで見ると背景が途中で切れて(ずれて)表示される), 我々は、より多くの情報をここで見つけました https://qiita.com/4cres/items/96910528e8019b95fba0著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .