margin: ***; padding: ***;

ブラウザ
  • IE
  • Cr
  • Sf
  • Fx
  • O
プロパティ

margin はマージン(外側の余白)を、padding はパディング(内側の余白)を指定するプロパティです。

このプロパティをfieldset要素に対して設定すると、部品グループの余白を調整することができます。


fieldset {
margin: 0 0 20px;
padding: 0 20px 15px;
}

プロパティ名 説明
margin 数値+単位(px 等)またはパーセント マージンの大きさを指定
padding 数値+単位(px 等)またはパーセント パディングの大きさを指定

margin の値には auto(自動)を指定することもできます。

マージンとパディングの指定については、以下のページをご覧ください。

使用例


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>文書のタイトル</title>

<style type="text/css">

fieldset.example {
margin: 0 0 20px;
padding: 0 20px 15px;
}

fieldset p {
margin-bottom: 1em;
}
fieldset input {
width: 200px;
}

</style>

</head>
<body>

<form method="post" action="example.cgi">

<p>余白を調整した例</p>

<fieldset class="example">
<legend>申込者</legend>
<p>お名前:<input type="text" name="name1" size="30"></p>
<p>ご住所:<input type="text" name="address1" size="30"></p>
</fieldset>

<fieldset class="example">
<legend>お届け先</legend>
<p>お名前:<input type="text" name="name2" size="30"></p>
<p>ご住所:<input type="text" name="address2" size="30"></p>
</fieldset>

<p>デフォルトでは次のように表示されます</p>

<fieldset>
<legend>申込者</legend>
<p>お名前:<input type="text" name="name3" size="30"></p>
<p>ご住所:<input type="text" name="address3" size="30"></p>
</fieldset>

<fieldset>
<legend>お届け先</legend>
<p>お名前:<input type="text" name="name4" size="30"></p>
<p>ご住所:<input type="text" name="address4" size="30"></p>
</fieldset>

<p><input type="submit" value="送信する"></p>

</form>

</body>
</html>

表示例

余白を調整した例

申込者

お名前:

ご住所:

お届け先

お名前:

ご住所:

デフォルトでは次のように表示されます

申込者

お名前:

ご住所:

お届け先

お名前:

ご住所:

  • サンプルのため送信できません。