๐Ÿ’›[๋ถ€์ŠคํŠธ์ฝ”์Šค_์›น UI ๊ฐœ๋ฐœ] 19. ํผ

๐Ÿ‘พยท2021๋…„ 2์›” 1์ผ
0

HTML & CSS

๋ชฉ๋ก ๋ณด๊ธฐ
19/20
post-custom-banner

ํผ ์†Œ๊ฐœ

์›น ์„œ๋ฒ„์˜ ์ •๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ํ˜•์‹์˜ UI๋ฅผ <form>ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด์„œ ์ž‘์„ฑํ–ˆ๋‹ค๊ณ  ํ•ด์„œ Form UI๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ํƒœ๊ทธ๋“ค ์กด์žฌ.
์ด๋Ÿฐ ํƒœ๊ทธ๋“ค์„ ํผ๊ณผ ๊ด€๋ จ๋œ ์š”์†Œ๋“ค์ด๋ผ๊ณ  ํ•ด์„œ ํผ ์š”์†Œ/ํผ ํƒœ๊ทธ๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

์—ฌ๋Ÿฌ ๋ธŒ๋ผ์šฐ์ €์—์„œ๋Š” ๋™์ผํ•œ ํผ ์š”์†Œ๋„ ๋‹ค์–‘ํ•œ ๋””์ž์ธ์œผ๋กœ ํ‘œํ˜„๋จ
๋”ฐ๋ผ์„œ ํ†ต์ผ๋œ ๋ชจ์Šต์œผ๋กœ ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๋Š” ํผ ์š”์†Œ๋“ค์„ css๋ฅผ ์ด์šฉํ•˜์—ฌ ์ปค์Šคํ…€ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.


ํผ ์ปค์Šคํ…€ - ํ…์ŠคํŠธ ๋ฐ•์Šค

์‚ฌ์šฉ ์˜ˆ์‹œ

  • ๋„ค์ด๋ฒ„ ๋ฉ”์ธํŽ˜์ด์ง€ ๊ฒ€์ƒ‰์ฐฝ
  • ๋„ค์ด๋ฒ„ ๋กœ๊ทธ์ธ ํ™”๋ฉด

ํ…์ŠคํŠธ ํ•„๋“œ์˜ ์ปค์Šคํ…€์€ CSS ์†์„ฑ์„ ์ด์šฉํ•ด์„œ ๋‹จ์ˆœํ•œ ๋ฐ•์Šค ๋ชจ๋ธ์ฒ˜๋Ÿผ ์‰ฝ๊ฒŒ ์ˆ˜์ •๊ฐ€๋Šฅํ•˜๋‹ค.

placeholder๋ฅผ ์–ด๋–ป๊ฒŒ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์‚ดํŽด๋ณด์ž

์ฃผ์š” ํƒœ๊ทธ ๋ฐ ์†์„ฑ

  • HTML
    input[type=text], input[type=password], textarea
  • CSS
    ::placeholder
    placeholder๋กœ ๋“ค์–ด๊ฐ€๋Š” ๊ธฐ๋ณธ ๋ฌธ๊ตฌ๋Š” ::placeholder๋ฅผ ํ†ตํ•ด ํฐํŠธ ์Šคํƒ€์ผ์„ ํŽธ์ง‘ํ•  ์ˆ˜ ์žˆ๋‹ค.
    ํ•˜์ง€๋งŒ ์ด pseudo-class๋Š” ๋น„ํ‘œ์ค€์ฝ”๋“œ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ธŒ๋ผ์šฐ์ €์— ๋”ฐ๋ผ์„œ ๊ณตํ†ต๋œ ๋ฐฉ์‹์„ ์ œ๊ณตํ•˜์งˆ ์•Š๋Š”๋‹ค.
    ๊ทธ๋ž˜์„œ ๊ฐ ๋ธŒ๋ผ์šฐ์ €์— ๋”ฐ๋ผ์„œ ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ๋Š” ์„ ํƒ์ž๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋‹ค.
    w3cschool์ฐธ๊ณ !
<p><input type="text" placeholder="์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."></p>

<p><input type="password" placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."></p>

<p><textarea name="" id="" cols="30" rows="10" placeholder="๋ฌธ๊ตฌ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."></textarea></p>
input[type="text"],
input[type="password"] {
    width: 198px;
    height: 38px;
    line-height: 38px;
    border: 1px solid #ddd;
    font-size: 15px;
    text-indent: 10px;
    color: #000;
}

textarea {
    width: 280px;
    height: 130px;
    padding: 9px;
    border: 1px solid #ddd;
    font-size: 15px;
    resize: none;
    color: #000;
}

