简体   繁体   English

悬停在li元素上时的过渡效果

[英]transition effect when you hover on the li element

I'm trying to add an ease-in transition when one hovers on the <li> element, so that the <ul> element ca ease-in. 当一个鼠标悬停在<li>元素上时,我试图添加一个缓入过渡,以便<ul>元素可以缓入。 Here's my html: 这是我的html:

 <header>
        <nav>
            <div id="logo" style="color: white" class="try">Techflow</div>
            <label for="drop" class="toggle">Menu</label>
            <input type="checkbox" id="drop" />
            <div class="pull-left">
                <ul class="menu">
                    <li>
                        <label for="drop-1" class="toggle">Tech News</label>
                        <a href='@Url.Action("Index","Home")'>Tech News</a>
                        <input type="checkbox" id="drop-1" />
                        <ul>
                            <li><a href="@Url.Action("TechEvolution", "Tech")">Tech Evolution</a></li>
                            <li><a href="@Url.Action("Tablets", "Tech")">Tablets</a></li>
                            <li><a href="@Url.Action("Smartphones", "Tech")">Phones</a></li>
                            <li><a href="@Url.Action("InternetTV", "Tech")">Internet TV</a></li>
                            <li><a href="@Url.Action("UncappedInternet", "Tech")">Uncapped Internet</a></li>
                            <li><a href="@Url.Action("ReviewAndAdvice", "Tech")">Reviews and Advise...</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </nav>
    </header>

and here's my css: 这是我的CSS:

header nav div ul li ul:hover{
    transition: ease-in 3s ease;
}

You have a selector with more 4 level of deep, is a good practice that not nested more 3 levels of deep because es more reusable, if you change any elements or add a element your selector not work 您有一个选择器,其选择器的深度为4级以上,这是一个好习惯,不要嵌套3级以上的深度,这是因为es更可重用,如果更改任何元素或添加元素,则选择器不起作用

Your question, that proprieties should have the element father, and the elements li, have the property that you need change 您的问题是,礼节应具有元素父亲,元素li应具有您需要更改的属性

first things first, your selector should be on the last li:hover 首先,您的选择器应位于最后一个li:hover

header nav div ul li:hover ul{
    /* CSS magic */
}

CSS doesn't have a ease-in transition, you're might be thinking of jQuery fadeIn ? CSS没有轻松过渡,您可能正在考虑jQuery fadeIn吗? Either way, CSS transitions work like this: 无论哪种方式, CSS转换都是这样的:

transition: [property|all] [duration] [timing function] [delay];

For instance, if you'd want to ease in from hidden to visible: 例如,如果您希望从隐藏变为可见:

header nav div ul li ul{
    transition: opacity .33s ease;
    opacity: 0;
}
header nav div ul li:hover ul{
    opacity: 1;
}

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

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