表單美化

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>選項(xiàng)1</li>
      <li>選項(xiàng)2</li>
      <li>選項(xiàng)3</li>
      <li>選項(xiàng)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;/*玄學(xué)*/
  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;/*玄學(xué)*/
}
.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')
})
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市口注,隨后出現(xiàn)的幾起案子吊骤,更是在濱河造成了極大的恐慌粗井,老刑警劉巖祖搓,帶你破解...
    沈念sama閱讀 223,207評論 6 521
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異署照,居然都是意外死亡禽作,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,455評論 3 400
  • 文/潘曉璐 我一進(jìn)店門岸裙,熙熙樓的掌柜王于貴愁眉苦臉地迎上來猖败,“玉大人,你說我怎么就攤上這事降允《魑牛” “怎么了?”我有些...
    開封第一講書人閱讀 170,031評論 0 366
  • 文/不壞的土叔 我叫張陵剧董,是天一觀的道長幢尚。 經(jīng)常有香客問我,道長翅楼,這世上最難降的妖魔是什么尉剩? 我笑而不...
    開封第一講書人閱讀 60,334評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮毅臊,結(jié)果婚禮上理茎,老公的妹妹穿的比我還像新娘。我一直安慰自己管嬉,他們只是感情好皂林,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,322評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著蚯撩,像睡著了一般础倍。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上胎挎,一...
    開封第一講書人閱讀 52,895評論 1 314
  • 那天著隆,我揣著相機(jī)與錄音,去河邊找鬼呀癣。 笑死美浦,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的项栏。 我是一名探鬼主播浦辨,決...
    沈念sama閱讀 41,300評論 3 424
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了流酬?” 一聲冷哼從身側(cè)響起币厕,我...
    開封第一講書人閱讀 40,264評論 0 277
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎芽腾,沒想到半個月后旦装,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,784評論 1 321
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡摊滔,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,870評論 3 343
  • 正文 我和宋清朗相戀三年阴绢,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片艰躺。...
    茶點(diǎn)故事閱讀 40,989評論 1 354
  • 序言:一個原本活蹦亂跳的男人離奇死亡呻袭,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出腺兴,到底是詐尸還是另有隱情左电,我是刑警寧澤,帶...
    沈念sama閱讀 36,649評論 5 351
  • 正文 年R本政府宣布页响,位于F島的核電站篓足,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏闰蚕。R本人自食惡果不足惜纷纫,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,331評論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望陪腌。 院中可真熱鬧,春花似錦烟瞧、人聲如沸诗鸭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,814評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽强岸。三九已至,卻和暖如春砾赔,著一層夾襖步出監(jiān)牢的瞬間蝌箍,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,940評論 1 275
  • 我被黑心中介騙來泰國打工暴心, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留妓盲,地道東北人。 一個月前我還...
    沈念sama閱讀 49,452評論 3 379
  • 正文 我出身青樓专普,卻偏偏與公主長得像悯衬,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子檀夹,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,995評論 2 361

推薦閱讀更多精彩內(nèi)容

  • 1.表單美化—單選框 html結(jié)構(gòu) css樣式 js代碼 2.表單美化—復(fù)選框 html結(jié)構(gòu) css樣式 js代碼...
    渣渣灰灰閱讀 1,159評論 0 5
  • 美化input 美化input的代碼示例: 使用的工具: canuise:查看屬性在不同瀏覽器的支持情況 QQ截圖...
    學(xué)的會的前端閱讀 267評論 0 1
  • 1筋粗、模仿百度輸入框 讓xy浮起來策橘,這里看到輸入框input和xy直接還有空隙(原因是兩者之間有回車)這個空隙在不同...
    tsl1127閱讀 235評論 0 0
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML標(biāo)準(zhǔn)娜亿。 注意:講述HT...
    kismetajun閱讀 27,532評論 1 45
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫丽已、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,131評論 4 61