CSS 菜单过渡

标签 css menu navigation css-transitions

JSFiddle:http://jsfiddle.net/x6bM3/

如果您将鼠标悬停在产品链接上,您会看到我已经创建了一个下拉效果,但我想做的是给它一个很好的过渡,而不是仅仅出现。 我曾尝试在菜单的各个部分使用 :hover 和 css 转换,但在研究它之后我意识到动画无法与 display: none; 一起使用。在上面。请帮忙,

提前致谢, 亚当

CSS:

nav ul ul {
    display: none;
}
nav ul li:hover > ul {
    display: block;
}
nav ul {
    list-style: none;
    position: relative;
    display: inline-table;
    margin-top: 23px;
    padding: 0;
    float: left;
}
nav ul:after {
    content:"";
    display: block;
}
nav ul li {
    float: left;
    height: 50px;
    width: auto;
    padding: 5px;
    margin-left: 22px;
}
nav ul li a {
    display: block;
    text-decoration: none;
}
nav ul ul {
    background: #363c43;
    border-radius: 3px;
    border: 1px solid #2e363f;
    padding: 7px;
    position: absolute;
    font-size: 0.9em;
}
nav ul ul:before {
    content:'';
    display:block;
    width:0;
    height:0;
    position:absolute;
    border-right: 7px solid transparent;
    border-left: 7px solid transparent;
    border-bottom:10px solid #363c43;
    top:-8px;
    left: 30px;
}
nav ul ul li {
    height: 30px;
    float: none;
    position: relative;
    padding: 0px 0px 5px 0px;
    margin: 0px;
}
/* Other base styles */
 * {
    font-family: arial;
}
a:link, a:visited {
    color: #979797;
    font-size: 1.145em;
    /* 18px */
    text-decoration: none;
    font-weight: lighter;
    -webkit-transition: all .25s linear;
    transition: color .25s linear;
}
a:hover {
    color: #c4c1c1;
    font-size: 1.145em;
    /* 22px */
    text-decoration: none;
}

HTML:

<nav>
    <ul class="menu">
        <li><a href="index.php">home</a>
        </li>
        <li><a href="index.php">products</a>

            <ul>
                <li><a href="#">product 1</a>
                </li>
                <li><a href="#">product 2</a>
                </li>
            </ul>
        </li>
        <li><a href="index.php">solutions</a>
        </li>
    </ul>
</nav>

最佳答案

我可以详细解释,但是这个人做得很好:https://stackoverflow.com/a/3332179/363605

nav ul ul {
    display: block;
    -webkit-transition: opacity 1s ease-in;
    -moz-transition: opacity 1s ease-in;
    -o-transition: opacity 1s ease-in;
    transition: opacity 1s ease-in;
    opacity: 0; 
    height: 0;
    overflow: hidden;
}
nav ul li:hover > ul {
    height: auto;
    opacity: 1;
}

http://jsfiddle.net/pYhrk/

关于CSS 菜单过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14820403/

相关文章:

html - 如何在 HTML 电子邮件 css 中对齐表格

android - Menu.xml 以编程方式

ios - 向后滑动失败时,SwiftUI 导航栏项目变得困惑

html - 粗体悬停移动元素。唯一的解决方案在 firefox 中不起作用

css - 调整大小的浏览器在某处添加 1px 或从 css 中获取 1px 的高度,为什么?

CSS 5 张图片中的一张没有与其他图片对齐

jquery - 动态创建一个 div 并将其底部与另一个组件的顶部对齐

jQuery 和 CSS 弹出菜单链接问题

macos - 有没有办法在文件夹内右键单击并在 Mac 上打开终端? (就像 ubuntu 中的那个)

authentication - Flutter:应用生命周期之间的导航问题