CSSプロパティ早見表

例の h1 { } や #box { } は「どの要素に適用するか」を決める部分です。プロパティはどの要素にも使えます。たとえば color は h1 でも p でも button でも指定できます。どう指定するかは、CSSの指定の仕方を見てください。

色・背景

プロパティ説明例
color文字の色
h1 {
  color: red;
}
background-color背景色
body {
  background-color: #f0f0f0;
}
opacity透明度(0〜1。0で完全に透明)
#box {
  opacity: 0.8;
}

色の指定方法は主に3つあります。

color: red;           /* 色名。種類は限られる */
color: #ff0000;       /* カラーコード(16進数)。Webでは一般的 */
color: rgb(255, 0, 0); /* RGB値。赤・緑・青を0〜255で指定 */

文字

プロパティ説明例
font-size文字の大きさ
p {
  font-size: 20px;
}
font-familyフォントの種類(左から順に、使えるものが選ばれる)
body {
  font-family: "Hiragino Sans", "Meiryo", sans-serif;
}
font-weight太さ(normal, bold など)
h2 {
  font-weight: bold;
}
font-styleスタイル(斜体など)
p {
  font-style: italic;
}
text-align文字の位置(left, center, right)
h1 {
  text-align: center;
}
line-height行の高さ(行間)
p {
  line-height: 1.6;
}
letter-spacing文字間隔
h1 {
  letter-spacing: 2px;
}

余白

プロパティ説明例
margin外側の余白
#box {
  margin: 20px;
}
padding内側の余白
#box {
  padding: 10px;
}

上下左右をまとめて指定できます。

margin: 20px;                 /* 上下左右すべて20px */
margin: 10px 30px;            /* 上下10px、左右30px */
margin: 10px 20px 30px 40px;  /* 上 右 下 左 の順 */

レイアウト

プロパティ説明例
display要素の表示方法(block, inline, flex など)
#menu {
  display: flex;
}
position位置指定(relative, absolute, fixed など)
#ball {
  position: absolute;
}
top / left / right / bottom要素の位置(position を指定したときに効く)
#ball {
  position: absolute;
  top: 50px;
  left: 100px;
}
z-index要素の重なり順(大きいほど手前)
#title {
  position: relative;
  z-index: 10;
}
overflowはみ出した内容の扱い(hidden, scroll など)
#box {
  width: 200px;
  height: 100px;
  overflow: hidden;
}
width幅
#box {
  width: 300px;
}
height高さ
#box {
  height: 200px;
}

装飾

プロパティ説明例
border枠線(太さ 線種 色 の順)
#box {
  border: 2px solid #333;
}
border-radius角を丸くする
button {
  border-radius: 10px;
}
cursorマウスカーソルの形
button {
  cursor: pointer;
}
transform回転・拡大・移動など
#box {
  transform: rotate(15deg);
}

単位

単位意味例
pxピクセル(絶対値)
p {
  font-size: 16px;
}
%親要素に対する割合
#box {
  width: 80%;
}
em親要素のフォントサイズ基準
p {
  padding: 1.5em;
}
remルート(html)のフォントサイズ基準
p {
  font-size: 1.2rem;
}
vh / vw画面の高さ・幅に対する割合
#main {
  height: 100vh;
}

もっと詳しく調べる