css ——搜索框(精灵技术)

一、搜索框(精灵技术)

未点击的效果图
在这里插入图片描述
点击后的效果图
在这里插入图片描述
html

<section class="shop-sousu">
               <input type="text" name="" id="" placeholder="搜索偶像、商品">
               <span class="sectbtn"></span>
              </section>

这里用的是sass写的(影响不大)css

.shop-sousu {
            display: flex;
            height: 30px;
            padding-top: 23px;
            padding-left: 200px;
            box-sizing: border-box;
            position: relative;


            input {
                border: none;
                width: 430px;
                height: 40px;
                background-image: url(/img/icon/search_icon.png);
                background-repeat: no-repeat;
                background-position: 0 -44px;
                background-color: transparent; //input背景色透明
                outline: none; //内框线去掉
                padding-left: 2em;
                
                // 选择获得焦点的输入字段
                &:focus {
                    background-position: 0 0;
                }
                // 放大镜按钮点击点击后
                &:focus+span {
                    display: block;
                    color: white;
                    // border: 1px solid red;
                    width: 20px;
                    height: 20px;
                    background-image: url(/img/icon/search_icon.png);//背景图片
                    background-repeat: no-repeat;//背景不平铺
                    background-position: -465px -52px;
                    position: absolute;//绝对定位
                    top: 32px;
                    right: 11px;
                }
            }

            // 放大镜按钮点击前
            .sectbtn {
                
                display: block;
                color: white;
                // border: 1px solid red;
                width: 20px;
                height: 20px;
                background-image: url(/img/icon/search_icon.png);
                background-repeat: no-repeat;
                background-position: -465px -10px;
                position: absolute;
                top: 32px;
                right: 10px;

            }


        }

:focus伪元素选择器:是选择获得焦点的输入字段,并设置其样式:例如:用户单击一个input输入框获取焦点,然后这个input输入框的边框样式就会发生改变,和其他的输入框区别开来,表明已被选中

结构伪类选择器:
选择符简介
:firse-child匹配父元素中的第一个子元素E
:last-child匹配父元素中的最后一个子元素E
:nth-child(n)匹配父元素中的第n个子元素E
:first-of-type匹配指定类型E的第一个子元素
:last-of-type匹配指定类型E的最后一个子元素
:nth-of-type(n)匹配指定类型E的第n个子元素

背景颜色透明
background-color: transparent;
背景平铺
background-repeat : repeat | no-repeat | repeat-x | repeat-y

参数值作用
repeat背景图像在纵向和横向上平线(默认的)
no-repeat背景图像不平铺
repeat-x背景图片在横向上平铺
repeat-y背景图像在纵向平铺

可以改变图片在背景中的位置
background-position : x y;

参数值说明
length 百分数由浮点数字和单位标识符组成的长度值
position topcenter

设置背景图像是否固定或者随着页面的其余部分滚动
background-attachment : scroll | fixed

参数作用
scroll背景图像是随对象内容滚动
fixed背景图像固定
  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值