カテゴリー: CSS

HTML&CSSを練習してみましょう

HTML初級編

See the Pen aGNzZj by noce (@miuratta) on CodePen.

CSS初級編

See the Pen mLPddL by noce (@miuratta) on CodePen.

ボタンを押したらどうしたいですか?
いろいろやってみましょう

  1. 文字サイズを変える
  2. 背景色を変える
  3. 文字の色を変える
  4. ボタンの内側の余白を変える
  5. 角丸を変える
  6. ボタンの幅を変える
  7. 枠線をつける: (例) border:solid 5px #89c3eb;
    実線:solid   点線:dotted    
    破線: dashed   2重線: double

よく使うCSSプロパティ一覧

フォント関連

color 文字の色
font-size 文字の大きさ
font-weight 文字の太さ
font-family 文字の字体(フォント)の指定

テキスト関連

text-align 行揃え(左寄せ、中央揃え、右寄せなど)
text-decoration 文字の装飾(下線、上線など)
line-height 行間の高さ
letter-spacing 文字間隔
text-indent 文章の1行目の字下げ(インデント)の設定

幅・高さ

width
height 高さ

ボックス関連

margin 外部余白(一括指定は時計回り) margin:10px 8px 5px 8px;
(上)(右)(下)(左)
[margin-top] [margin-right] [margin-bottom] [margin-left]
padding 内部余白(一括指定は時計回り) padding:10px 8px 5px 8px;
(上)(右)(下)(左)
[padding-top] [padding-right] [padding-bottom] [padding-left]
border 枠線(線種 太さ 色) border: solid 1px #000000;
[solid:実線] [dashed:破線] [dotted:点線] など
border-radius 角丸の指定
border-collapse tableの各セルの枠線を重ねるかどうかを指定(tableタグに指定する) border-collapse: collapse;
(枠線を重ねる)
box-shadow ぼかしの影を指定 box-shadow: 3px 3px 5px #333;
box-sizing ボックスサイズの算出方法を指定 box-sizing: border-box;
(paddingとborderを幅と高さに含める)

背景関連

background-color 背景色
background-image 背景画像 background-image: url();
background-image: url(),url(); 複数指定
background-repeat 背景画像の繰り返し指定 background-repeat: no-repeat;
background-repeat: no-repeat,repeat-x; 複数指定
background-position 背景画像の位置 background-position: center top;
background-position: center top,right bottom; 複数指定

リスト関連

list-style-type リストマークの種類を指定 list-style-type:none;

その他

opacity 半透明の指定 opacity: 0.7;
display 表示形式 display: block;
a:hover マウスオーバー時のCSSを定義する
cursor カーソルの形
z-index 要素の重なり順序を指定
float 左または右に寄せて配置する。後に続く内容はその反対側に回り込む。

flexbox

flexboxを使ってみましょう

flex-container

item
item
item
item
item

初期状態

<div class="flex-container">
<div class="flex-item">item</div>
<div class="flex-item">item</div>
<div class="flex-item">item</div>
<div class="flex-item">item</div>
<div class="flex-item">item</div>
</div>
item
item
item
item
item

このitemたちを横並びにしたい

まず、単純に横並びにします。

flex-containerdisplay: flex;を1行加えるだけで、floatを使うより簡単に横並びになります。

.flex-container{
display: flex;
}

item
item
item
item
item

flex-containerにできるいろいろ

justify-content横方向の位置

全体の幅に合わせてitemをどのように配置するかを指定します。

containerのjustify-contentspace-betweenを指定すると、左右は余白なしで残り余白を均等割りします。


.flex-container{
display: flex;
justify-content: space-between;
}

item
item
item
item
item


justify-content:
flex-start左寄せ(デフォルト)
flex-end右寄せ
center中央寄せ
space-between残り余白の均等割り
space-around左右余白 + 均等割り


flex-wrapitemの折り返しの指定

全体の幅からはみ出す時のitemの折り返しを指定します。

containerにflex-wrap: wrap;を指定すると、はみ出す場合折り返します。


.flex-container{
display: flex;
flex-wrap: wrap;
}

item
item
item
item
item
item
item
item
item


flex-wrap:
nowrap折り返し無し(デフォルト)
wrapはみ出す場合折り返す
wrap-reverse幅が狭くなると上へと折り返す


align-items縦方向の位置

縦方向にitemをどのように配置するかを指定します。

containerのalign-itemscenterを指定すると、itemの中央揃えで配置されます。


.flex-container{
display: flex;
align-items: center;
}

item
item
item
item
item
item


.flex-container{
display: flex;
align-items: baseline;
}

item
item
item
item
item
item


align-items:
stretch(デフォルト)
flex-start上寄せ
flex-end下寄せ
center中央寄せ
baseline文字のベースラインに合わせる


flex-directionitemを縦並び・横並びにする


.flex-container{
flex-direction: column-reverse;
}
.flex-item{
width: 200px;
}

item1
item2
item3
item4
item5


flex-direction:
row横並び(デフォルト)
row-reverse横並びで順番反対
column縦並び
column-reverse縦並びで順番反対


align-content複数行にまたがった縦並びの位置


.flex-container{
display: flex;
align-content:space-between;
flex-wrap: wrap;
}

item
item
item
item
item
item
item
item
item
item
item
item
item
item
item
item
item


align-content:
stretch(デフォルト)
flex-start上寄せ
flex-end下寄せ
center中央寄せ
space-between
space-around


flex-itemにできるいろいろ

orderitemの並ぶ順序


.item1{
order: 1;
}

item1
item2
item3


order:
0(デフォルト)
2数値で指定


flex-grow余りがあった時のitemの伸びる倍率


.item1{
flex-grow: 1;
}
.item2{
flex-grow: 2;
}

item1
item2
item3


flex-grow:
0(デフォルト)
2数値で指定


flex-shrinkitemの縮む倍率


flex-shrink:
1(デフォルト)
2数値で指定


flex-basisベースとなる長さ、或いは最小の長さ


.item1{
flex-basis: 350px;
}

item1
item
item
item


flex-basis:
auto(デフォルト)
350px数値で指定


flexflex-grow,flex-shrink,flex-basisをまとめて指定


.flex-item{
flex: 1 1 30%;
}

item
item
item
item
item
item
item
item
item

使用例

沢山のBOXを1列の個数を保ってflexで並べる

See the Pen flex by noce (@miuratta) on CodePen.

沢山のBOXを最低の幅を保ってflexで並べる

See the Pen flex by noce (@miuratta) on CodePen.

flexboxを使ってロゴを左、メニューを右に配置する

See the Pen flexbox by noce (@miuratta) on CodePen.


Copyright © 2025 miuratta note

Theme by Anders NorenUp ↑