简体   繁体   English

悬停时仅在CSS中选择第一个孩子

[英]select only first child in css when hovering

so here is my code: 所以这是我的代码:

ul.primary li:hover > a{
    transform:translate(7px,7px);
    -ms-transform:translate(7px,7px);
    -webkit-transform:translate(7px,7px);
} 

I want to select only the first "a" tag. 我只选择第一个“ a”标签。 Its for a menu and i dont want the links in the next "ul li a" to be translated 7 px down and right. 它的菜单,我不希望在下一个“ ul li a”中的链接向下和向右转换7像素。 For some reason when i try to change the css of the sub menu to: 由于某些原因,当我尝试将子菜单的CSS更改为:

ul.sub li a:hover {
    -moz-transition: none;
    -webkit-transition: none;
    -o-transition: color 0 ease-in;
    transition: none;
}

the transition is still there. 过渡仍然存在。

here is the html of the menu: 这是菜单的html:

<div class="wrap">
<span class="decor"></span>
<nav>
  <ul class="primary">
    <li>
      <a href="">WORKS</a>
      <ul class="sub">
        <li><a href="">CERAMICS</a></li>
        <li><a href="">EXHIBITIONS</a></li>
        <li><a href="">OTHERWORKS</a></li>
      </ul>
    </li>
    <li>
      <a href="">PHOTOS</a>
    </li>
    <li>
      <a href="">OTHER PROJECTS</a>
      <ul class="sub">
        <li><a href="">INSTAGRAM FEED</a></li>
        <li><a href="">PUBLICATIONS</a></li>
        <li><a href="">WARDOBE DESIGN</a></li>
      </ul>  
    </li>
  </ul>
</nav>
</div>

solved mmy problem: 解决了mmy问题:

ul.primary > li:hover > a

was the correct selector. 是正确的选择器。

You need ul.primary li:first-child:hover > a and 您需要ul.primary li:first-child:hover > a

ul.sub li:hover a {
    -moz-transition: none;
    -webkit-transition: none;
    -o-transition: color 0 ease-in;
    transition: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM