form_example.html

Download
html 352 lines 11.6 KB
  1<!DOCTYPE html>
  2<html lang="ko">
  3<head>
  4    <meta charset="UTF-8">
  5    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6    <title>HTML 폼 예제</title>
  7    <style>
  8        body {
  9            font-family: Arial, sans-serif;
 10            max-width: 800px;
 11            margin: 0 auto;
 12            padding: 20px;
 13        }
 14        form {
 15            background: #f9f9f9;
 16            padding: 20px;
 17            border-radius: 8px;
 18            margin-bottom: 30px;
 19        }
 20        fieldset {
 21            margin-bottom: 20px;
 22            border: 1px solid #ddd;
 23            border-radius: 4px;
 24            padding: 15px;
 25        }
 26        legend {
 27            font-weight: bold;
 28            padding: 0 10px;
 29        }
 30        .form-group {
 31            margin-bottom: 15px;
 32        }
 33        label {
 34            display: block;
 35            margin-bottom: 5px;
 36            font-weight: bold;
 37        }
 38        input[type="text"],
 39        input[type="email"],
 40        input[type="password"],
 41        input[type="number"],
 42        input[type="tel"],
 43        input[type="url"],
 44        input[type="date"],
 45        input[type="time"],
 46        input[type="datetime-local"],
 47        input[type="search"],
 48        textarea,
 49        select {
 50            width: 100%;
 51            padding: 10px;
 52            border: 1px solid #ddd;
 53            border-radius: 4px;
 54            box-sizing: border-box;
 55        }
 56        input:focus, textarea:focus, select:focus {
 57            outline: none;
 58            border-color: #4CAF50;
 59            box-shadow: 0 0 5px rgba(76, 175, 80, 0.3);
 60        }
 61        input:invalid {
 62            border-color: #f44336;
 63        }
 64        button {
 65            background-color: #4CAF50;
 66            color: white;
 67            padding: 12px 24px;
 68            border: none;
 69            border-radius: 4px;
 70            cursor: pointer;
 71            font-size: 16px;
 72        }
 73        button:hover {
 74            background-color: #45a049;
 75        }
 76        .checkbox-group, .radio-group {
 77            display: flex;
 78            flex-wrap: wrap;
 79            gap: 15px;
 80        }
 81        .checkbox-group label, .radio-group label {
 82            display: flex;
 83            align-items: center;
 84            font-weight: normal;
 85            cursor: pointer;
 86        }
 87        .checkbox-group input, .radio-group input {
 88            margin-right: 8px;
 89            width: auto;
 90        }
 91        .hint {
 92            font-size: 0.85em;
 93            color: #666;
 94            margin-top: 5px;
 95        }
 96        output {
 97            display: inline-block;
 98            padding: 5px 10px;
 99            background: #e8f5e9;
100            border-radius: 4px;
101        }
102    </style>
103</head>
104<body>
105    <h1>HTML 폼 예제</h1>
106
107    <!-- 기본 폼 -->
108    <form action="/submit" method="POST">
109        <h2>νšŒμ›κ°€μž… 폼</h2>
110
111        <!-- κΈ°λ³Έ ν…μŠ€νŠΈ μž…λ ₯ -->
112        <fieldset>
113            <legend>κΈ°λ³Έ 정보</legend>
114
115            <div class="form-group">
116                <label for="username">μ‚¬μš©μžλͺ… *</label>
117                <input type="text" id="username" name="username"
118                       placeholder="영문, 숫자 μ‘°ν•©"
119                       required
120                       minlength="3"
121                       maxlength="20"
122                       pattern="[A-Za-z0-9]+">
123                <p class="hint">3-20자, 영문과 숫자만 μ‚¬μš© κ°€λŠ₯</p>
124            </div>
125
126            <div class="form-group">
127                <label for="email">이메일 *</label>
128                <input type="email" id="email" name="email"
129                       placeholder="example@domain.com"
130                       required>
131            </div>
132
133            <div class="form-group">
134                <label for="password">λΉ„λ°€λ²ˆν˜Έ *</label>
135                <input type="password" id="password" name="password"
136                       placeholder="8자 이상"
137                       required
138                       minlength="8">
139            </div>
140
141            <div class="form-group">
142                <label for="phone">μ „ν™”λ²ˆν˜Έ</label>
143                <input type="tel" id="phone" name="phone"
144                       placeholder="010-1234-5678"
145                       pattern="[0-9]{3}-[0-9]{4}-[0-9]{4}">
146            </div>
147        </fieldset>
148
149        <!-- μˆ«μžμ™€ λ‚ μ§œ -->
150        <fieldset>
151            <legend>μΆ”κ°€ 정보</legend>
152
153            <div class="form-group">
154                <label for="age">λ‚˜μ΄</label>
155                <input type="number" id="age" name="age"
156                       min="0" max="150" step="1"
157                       placeholder="25">
158            </div>
159
160            <div class="form-group">
161                <label for="birthdate">생년월일</label>
162                <input type="date" id="birthdate" name="birthdate"
163                       min="1900-01-01" max="2024-12-31">
164            </div>
165
166            <div class="form-group">
167                <label for="website">μ›Ήμ‚¬μ΄νŠΈ</label>
168                <input type="url" id="website" name="website"
169                       placeholder="https://example.com">
170            </div>
171        </fieldset>
172
173        <!-- 선택 μš”μ†Œ -->
174        <fieldset>
175            <legend>선택 사항</legend>
176
177            <div class="form-group">
178                <label for="country">κ΅­κ°€</label>
179                <select id="country" name="country">
180                    <option value="">μ„ νƒν•˜μ„Έμš”</option>
181                    <optgroup label="μ•„μ‹œμ•„">
182                        <option value="kr">λŒ€ν•œλ―Όκ΅­</option>
183                        <option value="jp">일본</option>
184                        <option value="cn">쀑ꡭ</option>
185                    </optgroup>
186                    <optgroup label="유럽">
187                        <option value="uk">영ꡭ</option>
188                        <option value="fr">ν”„λž‘μŠ€</option>
189                        <option value="de">독일</option>
190                    </optgroup>
191                    <optgroup label="뢁미">
192                        <option value="us">λ―Έκ΅­</option>
193                        <option value="ca">μΊλ‚˜λ‹€</option>
194                    </optgroup>
195                </select>
196            </div>
197
198            <div class="form-group">
199                <label>성별</label>
200                <div class="radio-group">
201                    <label>
202                        <input type="radio" name="gender" value="male"> 남성
203                    </label>
204                    <label>
205                        <input type="radio" name="gender" value="female"> μ—¬μ„±
206                    </label>
207                    <label>
208                        <input type="radio" name="gender" value="other"> 기타
209                    </label>
210                </div>
211            </div>
212
213            <div class="form-group">
214                <label>관심 λΆ„μ•Ό (볡수 선택 κ°€λŠ₯)</label>
215                <div class="checkbox-group">
216                    <label>
217                        <input type="checkbox" name="interests" value="tech"> 기술
218                    </label>
219                    <label>
220                        <input type="checkbox" name="interests" value="sports"> 슀포츠
221                    </label>
222                    <label>
223                        <input type="checkbox" name="interests" value="music"> μŒμ•…
224                    </label>
225                    <label>
226                        <input type="checkbox" name="interests" value="travel"> μ—¬ν–‰
227                    </label>
228                </div>
229            </div>
230        </fieldset>
231
232        <!-- ν…μŠ€νŠΈ μ˜μ—­ -->
233        <fieldset>
234            <legend>μžκΈ°μ†Œκ°œ</legend>
235
236            <div class="form-group">
237                <label for="bio">μžκΈ°μ†Œκ°œ</label>
238                <textarea id="bio" name="bio"
239                          rows="5"
240                          placeholder="κ°„λ‹¨ν•œ μžκΈ°μ†Œκ°œλ₯Ό μž‘μ„±ν•΄μ£Όμ„Έμš”..."
241                          maxlength="500"></textarea>
242                <p class="hint">μ΅œλŒ€ 500자</p>
243            </div>
244        </fieldset>
245
246        <!-- λ™μ˜ -->
247        <fieldset>
248            <legend>μ•½κ΄€ λ™μ˜</legend>
249
250            <div class="form-group">
251                <label>
252                    <input type="checkbox" name="terms" required>
253                    μ΄μš©μ•½κ΄€μ— λ™μ˜ν•©λ‹ˆλ‹€ *
254                </label>
255            </div>
256
257            <div class="form-group">
258                <label>
259                    <input type="checkbox" name="newsletter">
260                    λ‰΄μŠ€λ ˆν„° μˆ˜μ‹ μ— λ™μ˜ν•©λ‹ˆλ‹€ (선택)
261                </label>
262            </div>
263        </fieldset>
264
265        <!-- 제좜 λ²„νŠΌ -->
266        <div class="form-group">
267            <button type="submit">κ°€μž…ν•˜κΈ°</button>
268            <button type="reset" style="background-color: #888;">μ΄ˆκΈ°ν™”</button>
269        </div>
270    </form>
271
272    <!-- 기타 μž…λ ₯ νƒ€μž…λ“€ -->
273    <form>
274        <h2>기타 μž…λ ₯ νƒ€μž…</h2>
275
276        <fieldset>
277            <legend>특수 μž…λ ₯ νƒ€μž…</legend>
278
279            <div class="form-group">
280                <label for="color">색상 선택</label>
281                <input type="color" id="color" name="color" value="#4CAF50">
282            </div>
283
284            <div class="form-group">
285                <label for="range">λ²”μœ„ (range): <output id="rangeOutput">50</output></label>
286                <input type="range" id="range" name="range"
287                       min="0" max="100" value="50"
288                       oninput="rangeOutput.value = this.value">
289            </div>
290
291            <div class="form-group">
292                <label for="file">파일 μ—…λ‘œλ“œ</label>
293                <input type="file" id="file" name="file"
294                       accept=".jpg,.png,.pdf"
295                       multiple>
296                <p class="hint">JPG, PNG, PDF 파일만 κ°€λŠ₯</p>
297            </div>
298
299            <div class="form-group">
300                <label for="search">검색</label>
301                <input type="search" id="search" name="search"
302                       placeholder="검색어 μž…λ ₯...">
303            </div>
304
305            <div class="form-group">
306                <label for="browser">λΈŒλΌμš°μ € (datalist)</label>
307                <input type="text" id="browser" name="browser"
308                       list="browsers"
309                       placeholder="λΈŒλΌμš°μ € 선택 λ˜λŠ” μž…λ ₯">
310                <datalist id="browsers">
311                    <option value="Chrome">
312                    <option value="Firefox">
313                    <option value="Safari">
314                    <option value="Edge">
315                    <option value="Opera">
316                </datalist>
317            </div>
318
319            <div class="form-group">
320                <label for="time">μ‹œκ°„</label>
321                <input type="time" id="time" name="time">
322            </div>
323
324            <div class="form-group">
325                <label for="datetime">λ‚ μ§œμ™€ μ‹œκ°„</label>
326                <input type="datetime-local" id="datetime" name="datetime">
327            </div>
328
329            <div class="form-group">
330                <label for="month">μ›”</label>
331                <input type="month" id="month" name="month">
332            </div>
333
334            <div class="form-group">
335                <label for="week">μ£Ό</label>
336                <input type="week" id="week" name="week">
337            </div>
338
339            <div class="form-group">
340                <label for="hidden">μˆ¨κ²¨μ§„ ν•„λ“œ</label>
341                <input type="hidden" id="hidden" name="hidden" value="secret_value">
342                <p class="hint">이 ν•„λ“œλŠ” 보이지 μ•Šμ§€λ§Œ 값이 μ „μ†‘λ©λ‹ˆλ‹€</p>
343            </div>
344        </fieldset>
345    </form>
346
347    <footer style="margin-top: 40px; text-align: center; color: #666;">
348        <p>&copy; 2024 HTML 폼 예제</p>
349    </footer>
350</body>
351</html>