表单美化

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')
})
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,496评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,407评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,632评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,180评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,198评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,165评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,052评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,910评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,324评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,542评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,711评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,424评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,017评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,668评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,823评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,722评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,611评论 2 353

推荐阅读更多精彩内容

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