css in html how to,html - How to do floating of labels in CSS - Stack Overflow

Check this Tutorial Link

This is inspired by latest Gmail Login style

N6cP4.png

HTML

It's nice to meet you.

Enter your email
Enter your password

Login

CSS Style

.field-wrapper{

position: relative;

margin-bottom: 15px;

}

.field-wrapper input{

border: 1px solid #DADCE0;

padding: 15px;

border-radius: 4px;

width: 100%;

}

.field-wrapper input:focus{

border:1px solid #1A73E8;

}

.field-wrapper .field-placeholder{

font-size: 16px;

position: absolute;

/* background: #fff; */

bottom: 17px;

-webkit-box-sizing: border-box;

box-sizing: border-box;

color: #80868b;

left: 8px;

padding: 0 8px;

-webkit-transition: transform 150ms cubic-bezier(0.4,0,0.2,1),opacity 150ms cubic-bezier(0.4,0,0.2,1);

transition: transform 150ms cubic-bezier(0.4,0,0.2,1),opacity 150ms cubic-bezier(0.4,0,0.2,1);

z-index: 1;

text-align: left;

width: 100%;

}

.field-wrapper .field-placeholder span{

background: #ffffff;

padding: 0px 8px;

}

.field-wrapper input:not([disabled]):focus~.field-placeholder

{

color:#1A73E8;

}

.field-wrapper input:not([disabled]):focus~.field-placeholder,

.field-wrapper.hasValue input:not([disabled])~.field-placeholder

{

-webkit-transform: scale(.75) translateY(-39px) translateX(-60px);

transform: scale(.75) translateY(-39px) translateX(-60px);

}

jQuery Event Listener

$(".field-wrapper .field-placeholder").on("click", function () {

$(this).closest(".field-wrapper").find("input").focus();

});

$(".field-wrapper input").on("keyup", function () {

var value = $.trim($(this).val());

if (value) {

$(this).closest(".field-wrapper").addClass("hasValue");

} else {

$(this).closest(".field-wrapper").removeClass("hasValue");

}

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值