下拉菜单过渡

下拉过渡,利用Y轴的transform:scaleY(0) ---》transform:scaleY(1)

代码:

javascript 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background-color: #f4f4f4;
        }
        .text-select {
            width: 300px;
            /* background: #fff; */
            /* border-radius: 8px; */
            /* box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); */
            overflow: hidden;
            position: relative;
        }
        .text-select .text {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-bottom: none;
            /* border-radius: 8px 8px 0 0; */
            box-sizing: border-box;
            font-size: 16px;
            transition: border-color 0.3s ease;
        }
        .text-select .text:focus {
            border-color: #007BFF;
            outline: none;
        }
        .text-select .select {
            border: 1px solid #ddd;
            border-top: none;
            background: #fff;
            border-radius: 0 0 8px 8px;
            overflow: hidden;
            transform-origin: top;
            transform: scaleY(0);
            transition: transform 0.3s ease;
            z-index: 1;
        }
        .text-select .select span {
            display: block;
            padding: 10px;
            font-size: 14px;
            color: #333;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .text-select .select span:hover {
            background-color: #f0f0f0;
        }
        .text-select .text:focus ~ .select {
            transform: scaleY(1);
        }
    </style>
</head>
<body>
    <div class="text-select">
        <input type="text" class="text" placeholder="Select an option..." />
        <div class="select">
            <span>Option 1</span>
            <span>Option 2</span>
            <span>Option 3</span>
            <span>Option 4</span>
            <span>Option 5</span>
        </div>
    </div>
</body>
</html>```
相关推荐
Asthenia041230 分钟前
技术复盘:从一次UAT环境CORS故障看配置冗余的危害与最佳实践
前端
csj5035 分钟前
前端基础之《React(1)—webpack简介》
前端·react
被巨款砸中38 分钟前
前端 20 个零依赖浏览器原生 API 实战清单
前端·javascript·vue.js·web
文韬_武略1 小时前
web vue之状态管理Pinia
前端·javascript·vue.js
董世昌411 小时前
js怎样改变元素的内容、属性、样式?
开发语言·javascript·ecmascript
mosen8681 小时前
【Vue】Vue Router4x关于router-view,transtion,keepalive嵌套写法报错
前端·javascript·vue.js
鸠摩智首席音效师2 小时前
如何清除 Yarn 缓存 ?
javascript
写不来代码的草莓熊2 小时前
vue前端面试题——记录一次面试当中遇到的题(5)
前端
weixin_ab2 小时前
【HTML分离术】
前端·html
文心快码BaiduComate3 小时前
新手该如何选择AI编程工具?文心快码Comate全方位体验
前端·后端·程序员