12月更新・前月(11月)の人気記事トップ10 12/07/2023
- ( 02 ↑) 【Mac】macOSをHigh SierraからMontereyにアップグレード
- ( 01 ↓) 【iPhone / iPad】iPhoneでSuicaをクレジットカード無しで使う方法
- ( 03 – ) 【iPhone / iPad】iPhoneのツイッターアプリでユーザー名をコピーする方法
- ( 05 ↑) 【Labs】position:absoluteとwidth:100%を指定すると横幅の設定がうまくいかない場合の対処方法について
- ( 06 ↑) 【jQuery】入門2. jQueryをHTMLに組み込む
- (圏外↑) 【jQuery】入門11. switch文による条件分岐
- (圏外↑) 【Mac】Safariでソースコードを見る方法
- ( 09 ↑) 【Mac】横画面で撮影した動画をYouTubeショート用にMacのiMovieで縦画面に編集する方法
- (圏外↑) 【jQuery】入門7. jQueryで新しいWindowを開く
- (圏外↑) 【iPhone iPad】iPhoneやiPadの音量を細かく調整する方法
【CSSリファレンス】padding
こんにちは(・∀・)
CSSプロパティをご紹介します。今回ご紹介するCSSプロパティはpaddingです。
概要
paddingプロパティを使用して要素の枠線と文字列(内容)の間隔を指定します。四辺まとめて指定する方法と、個別に指定する方法があります。
.sample {
padding: 10px;
}
適用要素
すべての要素
tr要素・thead要素・tbody要素・tfoot要素col要素・colgroup要素を除く
指定できる値
- 実数値+単位
- paddingを実数値+単位で設定
- %値
- paddingを親要素の幅に対する割合で設定
- auto
- 自動設定。
初期値
auto
指定方法
- padding:10px;
- 上下左右
- padding:10px 20px;
- 上下 左右
- padding:10px 20px 10px;
- 上 左右 下
- padding:10px 20px 10px 20px;
- 上 右 下 左
0の場合単位はなくても可。autoの指定もできます。
個別に指定
- padding-top:
- 上
- padding-right:
- 右
- padding-bottom:
- 下
- padding-left:
- 左
1. サンプル
要素にpaddingを指定します。
HTML
<p class="demo">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eget tellus porttitor odio vulputate bibendum vel non nulla. Fusce non elementum nunc, in elementum dolor. Ut ante nulla, porta in felis nec, egestas tempor metus. Mauris posuere leo elit, nec rhoncus nibh fermentum id. Nam commodo rhoncus posuere. Nunc vel imperdiet eros. Vivamus laoreet leo eros, eget scelerisque quam sodales venenatis. Integer magna libero, semper ac ultricies id, interdum vel orci. Aenean euismod sapien eget maximus sagittis.
</p>
CSS
.demo {
padding: 10px;
}
Result
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris eget tellus porttitor odio vulputate bibendum vel non nulla. Fusce non elementum nunc, in elementum dolor. Ut ante nulla, porta in felis nec, egestas tempor metus. Mauris posuere leo elit, nec rhoncus nibh fermentum id. Nam commodo rhoncus posuere. Nunc vel imperdiet eros. Vivamus laoreet leo eros, eget scelerisque quam sodales venenatis. Integer magna libero, semper ac ultricies id, interdum vel orci. Aenean euismod sapien eget maximus sagittis.
要素にpadding:10pxの指定がしてあるのでコンテンツが要素の内側から10px離れて表示されます。
2. サンプル
テーブルのセルにpaddingを指定します。
HTML
<div class="demo2">
<table>
<tr>
<td>サンプルデモ</td>
<td>サンプルデモ</td>
</tr>
</table>
</div>
CSS
.demo2 table td {
padding: 10px;
}
Result
サンプルデモ | サンプルデモ |
テーブルのセルにpadding:10pxの指定がしてあるのでコンテンツがセルの内側から10px離れて表示されます。