概要
要素の背景は、
背景の色、画像、原点と寸法、反復方法などです。
要素の高さは、コンテンツの上端と下端との距離を言います。
height プロパティで指定しますが、その指定する内容も、box-sizing プロパティによりコンテンツ領域の高さか境界領域の高さかを指定する事ができます。
尚、ブロックレベル要素での要素に含まれる行ボックスの最小の高さや、非置換インライン要素での行ボックスの高さの計算に使われる高さは line-height プロパティで指定します。
- 1.background : 要素の背景を指定する一括指定プロパティ
- 2.background-color : 要素の背景の色を指定する個別指定プロパティ
- 3.background-image : 要素の背景画像を指定する個別指定プロパティ
- 4.background-position : 要素の背景画像の初期位置を指定する個別指定プロパティ
- 5.background-size : 要素の背景画像の寸法を指定する個別指定プロパティ
- 6.background-repeat : 要素の背景画像の反復方法を指定する個別指定プロパティ
- 7.background-attachment : 要素の背景画像の位置をビューポートの中に固定するか、包含ブロックと一緒にスクロールするかを設定する個別指定プロパティ
- 8.background-origin : 要素の背景配置領域を設定する個別指定プロパティ
- 9.background-clip : 要素の背景画像の要素の背景の <color> または <image> を境界の下まで拡張するかどうかを設定する個別指定プロパティ
- 1.概要
- 2.インライン要素への背景の指定
- 3.要素の背景の適用方法
- 4.計算値(継承)
- 5.一括指定プロパティと初期値
- 6.おまけ
- 7.付記
インライン要素への 背景の指定
- cdvSample021
> * { outline: solid1px ; }currentColor - cdvSample021
> *:nth-of-type(2) { background: url(./sample32.png)no-repeat ; }#ffccff
- <div class=
"cdvSample021"> - <div>ブロック<br>要素</div>
- <span>インライン要素</span
- ><span>インライン要素</span
- ><span>インライン要素</span>
- <div>ブロック<br>要素</div>
インライン要素の閉じタグを複数行に渡らせることで、タグ内に改行コードを押し込む対応をしています。
テキスト,インライン要素後の改行コードは1つのスペース相当と扱われてしまう為です。
要素
要素
要素の背景の適用方法
- cdvSample010
> div { outline: solid1px ; padding: 1em; border: solid1em ; overflow: hiddentransparent scroll ; height: 6em; }
- <div class=
"cdvSample031"> - <div style=
"">壱<br>弐<br>参<br><br><br><br><br></div></div>
例示の雛型です。style属性を書き換えて例示しています。
弐
参
- background-color: #ffccff;
- background-image: url(./sample16.png)
,url(./sample32.png) ; - background-repeat: no-repeat;
- background-position: top left,top right;
- background-clip: padding-box
,content-box ;,border-box
background-color と background-clip の値を指定しました。背景色は、一番下の背景画像レイヤーに関連付けられているbackground-clip値に従ってクリッピングされます。
例示では、background-clip の値は3つありますが、background-image の値は2つだけですので背景画像レイヤーに関連付けられているのは2つまでです。
弐
参
- background-color: #ffccff;
- background-image: url(./sample32.png);
- background-repeat: repeat;
- background-position: top right;
- background-attachment: fixed;
- background-origin: content-box;
- background-clip: padding-box;
background-attachment プロパティに fixed の値を指定しました。fixed は、背景はビューポートに関して固定されています。
弐
参
- background-color: #ffccff;
- background-image: url(./sample32.png);
- background-repeat: repeat;
- background-position: top right;
- background-attachment: local;
- background-origin: content-box;
- background-clip: border-box;
background-attachment プロパティに local の値を指定しました。local は、背景は要素のコンテンツに関して固定されています。スクロール可能な領域にはボーダー領域が含まれていないため、スクロール可能な要素の場合、background-clipのborder-box値はpadding-boxと同じように扱われます。
弐
参
- background-color: #ffccff;
- background-image: url(./sample32.png);
- background-repeat: repeat;
- background-position: top right;
- background-attachment: scroll;
- background-origin: content-box;
- background-clip: border-box;
- border: dashed 1em;
- border-radius: 2em;
境界線 を指定しました。背景は境界線の後ろに描画されます。
弐
参
計算値 (継承)
- cdvSample041
> div { background-image: url(./sample16.png),url(./sample32.png) ; background-repeat: no-repeat; background-position: top left,top right ; outline: solid1px ; padding: 1em; }currentColor - cdvSample041
> div { background-image: url(./sample16.png)> div ,url(./sample32.png) ; background-repeat: no-repeat; background-position: inherit; outline: solid1px ; height: 6em; }currentColor
- <div class=
"cdvSample041"> - <div style=
""><div></div></div></div>
例示の雛型です。子要素のstyle属性を書き換えて例示しています。
background-position: inherit; を子要素に指定する事により、継承による計算値の確認を意図しています。
- background-image: url(./sample16.png);
親要素の background-image プロパティの値を1つに上書きしました。background-image プロパティの数でレイヤーの数が決まるので、親要素のレイヤー1つとなります。
一括指定プロパティ と初期値
- height: 6em; background: url(./sample32.png);
- height: 6em; background: url(./sample32.png); background: #ffccff;
background: #ffccff の記述により、background: none
おまけ
付記
次は、上位のページの「離珠のCSS」に戻ります。
前のページの「要素の高さ」はこちらです。
背景に対して実際に記述する為のプロパティについては、以下のページです。
- 1.background : 要素の背景を指定する一括指定プロパティ
- 2.background-color : 要素の背景の色を指定する個別指定プロパティ
- 3.background-image : 要素の背景画像を指定する個別指定プロパティ
- 4.background-position : 要素の背景画像の初期位置を指定する個別指定プロパティ
- 5.background-size : 要素の背景画像の寸法を指定する個別指定プロパティ
- 6.background-repeat : 要素の背景画像の反復方法を指定する個別指定プロパティ
- 7.background-attachment : 要素の背景画像の位置をビューポートの中に固定するか、包含ブロックと一緒にスクロールするかを設定する個別指定プロパティ
- 8.background-origin : 要素の背景配置領域を設定する個別指定プロパティ
- 9.background-clip : 要素の背景画像の要素の背景の <color> または <image> を境界の下まで拡張するかどうかを設定する個別指定プロパティ