Is it possible to trigger a parent's class when on hover? I know it can be done with jquery but I want to do a pure css solution.
My code:
.navbar-form{
padding-left: 55px;
.input-group{
width: 200px;
.form-control{
border-right: none;
width: 350px;
&:hover & {
border-color: blue;
}
}
.input-group-addon{
background-color: white;
border-left: none;
}
}
}
FIDDLE: http://jsfiddle.net/fcKyc/
Looking to have that when I focus on the input
, .input-group-addon
would do something. input
and the icon are children of the input-group.
If I understand it right, here is my interpretation of the DOM interaction you're describing.
.parent
.child1
.child2
A hover on .child1 affects .child2
If yeah, then here:
.form-control {
... //your CSS for this
input {
//CSS for input
&:hover ~ .input-group-addon {
//CSS for .input-group-addon when input is hovered
}
}
}
OR, if .input-group-addon
is right after input
(adjacent sibling), then you could use the following:
.form-control {
... //your CSS for this
input {
//CSS for input
&:hover + .input-group-addon {
//CSS for .input-group-addon when input is hovered
}
}
}
As @Martin suggested.
I think you are looking for something like this:
<style type="text/css">
.navbar {
background: #000;
&:hover .change{
background: #ccc;
}
}
</style>
<div class="navbar">
<div class="change">
</div>
</div>
If you hover above the navbar then the .change div will change colors. This is what I usually use instead of using jQuery for certain effect triggers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With