css + js ) input date 커스텀
2022. 11. 29. 17:01ㆍCSS
input[type='date']가 처음 로딩됐을 떄 placehorder의 내용으로 보여지게 하고 날짜를 선택하면 해당 날짜가 보여지게 함
HTML
<input className='has-value' type='date' data-placeholder='From' onchange={dataChange} />
CSS
input[type="date"] {position:relative; padding:14px; width:150px; height:30px; font-size:14px; color:#999; border:none; border-bottom:1px solid #e0e0e0;}
input[type="date"]::-webkit-calendar-picker-indicator {position:absolute; top:0; left:0; right:0; bottom:0; width:auto; height:auto; color:transparent; background:transparent;}
input[type="date"].has-value::before {content:attr(data-placeholder); width:100%;}
JS
const dataChange = (e) => {
const target = $(e.target);
if (target.val() == '') {
target.addClass('has-value');
} else {
target.removeClass('has-value');
}
input의 value값의 유무로 클래스를 첨삭하여 placehorder의 내용을 보였다 안보였다 함
결과
'CSS' 카테고리의 다른 글
chat animation only css(채팅 애니메이션) (0) | 2023.01.03 |
---|---|
input date 텍스트 컬러 변경 (0) | 2022.12.08 |
tab Menu - input type radio (input 라디오로 탭메뉴 만들기) (0) | 2022.10.18 |
css 한줄쓰기 (0) | 2022.10.14 |
플로팅 메뉴 (시간차 메뉴 나오기) (0) | 2022.08.30 |