プロが教える店舗&オフィスのセキュリティ対策術

background-size:contain;とかで表示される背景画像に最小値や最大値の指定は行えますか?

画面幅をあまり小さくした場合には、例えば横幅が400px以下の背景画像にならないように出来るのでしょうか?大きい場合にはその逆で、1200pxを超えたらそれ以上は大きくならないといった具合に…。

出来れば、画面幅を指定して別のCSSに切りかえるなどではなく、普通のCSS定義で出来れば嬉しいのですが、これは不可能でしょうか?
ちなみに、min-widthなどの定義では背景画像は変化が見られませんでした…。

お詳しい方、アドバイスいただけないでしょうか。

A 回答 (2件)

ちなみにサンプル



★Another HTML Lint - Gateway( http://www.htmllint.net/html-lint/htmllint.html# )
 の<DATA>にて検証済みのHTML5
★W3C CSS 検証サービス( http://jigsaw.w3.org/css-validator/#validate_by_ … )
 にて検証済みのCSS3
★タブは_に置換してあるので戻すこと
※ background-sizeは、ルート要素---htmlとbody要素には・・・

【引用】____________ここから
For documents whose root element is an HTML HTML element [HTML401] or an XHTML html element [XHTML11]: if the computed value of ‘background-image’ on the root element is ‘none’ and its ‘background-color’ is ‘transparent’, user agents must instead propagate the computed values of the background properties from that element's first HTML BODY or XHTML body child element. The used values of that BODY element's background properties are their initial values, and the propagated values are treated as if they were specified on the root element. It is recommended that authors of HTML documents specify the canvas background for the BODY element rather than the HTML element.
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ここまで[CSS Backgrounds and Borders Module Level 3( http://www.w3.org/TR/2014/CR-css3-background-201 … )]より

<!doctype html>
<html>
<head>
_<meta charset="utf-8">
_<title>サンプル</title>
_<meta name="description" content="">
_<meta name="author" content="ORUKA1951">
<style media="screen">
<!--
html,body{margin:0;padding:0;}
body>article{
_width:80%;
_min-width:400px;
_max-width:800px;
_margin:0 auto;
_background-image:url("./images/background/conteainer.png");
_background-repeat:repeat-y;
_background-size:contain;
}
h1,h2,h3,h4,h5,h6,p{margin:0 2em;line-height:1.6em;}
body>article>section{min-height:800px;}
-->
</style>
</head>
<body>
_<article><!-- articleとはheader,section,footerを持つであろう一連の記事を示す要素 --->
__<header>
___<h1 id="title">Your title</h1>
___<nav>
____<ul>
_____<li><a href="/">Top</a></li>
_____<li><a href="/books">Book</a></li>
_____<li><a href="/links.html">links</a></li>
____</ul>
___</nav>
__</header>
__<section>
___<h2>A smaller heading</h2>
___<p>
___</p>
___<aside>
____<h3>Something aside</h3>
___</aside>
__</section>
__<footer>
___<h3>A nice footer</h3>
___<dl class="document-version">
____<dt id="FIRST-PUBLISHED">First Published</dt>
____<dd>2005-06-10</dd>
____<dt id="LAST-MODIFIED">Last Modified</dt>
____<dd>2005-06-10 12:00:00 (JST)</dd>
___</dl>
__</footer>
_</article>
</body>
</html>
    • good
    • 0

こんなところで聞いたって正解は返ってこない。

必ず仕様書を確認してその解釈がわからないときなどに相談する。これはHTML/CSSとかに限らず、すべての勉強に言えること
3.9. Sizing Images: the ‘background-size’ property( http://www.w3.org/TR/2014/CR-css3-background-201 … )
 Value: <bg-size> [ , <bg-size> ]*
・・・・・
<bg-size> = [ <length> | <percentage> | auto ]{1,2} | cover | contain
・・・・・
 max-widthとかmin-widthはありません。

 理由はそれが『背景』だからです。
 よって、あるブロックないし画像を作ってそのブロックのサイズを指定して、それに背景--ないし画像のサイズを指定すればよい。背景と考えるからむつかしくなる。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!