表单美化

fake-baidu

  • html:



  
  Document
  


  
  • 选项1
  • 选项2
  • 选项3
  • 选项4
  • 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:



  
  Document


编辑
  • 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:



  
  Document


  


  • 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')
})

你可能感兴趣的:(表单美化)