CSS:伸缩式搜索框(Bootstrap字体图标)

该文章展示了如何使用CSS和Bootstrap的字体图标创建一个可伸缩的搜索框。HTML结构包含一个输入框和一个搜索按钮,通过CSS定义了样式,包括清除默认边距,设置定位,以及添加过渡效果来改变输入框的宽度和搜索按钮的背景色。
摘要由CSDN通过智能技术生成

CSS:伸缩式搜索框(Bootstrap字体图标)

1. HTML代码

<body>
    <div class="box">
        <input type="text" name="" class="txt" placeholder="你想搜啥?">
        <a href="#" class="btn">
            <i class="glyphicon glyphicon-search"></i>
        </a>
    </div>
</body>

2. CSS样式代码

		/* 清除浏览器默认的margin和padding */
        * {
            margin: 0;
            padding: 0;
        }
        .box {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            height: 60px;
            background-color: #2f3640;
            border-radius: 60px;
            padding: 10px;
        }

        /* 文本输入框样式 */
        .txt {
            /* 清除边框 */
            border: 0;
            /* 清除轮廓 */
            outline: none;
            float: left;
            height: 40px;
            padding: 0px;
            border-radius: 40px;
            font-size: 16px;
            /* 居中 */
            line-height: 40px; 
            width: 0; 
            background: none;
            color: #FFF;
            /* 过渡时间 */
            transition: all 0.5s;
        }
        /* 文本输入框提示语 */
        .txt::placeholder {
            color: #FFF;
            /* 半透明 */
            opacity: .5;
        }

        /* 搜索按钮样式 */
        .btn {

            float: right;
            width: 40px;
            height: 40px;
            color: #e84118;
            border-radius: 40px;
            font-size: 18px;
            /* flex布局 */
            display: flex;
            /* 水平居中 */
            justify-content: center;
            /* 垂直居中 */
            align-items: center;
            /* 过渡时间 */
            transition: all 0.5s;
        }

        .box:hover .txt {
            width: 200px;
            padding: 0 10px;
        }
        .box:hover .btn {
            background-color: #fff;
        }

3. 效果

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值