首页 > 解决方案 > 无法在此下拉菜单上应用过渡

问题描述

我似乎无法对我所做的这个下拉列表应用过渡。它看起来不好的原因是因为它只是为了测试目的,因此我来这里寻求帮助。如果您能帮助我,将不胜感激:)

很明显,我做错了,或者我做下拉菜单的方式很明显,这样过渡不会影响任何事情。

这是我的 HTML 代码:

* {
    margin: 0;
    padding: 0;
    font-family: Arial, Helvetica, sans-serif;
    outline: 0;
}

body {
    display: grid;
    place-items: center;
    min-height: 90vh;
}

.container {
    width: 200px;
    height: 400px;
    border: 1px solid black;
    text-align: center;
    text-transform: capitalize;
    list-style: none;
    font-size: 20px;
}

li {
    padding: 10px;
    border-bottom: 1px solid black;
    cursor: pointer;
}

li, .box {
    transition: .25s;
}

li:hover, .box:hover {
    background-color: #f1f1f1;
}

.list-item-1:hover + .dropdown {
    display: grid;
}

.dropdown {
    display: none;
    padding: 10px 50px;
    border-bottom: 1px solid black;
}

.dropdown:hover {
    display: grid;
}

.box {
    padding: 5px 0;
    border-bottom: 1px solid black;
    cursor: pointer;
}

.box:last-child {
    border-bottom: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <ul class="container">
        <li class="list-item-1">something</li>
        <div class="dropdown">
            <div class="box">link 1</div>
            <div class="box">link 1</div>
            <div class="box">link 1</div>
            <div class="box">link 1</div>
        </div>
        <li class="list-item-1">something</li>
        <div class="dropdown">
            <div class="box">link 1</div>
            <div class="box">link 1</div>
            <div class="box">link 1</div>
            <div class="box">link 1</div>
        </div>
    </ul>
</body>
</html>

标签: htmlcss

解决方案


您尚未声明要转换的属性。来自 MDN 文档:

div {
  transition: <property> <duration> <timing-function> <delay>; 
}

请记住,并非所有属性都可以转换。

资源:https ://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions


推荐阅读