사용자가 아무 것도 입력하지 않은 경우 초점이 흐려지면 흐리게 표시되는 기본값이있는 양식이 있습니다. 사용자가 무언가를 입력하거나 텍스트 상자가 사용자 입력 텍스트로 흐려지면 텍스트의 색상이 검은 색으로 어두워집니다.여기를 중요하게 사용해야합니까?
문제 : 내가 글꼴이 어두운 검은 색으로 변경 얻을 수 없을 때 사용자 유형에 뭔가 때 또는 텍스트 상자가 !important
를 사용하지 않고 사용자 입력 텍스트 흐림로 들어갑니다. 뭔가 잘못된 것이 나에게 !important
을 사용하도록 요구 했습니까? 아니면 더 좋은 방법이 있습니까?
HTML 코드
<div id="splash_register_form">
<input type="text" name="register_first_name" class="splash_register_short_input" title="First Name" />
<input type="text" name="register_last_name" class="splash_register_short_input" title="Last Name" />
<input type="text" name="register_email" class="splash_register_long_input" title="Email" />
<input type="text" name="register_password" class="splash_register_long_input" title="Password" />
</div>
jQuery를 코드
$(".splash_register_short_input, .splash_register_long_input").each(function() {
$(this).val($(this).attr('title'));
});
$(".splash_register_short_input, .splash_register_long_input").focus(function() {
if($(this).val() == $(this).attr('title')) {
$(this).val('');
}
});
$(".splash_register_short_input, .splash_register_long_input").blur(function() {
if($(this).val() == '') { // If there is no user input
$(this).val($(this).attr('title'));
$(this).removeClass('splash_register_have_userinput');
} else { // If there is user input
$(this).addClass('splash_register_have_userinput');
}
});
CSS
.splash_register_long_input {
height: 22px;
width: 300px;
padding: 3px 0px 3px 8px;
margin: 0px 1px 2px 0px;
float: left;
font-family: Arial, Sans-Serif;
font-weight: bold;
border: 1px solid #5cb5ee;
}
.splash_register_long_input:focus {
border: 2px solid #5cb5ee;
width: 298px;
height: 20px;
}
.splash_register_short_input{
height: 22px;
width: 144px;
padding: 3px 0px 3px 8px;
margin: 0px 1px 2px 0px;
float: left;
font-family: Arial, Sans-Serif;
font-weight: bold;
border: 1px solid #5cb5ee;
}
.splash_register_short_input:focus {
border: 2px solid #5cb5ee;
width: 142px;
height: 20px;/
}
.splash_register_short_input:focus, .splash_register_long_input:focus {
color: #333 !important;
-webkit-box-shadow:0 0 10px #5cb5ee;
-moz-box-shadow:0 0 10px #5cb5ee;
box-shadow:0 0 10px #5cb5ee;
outline: none; /* prevent chrome from adding border */
}
#splash_register_form input {
color: #AAA;
}
.splash_register_have_userinput {
color: #333 !important;
}
위의 예에서 클래스에 추가로 ID를 사용하면 규칙의 특수성이 높아져 덜 구체적인 '# splash_register_form' 전용 규칙을 무시할 수 있습니다. – N13
이 말이 맞습니다! – Nyxynyx
@Nyxynyx 도움을 기쁘게 :) –