::-webkit-input-placeholder { /* Chrome/Opera/Safari */
    color: red;
}
::-moz-placeholder { /* Firefox 19+ */
    color: red;
}
:-ms-input-placeholder { /* IE 10+ */
    color: red;
}
:-moz-placeholder { /* Firefox 18- */
    color: red;
}

textarea::-webkit-input-placeholder { /* Chrome/Opera/Safari */
    color: blue;
}
textarea::-moz-placeholder { /* Firefox 19+ */
    color: blue;
}
textarea:-ms-input-placeholder { /* IE 10+ */
    color: blue;
}
textarea:-moz-placeholder { /* Firefox 18- */
    color: blue;
}

๋งŒ์•ฝ ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ธ์‹ํ•  ์ˆ˜ ์—†๋Š” ์„ ํƒ์ž๊ฐ€ ๋ผ์–ด์žˆ๋‹ค๋ฉด ๊ทธ ์ฝ”๋“œ ์ž์ฒด๋ฅผ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๋ฌด์‹œํ•˜๊ฒŒ ๋จ.
๊ทธ๋Ÿฌ๋ฏ€๋กœ prefix๊ฐ€ ๋ถ™๋Š” placeholder ๋‚ด์šฉ๋“ค์€ ๋”ฐ๋กœ๋”ฐ๋กœ ์จ์ฃผ๋Š”๊ฒƒ์ด ์˜ฌ๋ฐ”๋ฅธ ๋ฐฉ๋ฒ•์ด๋‹ค.

์ •๋ฆฌ

  • ํ…์ŠคํŠธ ํ•„๋“œ์˜ ์ปค์Šคํ…€์€ ์ผ๋ฐ˜์ ์ธ ๋ฐ•์Šค ํ˜•ํƒœ๋ฅผ ์ปค์Šคํ…€ํ•˜๋Š”๊ฒƒ๊ณผ ๋™์ผ
  • placeholder๋ฅผ ์ปค์Šคํ…€ํ• ๋•Œ์—๋Š” ๋น„ํ‘œ์ค€ ์ฝ”๋“œ์ž„์„ ์ธ์ง€ํ•˜๊ณ  ๊ฐ ๋ธŒ๋ผ์šฐ์ €์— ๋Œ€์‘ํ•˜๋Š” ๋ฐฉ์‹์„ ์ž˜ ํ™•์ธํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์„ ๊ธฐ์–ตํ•˜๊ธฐ.

ํผ ์ปค์Šคํ…€ - ์ฒดํฌ๋ฐ•์Šค, ๋ผ๋””์˜ค

์ฃผ์š” ํƒœ๊ทธ ๋ฐ ์†์„ฑ

  • HTML
    input[type:checkbox], input[type:radio], label
    label ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด์„œ ํ˜•ํƒœ ๋งŒ๋“ฆ
  • CSS
    UI element states pseudo-classes(:checked) Pseudo-element(:before)
    :checked๋ฅผ ์ด์šฉํ•ด์„œ ํ™œ์„ฑํ™”๋˜์—ˆ๋Š”์ง€ ์ฒดํฌํ•˜๋Š” ๋ฐฉ์‹์„ ์ด์šฉํ•ด์„œ ์ƒํƒœ๊ฐ’ ๋ฐ˜์˜
    :before๋ฅผ ์ด์šฉํ•ด ์ปค์Šคํ…€ ๋œ ์˜ˆ์ œ๋“ค ๊ตฌํ˜„
  1. CSS๋งŒ์„ ์ด์šฉํ•œ checkbox ์ปค์Šคํ…€
<div>
    <input type="checkbox" id="check_button1" name="">
    <label for="check_button1">์„ ํƒ1</label>
</div>

<div>
    <input type="checkbox" id="check_button2" name="">
    <label for="check_button2">์„ ํƒ2</label>
</div>
input[type='checkbox'] { /* input ๊ฐ์ถ”๊ธฐ */
    position: absolute;
    overflow:hidden;
    width: 1px;
    height: 1px;
    margin: -1px;
    opacity: 0;
}
input[type='checkbox'] + label { /*ํšŒ์ƒ‰ ๋ฐฐ๊ฒฝ*/
    display: inline-block;
    overflow: hidden; /*๊ธ€์”จ ์ดˆ๊ธฐํ™”*/
    position: relative; 
    width: 36px;
    height: 21px;
    border-radius: 10px;
    background: #666;
    vertical-align: top;
    color: transparent; /*๊ธ€์”จ ์ดˆ๊ธฐํ™”*/
}
input[type='checkbox'] + label:after { /*๋™๊ทธ๋ผ๋ฏธ ๋ชจ์–‘*/
    content: '';
    position: absolute;
    top: 1px;
    left: 1px;
    width: 19px;
    height: 19px;
    background: #fff;
    border-radius: 50%;
}

