๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
HTML๐Ÿ”จ/html&css ํผ์š”์†Œ

css radio ๋งŒ๋“ค๊ธฐ

by hyojinny 2022. 10. 10.

ํผ์š”์†Œ์˜ input ํƒ€์ž… radio ๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์ž 

checkbox๋Š” ์ค‘๋ณต ์„ ํƒ์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ radio ๋ฒ„ํŠผ์€ ๋‹จ์ผ ์„ ํƒ๋งŒ ๊ฐ€๋Šฅ!

 


 

1. html ์ž‘์„ฑ 

๊ฐ€๋กœ๋กœ ๋ฐฐ์น˜ํ• ์ˆ˜ ์žˆ๋„๋ก div wrap์„ ์‚ฌ์šฉํ•ด ๊ทธ๋ฃน์œผ๋กœ ๊ฐ์•„์ค€๋‹ค.

์‹œ๊ฐ์žฅ์• ์ธ์šฉ ์›น ์ ‘๊ทผ์„ฑ์„ ์œ„ํ•ด class๋ช… bilnd

๊ธ€์ž๋ฅผ ์„ ํƒํ•ด๋„ ์ฒดํฌ ๋ ์ˆ˜ ์žˆ๋„๋ก label for ์ง€์ • 

๊ฐ™์€ ๊ทธ๋ฃน์˜ name์€ ๊ฐ™๊ฒŒ id๋ช…์€ ์ˆœ์„œ๋Œ€๋กœ label๊ณผ ๊ผญ ์ผ์น˜ํ•˜๊ฒŒ ๋งŒ๋“ ๋‹ค.

 

                <div class="agree_bottom">
                  <div class="radio_wrap">
                    <input class="bilnd" id="fruit1" type="radio" name="fruit" checked>
                    <label for="fruit1">๋”ธ๊ธฐ</label>
                  </div>
                  <div class="radio_wrap">
                    <input class="bilnd" id="fruit2" type="radio" name="fruit">
                    <label class="bilnd" for="fruit2">์‚ฌ๊ณผ</label>
                  </div>
                  <div class="radio_wrap">
                    <input id="fruit3" type="radio" name="fruit">
                    <label for="fruit3">๋ฉ”๋ก </label>
                  </div>
                </div>

 

 


2. ๊ณตํ†ตํด๋ž˜์Šค ๊ธฐ์กด ๋””์ž์ธ ์ดˆ๊ธฐํ™” ํ•ด์ฃผ๊ธฐ  

 

/* ํผ์š”์†Œ์˜ ๋†’์ด๊ฐ€ ๋‹ค๋ฅผ๋•Œ ์š”์†Œ๋ผ๋ฆฌ ์„ธ๋กœ์ •๋ ฌ์‹œํ‚ด, ios ๋‘ฅ๊ทผ๋ชจ์„œ๋ฆฌ, ๊ธฐ๋ณธ์Šคํƒ€์ผ ์ œ๊ฑฐ */
/* border-radius:0 -> iOS์—์„œ ํ…Œ๋‘๋ฆฌ๊ฐ€ ๋‘ฅ๊ธ€๊ฒŒ ๋‚˜์˜ค๋ฏ€๋กœ ๋นผ์คŒ */
/* -webkit-appearance: none -> iOS์—์„œ ํผ์š”์†Œ์— ๋‚ด๋ถ€๊ทธ๋ฆผ์ž๊ฐ€ ๋‚˜์˜ค๋ฏ€๋กœ ๋นผ์คŒ */
input, select, textarea, button {
 vertical-align: middle; 
 margin: 0; padding: 0; 
 border-radius: 0; 
 -webkit-appearance: none; 
 -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1); 
 }

 

๊ทธ๋Ÿผ ๊ธฐ๋ณธ์œผ๋กœ ๋“ค์–ด๊ฐ€์žˆ๋Š”

๋ผ๋””์˜ค ๋ฐ•์Šค ๋””์ž์ธ์ด ์ดˆ๊ธฐํ™” ๋œ๋‹ค.

 

 

 

 

์ฒดํฌ๋ฐ•์Šค ๋งŒ๋“ค๊ธฐ ์ฐธ๊ณ 

https://hyojinny.tistory.com/82

 


3. ๊ณตํ†ตํด๋ž˜์Šค๋กœ ๊พธ๋ฉฐ์ฃผ๊ธฐ

 

3-1 ๊ฐ€๋กœ๋กœ ์ขŒ์šฐ์ •๋ ฌ

 .radio_wrap { display: inline-block;}

์ธ๋ผ์ธ ๋ธ”๋ก์‹œ์— ์ขŒ์šฐ ์ƒํ•˜ ๋‹ค ์ปจํŠธ๋กค ๊ฐ€๋Šฅ 

 


 

3-2 ๊ธ€์”จ์— ๋งˆ์šฐ์Šค ๊ฐ€์ ธ๊ฐ€๋ฉด ํฌ์ธํŠธ ๋ณ€๊ฒฝ

 

input[type=radio] + label {
    cursor: pointer;
    position: relative;
}

 

3-3 ๊ธ€์”จ์— ๋งˆ์šฐ์Šค ๊ฐ€์ ธ๊ฐ€๋ฉด ํฌ์ธํŠธ ๋ณ€๊ฒฝ

๊ธฐ์กด ๋ธŒ๋ผ์šฐ์ € ๋””์ž์ธ ๋Œ€์‹  

๋™๊ทธ๋ผ๋ฏธ ๋””์ž์ธ์„ ๋ณ€๊ฒฝํ•ด์ค€๋‹ค.

 

input[type=radio] + label:before {
    content: '';
    display: inline-block;
    height: 18px;
    width: 18px;
    border-radius: 50%;
    border: 2px solid #ddd;
    vertical-align: -4px;
    margin-right: 6px;
}
 

 

3-4 ์ฒดํฌํ–ˆ์„๋–„ ๋ชจ์–‘ ํ‘œ์‹œ๋ชจ์–‘๋ณ€๊ฒฝ

์ฒดํฌํ•˜๋ฉด ํฌ์ธํŠธ๋กœ ๋™๊ทธ๋ผ๋ฏธ๊ฐ€ ์ฒดํฌ๋˜๊ฒŒ ํ•œ๋‹ค.

 

 

input[type=radio]:checked + label:after{
    position: absolute;
    content: '';
    left: 5px;
    top: 50%;
    width: 8px;
    height: 8px;
    margin-top: -2px;
    border-radius: 50%;
    background: #009223;
}

๋Œ“๊ธ€