aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/html/attributes/size/index.html
blob: cbe5fd3aa978ef875905e87dfe96106f8a234026 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
title: 'HTML 属性: size'
slug: Web/HTML/Attributes/size
tags:
  - Attribute
  - HTML
  - Input
  - Reference
  - Select
translation_of: Web/HTML/Attributes/size
---
<p>{{HTMLSidebar}}</p>

<p class="summary"><strong><code>size</code></strong> 属性は、 {{htmlelement('input')}} 要素の幅と {{htmlelement('select')}} 要素の高さを定義します。 <code>input</code> については、 <code>type</code> 属性が {{HTMLElement("input/text", "text")}} または {{HTMLElement("input/password", "password")}} の場合は文字数です。これは 0 以上の整数でなければなりません。 <code>size</code> が指定されていないか、無効な値が指定された場合、入力欄にサイズが宣言されず、そのフォームコントロールはユーザーエージェントに基づいた既定の幅になります。 CSS が幅に影響を与えるプロパティで要素を対象としている場合は、 CSS が優先されます。</p>

<p><code>size</code> 属性は制約検証には影響しません。</p>

<h2 id="Examples" name="Examples"></h2>

<p>一部の入力型で <code>size</code> を指定すると、入力欄の幅を制御することができます。 select に size を追加すると、閉じた状態のときにいくつの選択肢が見えるかを定義します。</p>

<pre class="brush: html notranslate">&lt;label for="fruit"&gt;Enter a fruit&lt;/label&gt; &lt;input type="text" size="15" id="fruit"&gt;
&lt;label for="vegetable"&gt;Enter a vegetable&lt;/label&gt; &lt;input type="text" id="vegetable"&gt;

&lt;select name="fruits" size="5"&gt;
  &lt;option&gt;banana&lt;/option&gt;
  &lt;option&gt;cherry&lt;/option&gt;
  &lt;option&gt;strawberry&lt;/option&gt;
  &lt;option&gt;durian&lt;/option&gt;
  &lt;option&gt;blueberry&lt;/option&gt;
&lt;/select&gt;

&lt;select name="vegetables" size="5"&gt;
&lt;option&gt;carrot&lt;/option&gt;
&lt;option&gt;cucumber&lt;/option&gt;
&lt;option&gt;cauliflower&lt;/option&gt;
&lt;option&gt;celery&lt;/option&gt;
&lt;option&gt;collard greens&lt;/option&gt;
&lt;/select&gt;</pre>

<p>{{EmbedLiveSample('Examples', '100%', 200)}}</p>

<h2 id="Specifications" name="Specifications">仕様書</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">仕様書</th>
   <th scope="col">状態</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'input.html#attr-input-size', 'size attribute')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5.1', 'input.html#attr-size-accept', 'size attribute')}}</td>
   <td>{{Spec2('HTML5.1')}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>

<p>{{Compat("html.elements.attribute.size")}}</p>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li><code><a href="/ja/docs/Web/HTML/Attributes/maxlength">maxlength</a></code></li>
 <li><code><a href="/ja/docs/Web/HTML/Attributes/minlength">minlength</a></code></li>
 <li><code><a href="/ja/docs/Web/HTML/Attributes/pattern">pattern</a></code></li>
</ul>