CSS, hover one element, affect another

柔情痞子 提交于 2019-12-10 16:36:54

问题


When i hover a "li a" can i then affect another element in plain CSS?

becuase I'm trying to make a box slide in, as a background element, when hovering my link. Exactly like this sites navigation, just instead of when activated, it works with hover

http://www.zindhai.com

this is my code

nav ul li a:hover{
    color: #C3E1FF;
    font-weight: 700;
}

nav ul li span:hover{
    -webkit-transform:translate(0px, 0px);
    -webkit-transition:all 0.5s ease-out;
    transition:all 0.5s ease-out;
}

nav ul li span{
    height:43px;
    width:300px;
    position: absolute;
    background-color:#47525D;
    -webkit-transform:translate(300px, 0px);
    -webkit-transition:all 0.5s ease-out;
    transition:all 0.5s ease-out;
    background-position:initial initial;
    background-repeat:initial initial;
}

thanks in advance!

This is how it looks now;

http://jsfiddle.net/mbyc3tf9/


回答1:


If you need move the span, when you put your mouse over the a, add this

nav ul li a:hover > span {}



回答2:


Yeah it's pretty easy to do. Assuming your HTML is called something like .myElement for example. All you need to do is...

nav ul li a:hover .myElement { ... }

Then enter your CSS inside the { }.



来源:https://stackoverflow.com/questions/26289664/css-hover-one-element-affect-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!