表单美化

fake-baidu

  • html:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="https://at.alicdn.com/t/font_1058920_4sjoxjshme.js"></script>
</head>
<body>
  <div class="wrapper">
    <span class="inputWrapper">
      <input id="keyword" type="text" autocomplete="off">
      <span class="floatDiv">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-mic"></use>
        </svg>
        <span class="splitLine"></span>
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-camera"></use>
        </svg>
      </span>
    </span>
    <button>百度一下</button>
    <ul id="suggestion" class="suggestion">
      <li>选项1</li>
      <li>选项2</li>
      <li>选项3</li>
      <li>选项4</li>
    </ul>
  </div>
</body>
</html>
  • css:
* {
  margin: 0;
  padding: 0;
}
* {
  box-sizing: border-box;
}
ul,ol {
  list-style: none;
}
.icon {
  width: 1em; height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
.wrapper {
  display: flex;
  position: relative;
}
.suggestion {
  position: absolute;
  top: 100%;
  left: 0;
  display: none;
}
.suggestion.active{
  display: block;
}
.floatDiv {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 10px;
  color: #b8b8b8;
}
.splitLine {
  width: 0;
  height: 16px;
  border-left: 1px solid;
  margin: 0 10px;
}
.inputWrapper {
  position: relative;
  display: inline-block;/*玄学*/
  float: left;/*为了清除两个span之间的空隙*/
}
.inputWrapper + button {
  float: left;/*为了清除两个span之间的空隙*/ 
}
.inputWrapper input[type=text] {
  border: 1px solid #b8b8b8;
  width: 540px;
  height: 35px;
  padding-left: 8px;
  font-size: 15px;
  line-height: 35px;
}
.inputWrapper input[type=text]:focus {
  outline: none;
  border-color: #4b94fc;
}
.inputWrapper svg.icon {
  width: 20px;
  height: 20px;
  fill: #b8b8b8;
}
.inputWrapper svg.icon:hover {
  fill: #4b94fc;
  cursor: pointer;
}
.inputWrapper + button {
  background: #4b94fc;
  border: none;
  font-size: 14px;
  color: white;
  padding: 0 20px;
}
.inputWrapper + button:focus {
  outline: none;
}
.inputWrapper + button:hover {
  box-shadow: 1px 1px 1px 0 rgba(0, 0, 0, 0.2);
  background: #3781F0;
}
  • javascript:
keyword.oninput = function(e){
  var value = keyword.value
  if(value) {
    suggestion.classList.add('active')
  }else{
    suggestion.classList.remove('active')
  }
}
  • output:


图片上传

  • html:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
<form action="xxx">
  <div class="imagePicker">
    <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1551098772209&di=d3d333e90361357eb78a0b8a2a1aa757&imgtype=0&src=http%3A%2F%2Fcbu01.alicdn.com%2Fimg%2Fibank%2F2015%2F305%2F851%2F2172158503_174163100.jpg_270x270xzq60.jpg" alt="">
    <input id="imageInput" type="file">
    <div class="mask">
      编辑
    </div>
  </div>
</form>
</body>
</html>
  • css:
.imagePicker {
  width: 120px;
  height: 120px;
  border: 1px solid red;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 60px;
  overflow: hidden;
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.5);
  position: relative;
}
.imagePicker img {
  max-width: 100%;
  max-height: 100%;
  vertical-align: top;/*玄学*/
}
.imagePicker input[type=file] {
  position: absolute;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  opacity: 0;
  z-index: 1;
  cursor: pointer;
}
.imagePicker .mask {
  display: none;
  position: absolute;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0; 
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  color: white;
}
.imagePicker:hover .mask {
  display: flex;
}
  • js:
imageInput.onchange = function(e) {
  e.target.value = ''
}

  • output:


美化按钮

  • html:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <button id="b" class="yaoButton">按钮
    <span class="circle"></span>
  </button>
</body>
</html>
  • css:
.yaoButton {
  background: none;
  border: none;
  box-sizing: border-box;
  height: 36px;
  line-height: 36px;
  padding: 0 16px;
  font-size: 14px;
  transition: all 0.5s;
  position: relative;
  overflow: hidden;
  z-index: 0;
}
.yaoButton:hover {
  background: #E5E5E5;
}
.yaoButton:focus {
  outline: none;
  background: #E5E5E5;
}
.yaoButton > .circle {
  position: absolute;
  top: 50%;
  left: 50%;
  border:  1px solid red;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: red;
  /* transform: translate(-50%, -50%); */
  margin-left: -5px;
  margin-top: -5px;
  transition: transform 0.5s;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}
.yaoButton > .circle.active {
  transform: scale(8);
  visibility: visible;
}
  • js:
b.onclick = function() {
  b.querySelector('.circle').classList.add('active')
}
b.querySelector('.circle')
  .addEventListener('transitionend',function(){
  b.querySelector('.circle').classList.remove('active')
})
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.表单美化—单选框 html结构 css样式 js代码 2.表单美化—复选框 html结构 css样式 js代码...
    渣渣灰灰阅读 1,204评论 0 5
  • 美化input 美化input的代码示例: 使用的工具: canuise:查看属性在不同浏览器的支持情况 QQ截图...
    学的会的前端阅读 285评论 0 1
  • 1、模仿百度输入框 让xy浮起来,这里看到输入框input和xy直接还有空隙(原因是两者之间有回车)这个空隙在不同...
    tsl1127阅读 258评论 0 0
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,958评论 1 45
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,305评论 4 61