input[type='checkbox']:checked + label { /*input์ด checked ๋˜์—ˆ์„๋•Œ*/
    background-color: #62a7ee;
}
input[type='checkbox']:checked + label:after { /*๋™๊ทธ๋ผ๋ฏธ ์ด๋™*/
    left: auto;
    right: 1px;
}
  1. ์ด๋ฏธ์ง€๋ฅผ ์ด์šฉํ•œ checkbox ์ปค์Šคํ…€
<div>
    <input type="checkbox" id="check_button1" name="">
    <label for="check_button1">์„ ํƒ1</label>
</div>

<div>
    <input type="checkbox" id="check_button2" name="">
    <label for="check_button2">์„ ํƒ2</label>
</div>
input[type='checkbox'] { /* input ๊ฐ์ถ”๊ธฐ */
    position: absolute;
    overflow:hidden;
    width: 1px;
    height: 1px;
    margin: -1px;
    opacity: 0;
}
input[type='checkbox'] + label {
    display: inline-block;
    font-size: 16px;
}
input[type='checkbox'] + label:before {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin:-4px 5px 0 0;
    background: url(checkbox.png) no-repeat 0 0;
    background-size: 20px;
    vertical-align: top;
    content:'';
}
input[type='checkbox']:checked + label:before { /*์„ ํƒํ–ˆ์„๋–„ ์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ*/
    background-image: url(checkbox_on.png); 
}
  1. ์ด๋ฏธ์ง€๋ฅผ ์ด์šฉํ•œ radio ๋ฒ„ํŠผ ์ปค์Šคํ…€
<div>
    <input type="radio" id="radio_button1" name="radio_form">
    <label for="radio_button1">๋ผ๋””์˜ค1</label>
</div>

<div>
    <input type="radio" id="radio_button2" name="radio_form">
    <label for="radio_button2">๋ผ๋””์˜ค2</label>
</div>

<div>
    <input type="radio" id="radio_button3" name="radio_form">
    <label for="radio_button3">๋ผ๋””์˜ค3</label>
</div>
input[type='radio'] { /* input ๊ฐ์ถ”๊ธฐ */
    position: absolute;
    overflow:hidden;
    width: 1px;
    height: 1px;
    margin: -1px;
    opacity: 0;
}
input[type='radio'] + label {
    display: inline-block;
    font-size: 16px;
}
input[type='radio'] + label:before {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin:-4px 5px 0 0;
    background: url(radio.png) no-repeat 0 0;
    background-size: 20px;
    vertical-align: top;
    content:'';
}
input[type='radio']:checked + label:before {
    background-image: url(radio_on.png); 
}

์ •๋ฆฌ

  • input๊ณผ label์˜ ์—ฐ๊ฒฐ์„ ํ†ตํ•œ UI ์ปจํŠธ๋กค
    (for, id ์—ฐ๊ฒฐํ•ด์•ผ ์—ฐ๊ฒฐ๋จ)
  • UI element states pseudo-classes(:checked)๋ฅผ ์ด์šฉํ•œ ์ƒํƒœ ๊ตฌ๋ถ„

ํผ ์ปค์Šคํ…€ - ํŒŒ์ผ์ฐพ๊ธฐ

์ฃผ์š” ํƒœ๊ทธ ๋ฐ ์†์„ฑ

  • HTML
    input[type=file]
  • CSS
    opacity
    ํŒŒ์ผ์ฐพ๊ธฐ type์˜ input์„ opacity๊ฐ’์„ ์ด์šฉํ•ด์„œ ์‚ฌ์šฉ์ž ๋ˆˆ์—๋Š” ๋ณด์ด์ง€ ์•Š๊ฒŒ ๋ฐ”๊พธ๊ณ  ์šฐ๋ฆฌ๊ฐ€ ์›ํ•˜๋Š” ๋ชจ์–‘์„ ๊ทธ ์œ„์— ๋ฎ์–ด์”Œ์šฐ๋Š” ๋ฐฉ์‹์œผ๋กœ ์ปค์Šคํ…€

1. CSS๋งŒ์„ ์ด์šฉํ•œ ํŒŒ์ผ ์„ ํƒ ๋ฒ„ํŠผ ์ปค์Šคํ…€

