html - 无法在此下拉菜单上应用过渡
问题描述
我似乎无法对我所做的这个下拉列表应用过渡。它看起来不好的原因是因为它只是为了测试目的,因此我来这里寻求帮助。如果您能帮助我,将不胜感激:)
很明显,我做错了,或者我做下拉菜单的方式很明显,这样过渡不会影响任何事情。
这是我的 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>
解决方案
您尚未声明要转换的属性。来自 MDN 文档:
div {
transition: <property> <duration> <timing-function> <delay>;
}
请记住,并非所有属性都可以转换。
资源:https ://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions
推荐阅读
- amazon-web-services - AWS Step Functions - 在不发生迭代时利用空 Map 状态输出
- python - google 的 python 风格指南 - 属性说明
- arrays - 如何在 Kotlin 中从单个字符串创建字符串数组
- javascript - Socket.io - React:如何显示房间中连接的用户?
- python - Python 请求问题 self._store[key.lower()][1]
- java - 用递归方法填充字符串列表(递归填充方法)
- r - 无法使用 R 对数据进行分类
- c# - EPPlus 将工作表从 Workbook1 复制到 Workbook2
- python - 模型拟合/TypeError:“NoneType”对象不可调用
- php - 在 Botman studio 中获取用户信息问题