005_HTML製作炫酷登入介面(CSS精靈圖、背景圖片區域性顯示)
效果:
<center>
</center>
說明:
-
輸入框由三部分組成:
- 裝區域性圖示的span
- 顯示提示文字的span
- 接受使用者輸入的input
-
互動效果
- 剛開啟頁面,所有輸入框顯示提示文字
- 當input獲得焦點,提示文字消失
- 當input失去焦點,並且使用者沒有輸入內容,再次顯示提示文字
步驟
1.搭建HTML骨架
2.CSS佈局樣式
3.JS完成互動
1.搭建HTML骨架
<body>
<div class="adClass">
</div>
<form action="" method="post" id="reForm">
<div class="inputClass">
<!-- 用來顯示提示資訊 -->
<span>使用者名稱</span>
<!-- 用來接受使用者輸入 -->
<input type="text" name="username"/>
<!-- 用來放圖示的 -->
<span class="userSpan"></span>
</div>
<div class="inputClass">
<span>密碼</span>
<input type="text" name="password"/>
<span class="passwordSpan"></span>
</div>
<div class="inputClass">
<span>郵箱</span>
<input type="text" name="email"/>
<span class="emailSpan"></span>
</div>
<div class="inputClass">
<span>電話</span>
<input type="text" name="phone"/>
<span class="phoneSpan"></span>
</div>
<div class="inputClass">
<span>身份證號</span>
<input type="text" name="identity"/>
<span class="identitySpan"></span>
</div>
<!-- 註冊按鈕 -->
<div class="reClass">
<a href="#">註冊</a>
</div>
</form>
</body>
2.CSS佈局樣式
重點是學會精靈圖的使用,背景圖示的定位:background-position屬性。
.inputClass {
position: relative;
height: 40px;
width: 400px;
font-size: 15px;
border: 1px solid;
border-radius: 20px;
margin: auto;
color: darkgray;
}
input {
position: absolute;
font-size: 15px;
padding-left: 10px;
width: 80%;
height: 70%;
left: 43px;
top: 5px;
/*取消有焦點時候的預設邊框*/
outline: none;
/*取消預設背景*/
background: none;
/*取消預設邊框*/
border: 0px;
}
body {
text-align: center;
background-color: #F0FFFF;
}
/*精靈圖*/
.userSpan {
/*1.匯入背景圖*/
background-image: url(../img/login_ico.png);
position: absolute;
left: 20px;
top: 8px;
/*設定背景所在的容器的大小*/
width: 25px;
height: 25px;
/*設定背景的起始位置*/
/*
* 注意:
* 取影象右邊的內容,座標 0 - x
* 取影象下邊的內容,座標 0 - y
*
️ */
background-position: -125px 0px;
}
/*精靈圖*/
.passwordSpan {
/*1.匯入背景圖*/
background-image: url(../img/login_ico.png);
position: absolute;
left: 20px;
top: 8px;
/*設定背景所在的容器的大小*/
width: 25px;
height: 25px;
/*設定背景的起始位置*/
/*
* 注意:
* 取影象右邊的內容,座標 0 - x
* 取影象下邊的內容,座標 0 - y
*
️ */
background-position: -125px -34px;
}
/*精靈圖*/
.emailSpan {
/*1.匯入背景圖*/
background-image: url(../img/login_ico.png);
position: absolute;
left: 20px;
top: 8px;
/*設定背景所在的容器的大小*/
width: 25px;
height: 25px;
/*設定背景的起始位置*/
/*
* 注意:
* 取影象右邊的內容,座標 0 - x
* 取影象下邊的內容,座標 0 - y
*
️ */
background-position: -85px 0px;
}
/*精靈圖*/
.phoneSpan {
/*1.匯入背景圖*/
background-image: url(../img/login_ico.png);
position: absolute;
left: 20px;
top: 8px;
/*設定背景所在的容器的大小*/
width: 25px;
height: 25px;
/*設定背景的起始位置*/
/*
* 注意:
* 取影象右邊的內容,座標 0 - x
* 取影象下邊的內容,座標 0 - y
*
️ */
background-position: -85px -115px;
}
/*精靈圖*/
.identitySpan {
/*1.匯入背景圖*/
background-image: url(../img/login_ico.png);
position: absolute;
left: 20px;
top: 8px;
/*設定背景所在的容器的大小*/
width: 25px;
height: 25px;
/*設定背景的起始位置*/
/*
* 注意(容器不變,資料是圖片移動的方向和大小):
* 取影象右邊的內容,座標 0 - x
* 取影象下邊的內容,座標 0 - y
*
️ */
background-position: -85px -32px;
}
.inputClass span:first-child {
position: absolute;
font-size: 15px;
top: 9px;
left:43px;
padding-left: 10px;
}
.reClass {
position: relative;
background-color: rgb(0,255,255);
width: 250px;
margin: auto;
height: 60px;
border-radius: 40px;
}
.reClass a {
/*去除下劃線*/
text-decoration: none;
color: white;
font-size: 30px;
line-height: 60px;
}
.adClass {
position: relative;
background-image: url(../img/logo.png);
width: 620px;
height: 114px;
margin-top: 20px;
margin: auto;
}
3.JS完成互動
主要是完成:
- input獲得焦點,隱藏提示資訊
- input失去焦點,判斷使用者是否輸入了有效內容,有的話,就不再顯示提示資訊,否則就顯示
<script type="text/javascript">
$(function() {
//input獲得焦點,隱藏提示資訊
$("input").focus(function() {
$(this).prev("span").hide(200)
});
//input失去焦點,判斷使用者的輸入資訊是否有效,再決定是否顯示提示資訊
$("input").blur(function() {
if( $(this).val().trim() == "" ) {
$(this).prev("span").show(200)
}
});
//調整輸入框之間的間距
var countInput = $(".inputClass").length;
$(".inputClass").css({
"margin-top": 100.0 / countInput / 8 + "%",
"margin-bottom": 100.0 / countInput / 8 + "%"
});
});
</script>
效果和原始碼下載
https://mp.weixin.qq.com/s/N0w7m9005k8WsTpT5-uaeg
歡迎加入討論群:451826376
<center>
</center>
相關文章
- 小程式button背景顯示圖片
- HTML連載79-背景圖片定位區域屬性、背景顏色HTML
- CSS圖片的灰色顯示效果CSS
- 短視訊平臺原始碼,登入介面插入背景圖片原始碼
- CSS · 兩種背景圖片CSS
- CSS精靈圖技術CSS
- Mac圖片區域性擦除工具Mac
- CSS背景圖片集中在同一個圖片CSS
- Activity背景顯示app圖示APP
- CSS3製作圖片樣式CSSS3
- 打造炫酷效果:用Java優雅地製作Excel迷你圖JavaExcel
- CSS3第二天(元素顯示模式、圖片背景設定)CSSS3模式
- PPT怎麼製作漸變UI圖示?PPT扁平化圖示圖片的製作方法UI
- 使用css製作滑鼠經過圖片時,放大圖片1.5倍CSS
- jQuery實現圖示特效(精靈圖)jQuery特效
- word圖文混排複製到CuteEditor圖片不顯示
- word圖文混排複製到KindEditor圖片不顯示
- 不規則圖形背景排版高階技巧 -- 酷炫的六邊形網格背景圖
- CSS-背景圖片|background-imageCSS
- html+css 設定背景圖片HTMLCSS
- 圖片區域性識別怎麼操作
- GIF動圖怎麼製作?GIF圖片製作
- SVG動畫應用-酷炫的圖片展示效果SVG動畫
- BMP圖片的複製#顯示到螢幕
- AndroidStudio製作歡迎介面與應用圖示Android
- 怎麼製作區域分佈圖?區域網格分佈圖怎麼做?
- 場所位置圖怎麼製作,怎樣製作自己需要的區域地圖地圖
- 上海疫情實時動態地圖製作,疫情風控區域地圖”助力精準防疫!地圖
- 論文研究區域圖的製作方法:ArcGIS
- Laravel-admin 區域性使用阿里圖示 IconfontLaravel阿里
- 直播帶貨原始碼,背景圖片顯示鋪滿但不變形原始碼
- 直播平臺製作,Glide載入網路圖,進度條顯示IDE
- 【傳智播客上海校區】PS製作牛仔布圖示-圖層樣式製造圖示
- svg製作小圖示SVG
- CSS3 設定多個背景圖片CSSS3
- 如何在 CSS 背景圖片中對 SVG 圖片進行著色 ,修改svg圖片顏色CSSSVG
- rtabmap 區域性建圖
- 製作一個複雜通用的圖片上傳介面
- PS製作圓角圖片