input[type=search]

input元素可以通过属性控制
MDN
https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input/search

css3新增属性控制input[type=search]

1.::-webkit-input-placeholder
2.::-webkit-search-cancel-button

重写边框样式

input[type=search]{
    border-radius: 5px;
    border: 1px solid #ebebeb;//必须对默认的border:2px inset覆盖,要不然下面的样式也是白搭
    width: 98%;
    height: 30px;
    outline: none;
}

重写占位符样式

input[type=search]::-webkit-input-placeholder{
    color: blue;
}

重写后面的小×样式

input[type=search]::-webkit-search-cancel-button{
    -webkit-appearance: none;//此处只是去掉默认的小×
}

重写小×样式

input[type=search]::-webkit-search-cancel-button{
    -webkit-appearance: none;

    position: relative;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background-color: #EBEBEB;
}

input[type=search]::-webkit-search-cancel-button:after{
    position: absolute;
    content: 'x';
    left: 25%;
    top: -12%;
    font-size: 20px;
    color: #fff;
}

正常情况软键盘上出现return。如果要出现search按钮,结构如下

<form action="#">
    <input type="search"/>
</form>

猜你喜欢

转载自blog.csdn.net/longlc123/article/details/81135305