【CSSリファレンス】background-color - web design lab
にほんブログ村 デザインブログ Webデザインへ PVアクセスランキング にほんブログ村

【CSSリファレンス】background-color


【CSSリファレンス】background-color

こんにちは(・∀・)

CSSプロパティをご紹介します。今回ご紹介するCSSプロパティはbackground-colorです。

概要

background-colorプロパティを使用して背景色を指定します。


.sample {
  background-color: blue;
}
適用要素

すべての要素

指定できる値
transparent
背景を透明にする
背景色
カラーコード、キーワード
初期値

transparent

1. サンプル

body全体に背景色を指定します。

CSS

body {
  background-color: #9fb7d4;
}
Result

サンプルデモはこちら


2.サンプル

フォームに背景色を指定します。

HTML

<p class="demo2"><input type="text"></p>
CSS

.demo2 input {
  background-color: #d49fc2;
}
Result


3. サンプル

フレームに背景色を指定します。

HTML

<p class="demo3">
<iframe src="iframe.html" allowtransparency="true">サンプルデモ</iframe>
</p>
CSS

インラインフレームを表示するHTML。
.demo3 {
  background-color: #d49fc2;
}
インラインフレームに読み込まれるHTML(iframe.html)。
.demo3 iframe {
  background-color: transparent;
}
Result

読み込まれたiframeの背景色にtransparentが指定されているので親要素で指定した背景色が表示されます。


4. サンプル

罫線に背景色を指定します。

HTML

<p class="demo4"><hr></p>
CSS

hr {
  width: 300px;
  height: 2px;
  background-color: #d49fc2;
}
Result



5. サンプル

テキストリンクに背景色を指定します。

HTML

<p class="demo5"><a href="http://example.com/">マウスオーバーでテキストの背景に色がつきます。リンク先はダミーです。</a></p>
CSS

.demo5 a:hover {
  background-color: #d49fc2;
  text-decoration: none;
}
Result

6. サンプル

テーブルに背景色を指定します。

HTML

<div class="demo6">
<table>
<tr>
<td>サンプルデモ</td>
<td>サンプルデモ</td>
</tr>
</table>
</div>
CSS

.demo6 table {
  background-color: #9fb7d4;
}
.demo6 table td {
  background-color: #d49fc2;
}
Result
サンプルデモ サンプルデモ

にほんブログ村 デザインブログ Webデザインへ PVアクセスランキング にほんブログ村