CSS专注于子元素更改父元素 [英] CSS focus on child element change a parent element
问题描述
我想设置一个样式,该样式在form字段内具有标签和输入,并且当我在输入内写一些东西(可能带有焦点)时,我希望边框以蓝色点亮.现在我有这样的东西:
I want to style a form that has the label and input inside the form field and when I'll write something inside the input (probably with focus), I want the borders to light up with some blue. Now I have something like this:
HTML
<div class="login-form-field">
<label for="email" class="login-form-label">Email:</label>
<input class="login-form-input" autofocus="autofocus" type="email" value="" name="user[email]" id="user_email">
</div>
CSS
.login-form-input{
margin-left: 20px;
width: 90%;
outline: none;
border: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: 0 0 0px 1000px white inset;
}
.login-form-label {
font-size: 13px;
font-weight: 300;
padding-left: 20px;
}
.login-form-field{
width: 100%;
border-radius: 0px;
height: 6rem;
border: 0.5px solid grey;
box-shadow: 0px 0px 0px;
}
我已经试图选择父母进行一些更改,以及在Google上找到的其他内容.我得到的最接近的颜色是:当鼠标悬停在:hover上时,用蓝色突出显示,但是我需要保持颜色不变,就像选择输入时一样.
I already tried to select the parent to made some change and other stuff I found on google. The closest I got was to highlight with blue when the mouser was over it with :hover, but i need the color to stay as I'm with the input selected.
.login-form-field:hover {
border-color: blue !important;
}
这是 JSFiddle ,如果有人可以帮助我,我将不胜感激!
Here is the JSFiddle, if anyone could help I would be grateful!
推荐答案
与jquery进行反应:
React with jquery:
$( document ).ready(function() {
console.log( "ready!" );
$('.login-form-input').focus(function() {
$(this).parent().css( "border", "#99f 2px solid" );
});
$('.login-form-input').focusout(function() {
$(this).parent().css( "border", "" );
});
});
这篇关于CSS专注于子元素更改父元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!