<div class="file_form">
  <input type="file">
  <span class="text">filename..</span>
</div>
.file_form {
    position: relative; /* position ๊ธฐ์ค€ */
    display: inline-block;
    width: 198px;
    height: 38px;
    line-height: 38px;
    border: 1px solid cornflowerblue;
    font-size: 12px;
}
.file_form .text { /*๋ง์ค„์ž„*/
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    padding: 0 50px 0 10px;
    white-space: nowrap;
}
.file_form .text:after { /* ๋ฒ„ํŠผํ˜•ํƒœ ๊ตฌํ˜„ */
    position: absolute;
    top:0;right:0;
    width: 50px;
    background-color: cornflowerblue;
    text-align: center;
    color: #fff;
    content:'ํŒŒ์ผ์ฐพ๊ธฐ';
}
.file_form input[type='file'] { /*input์„ ์ปค์Šคํ…€ํ•œ ์‚ฌ๊ฐํ˜• ์œ„๋กœ ๋„์›Œ์ฃผ๊ธฐ*/
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    z-index: 10; /*'ํŒŒ์ผ์ฐพ๊ธฐ'๋ณด๋‹ค ์˜ฌ๋ ค์คŒ*/
    width: 100%;
    opacity: 0;
}

2. ์ด๋ฏธ์ง€ ๋ฒ„ํŠผ์„ ์ด์šฉํ•œ ํ”„๋กœํ•„ ๋“ฑ๋ก ๋งŒ๋“ค๊ธฐ

<div class="file_form_img">
  <span class="img"><img src="default.png" alt="ํ”„๋กœํ•„ ์ด๋ฏธ์ง€"></span>
  <label class="file"><input type="file"></label>
</div>
.file_form_img {
    width: 100px; /* ํ”„๋กœํ•„ ๋“ฑ๋ก ์‚ฌ์ด์ฆˆ ์ง€์ • */
}
.file_form_img .img {
    overflow: hidden;
    position: relative;
    display: block;
    width: 100px;
    height: 100px;
    border:1px solid rgba(0, 0, 0, 0.2);
    border-radius: 50%; /* ์› ๋ชจ์–‘*/
}
.file_form_img .img img {
    width: 100%;
    height: auto;
    border-radius: 50%;
}
.file_form_img .file {
    position: relative;
    display: block;
    margin: 10px auto 0; /* ๋ฒ„ํŠผ ๊ฐ€์šด๋ฐ ์ •๋ ฌ */
    background:url(btn_file.jpg) no-repeat;
    width: 82px;
    height: 24px;
}
.file_form_img .file input[type=file] {
    position: absolute;
    z-index: 10;
    top: 0; right: 0; bottom: 0; left: 0;
    width: 100%;
    opacity: 0;
}

์ •๋ฆฌ

  • opacity๋ฅผ ์ด์šฉํ•ด์„œ input:file์˜ ๊ธฐ๋Šฅ๋งŒ ๋‚จ๊ธฐ๊ณ  ๊ฐ€๋ฆฌ๊ธฐ
    file type์€ ๋ฒ„ํŠผ์˜ ๋ชจ์–‘๊ณผ ๊ทธ ํŒŒ์ผ๋ช…์ด ๋…ธ์ถœ๋˜๋Š” ์˜์—ญ์— ์„ธ๋ถ€์ ์œผ๋กœ ์ปค์Šคํ…€์„ ํ•  ์ˆ˜ ์—†๋‹ค.

  • ์„ ํƒ๋œ ๊ฐ’์€ ๋‹ค๋ฅธ ๊ณต๊ฐ„์œผ๋กœ ๋ณด์—ฌ์ฃผ๋„๋ก js๋ฅผ ์ด์šฉํ•œ ๊ฐœ๋ฐœ๋Œ€์‘
    ์„ ํƒ๋œ ํŒŒ์ผ๋ช…์ด๋‚˜ ํŒŒ์ผ ์ •๋ณด๋“ค์„ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ํ˜•์‹์œผ๋กœ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐœ๋ฐœ๋Œ€์‘์ด ๊ผญ ํ•„์š”ํ•˜๋‹ค.


ํผ ์ปค์Šคํ…€ - SELECT ๋ฉ”๋‰ด

