HTML5+CSS3小实例:全屏搜索栏

实例:全屏搜索栏
技术栈:HTML+CSS
效果:

源码:
【html】



 

    
    
 
    全屏搜索栏
    
    

 

    
    
    
    

【css】

*{
    /* 初始化 */
    margin: 0;
    padding: 0;
    /* box-sizing: border-box; */
}
body{
    /* 100%窗口高度 */
    height: 100vh;
    /* 弹性布局 水平+垂直居中 */
    display: flex;
    justify-content: center;
    align-items: center;
}
/* 搜索按钮 */
.search-btn{
    position: relative;
    z-index: 1;
    width: 60px;
    height: 60px;
    line-height: 60px;
    text-align: center;
    cursor: pointer;
}
.search-btn .fa{
    color: #fff;
    font-size: 22px;
}
/* 关闭按钮 */
.close-btn{
    position: absolute;
    top: 25px;
    right: 25px;
    z-index: 1;
    font-size: 25px;
    color: #fff;
    cursor: pointer;
    display: none;
}
.container{
    /* 固定定位 */
    position: fixed;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    /* 渐变背景 */
    background: linear-gradient(200deg,#6e86ee,#453c90);
    /* 将元素剪切为一个圆形 【25px表示圆的半径】 【50% 50%表示圆心位置】 */
    clip-path: circle(30px at 50% 50%);
    /* 设置过渡 */
    transition: 0.4s;
}
.search-box{
    /* 默认宽度为0(隐藏) */
    width: 0;
    height: 50px;
    display: flex;
    border-bottom: 3px solid #fff;
    /* 溢出隐藏 */
    overflow: hidden;
    transition: 0.3s;
}
.search-box input{
    width: 100%;
    height: 50px;
    background: none;
    border: none;
    outline: none;
    color: #fff;
    font-size: 22px;
    font-weight: 500;
    text-indent: 8px;
}
.search-box input::placeholder{
    color: rgba(255,255,255,0.7);
}
.search-box .fa{
    width: 50px;
    height: 50px;
    line-height: 50px;
    color: #fff;
    font-size: 22px;
    text-align: center;
    cursor: pointer;
}
#search_btn:checked ~ .search-btn{
    display: none;
}
#search_btn:checked ~ .close-btn{
    display: block;
}
#search_btn:checked ~ .container{
    clip-path: circle(100%);
}
#search_btn:checked ~ .container .search-box{
    width: 400px;
}

你可能感兴趣的:(HTML5+CSS3小实例:全屏搜索栏)