div+css实现聚焦简洁输入框搜索框效果代码
代码语言:html
所属分类:搜索
代码描述:div+css实现聚焦简洁输入框搜索框效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" /> <style> /* this is a recreation of twitter search in css */ body{ background: black; padding: 120px; } .form { --input-text-color: #fff; --input-bg-color: #283542; --focus-input-bg-color: transparent; --text-color: #949faa; --active-color: #1b9bee; --width-of-input: 200px; --inline-padding-of-input: 1.2em; --gap: 0.9rem; } /* form style */ .form { font-size: 0.9rem; display: flex; gap: 0.5rem; align-items: center; width: var(--width-of-input); position: relative; isolation: isolate; } /* a fancy bg for showing background and border when focus. */ .fancy-bg { position: absolute; width: 100%; inset: 0; background: var(--input-bg-color); border-radius: 30px; height: 100%; z-index: -1; pointer-events: none; box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px; } /* label styling */ label { width: 100%; padding: 0.8em; height: 40px; padding-inline: var(--inline-padding-of-input); display: flex; align-items: center; } .search,.close-btn { position: absolute; } /* styling search-icon */ .search { fill: var(--text-color); left: var(--inline-padding-of-input); } /* svg -- size */ svg { width: 17px; display: block; } /* styling of close button */ .close-btn { border: none; right: var(--inline-padding-of-input); box-sizing: border-box; display: flex; align-items: center; justify-content: center; color: #fff; padding: 0.1em; width: 20px; height: 20px; border-radius: 50%; background: var(--active-color); opacity: 0; visibility: hidden; } /* styling of input */ .input { color: var(--input-text-color); width: 100%; margin-inline: min(2em,calc(var(--inline-padding-of-input) + var(--gap))); background: none; border: none; } .input:focus { outline: none; } .input::placeholder { color: var(--text-color) } /* input background change in focus */ .input:focus ~ .fancy-bg { border: 1px solid var(--active-color); background: var(--focus-input-bg-color); } /* search icon.........完整代码请登录后点击上方下载按钮下载查看
网友评论0