select ๋ฉ”๋‰ด๋ฅผ ํด๋ฆญํ–ˆ์„๋•Œ ๋‚˜์˜ค๋Š” ์•„๋ž˜์˜ ์„ ํƒํ˜• ๋‚ด์šฉ๋“ค์€ CSS๋งŒ์œผ๋กœ ์ปค์Šคํ…€์„ ํ•  ์ˆ˜๊ฐ€ ์—†๋‹ค.
๊ทธ๋ž˜์„œ ํŽผ์ณ์ง„ ๋“œ๋กญ๋ฐ•์Šค์˜ ๋ชจ์–‘์ด ๊ธฐ์กด ๋ชจ์Šต๊ณผ ๋‹ค๋ฅธ ๊ฒฝ์šฐ๋Š” ๋ชจ๋‘ ๋ ˆ์ด์–ด ํ˜•ํƒœ๋กœ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ํ”„๋ก ํŠธ ์—”๋“œ ๊ฐœ๋ฐœ ๋Œ€์‘์œผ๋กœ select์˜ ๋™์ž‘์„ ๊ตฌํ˜„ํ•œ ๊ฒƒ์ด๋‹ค.

์ฃผ์š” ํƒœ๊ทธ ๋ฐ ์†์„ฑ

  • HTML
    select
  • CSS
    appearance
    ๊ธฐ๋ณธ ๋ฒ„ํŠผ ๋ชจ์–‘ ๋ฐฉ์‹์„ appearance๋ฅผ ํ†ตํ•ด ์—†์• ๊ณ  ๊ทธ ์œ„์น˜์— ์›ํ•˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋„ฃ์–ด์„œ ์ปค์Šคํ…€ ํ•˜๋Š” ๋ฐฉ์‹
<div class="select_form">
    <select name="" id="">
        <option value="">์„ ํƒ1</option>
        <option value="">์„ ํƒ2</option>
        <option value="">์„ ํƒ3</option>
    </select>
</div>
.select_form {
    display: block;
    position: relative;
    width: 198px;
    height: 38px;
    line-height: 40px;
    border: 1px solid #ddd;
    text-align: left;
}
.select_form select {
    width: 100%;
    height: 100%;
    padding: 0 30px 0 10px;
    background-color: transparent;
    border: 0 none;
    font-size: 16px;
    appearance: none; /*๊ธฐ๋ณธ ๋ฒ„ํŠผ ๋ชจ์–‘ ์—†์• ๊ธฐ*/
    /*appearance ์†์„ฑ์ด webkit ์—”์ง„๊ณผ Mozilla์‚ฌ์—์„œ ์‚ฌ์šฉํ•˜๋Š” Gecko ์—”์ง„์—์„œ๋งŒ ์ œ๊ณตํ•˜๊ธฐ ๋•Œ๋ฌธ์— prefix๋ฅผ ๋ถ™์—ฌ์ค€ ๋‹ค์Œ ์—†์• ์ค˜์•ผ๋งŒ ํ•œ๋‹ค. appearance๋„ ๋น„ํ‘œ์ค€ ์ฝ”๋“œ*/
    -moz-appearance: none;
    -webkit-appearance: none;
}
.select_form:after { /*๋ฒ„ํŠผ ํ˜•ํƒœ*/
    position: absolute;
    top: 16px;
    right: 10px;
    background:url(select.png) no-repeat 0 0;
    width: 13px;
    height: 7px;
    display: block;
    content:'';
}

์ •๋ฆฌ

appearance ์†์„ฑ์„ ์ด์šฉํ•˜์—ฌ ๊ธฐ๋ณธ ๋ฒ„ํŠผ ๊ธฐ๋Šฅ์„ ๊ฐ์ถ”๊ธฐ

appearance ์†์„ฑ ๋˜ํ•œ placeholder ์ปค์Šคํ…€ํ• ๋•Œ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋น„ํ‘œ์ค€ ์ฝ”๋“œ๋กœ, webkit๊ณผ Gecko ์—”์ง„ ๊ธฐ๋ฐ˜์˜ ๋ธŒ๋ผ์šฐ์ €์—์„œ๋งŒ ๋™์ž‘ํ•œ๋‹ค.
์ฆ‰ MS์‚ฌ์—์„œ ์ œ๊ณตํ•˜๋Š” ์ธํ„ฐ๋„ท ์ต์Šคํ”Œ๋กœ๋Ÿฌ์—์„œ๋Š” ๋Œ€์‘์ฝ”๋“œ๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์— IE์—์„œ ์ปค์Šคํ…€ ๋œ ์…€๋ ‰ํŠธ ๋ฐ•์Šค๋ฅผ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ ˆ์ด์–ด ํ˜•ํƒœ์˜ ๋“œ๋กญ๋‹ค์šด๋ฐฉ์‹์„ ๋งŒ๋“ค์–ด์„œ ๊ฐœ๋ฐœ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๊ธฐ์–ตํ•˜์ž

post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€