作者:继续微笑丶保持硪的骄傲_195 | 来源:互联网 | 2023-02-11 19:57
我正在寻找css代码,将占位符文本移动到焦点上的输入上方.我在这里找到了这段代码.这段代码是完美的,但我的输入标签被包装在里面
,因此一般的兄弟选择器不起作用.有任何想法如何编辑这个CSS?
Your email address
Robert Stanl..
10
:placeholder-shown
在这种情况下,您可以使用CSS伪选择器来检测何时移动假占位符.见下面的例子:
label {
margin:20px 0;
position:relative;
display:inline-block;
}
span {
padding:10px;
pointer-events: none;
position:absolute;
left:0;
top:0;
transition: 0.2s;
transition-timing-function: ease;
transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
opacity:0.5;
}
input {
padding:10px;
}
input:focus + span, input:not(:placeholder-shown) + span {
opacity:1;
transform: scale(0.75) translateY(-100%) translateX(-30px);
}
/* For IE Browsers*/
input:focus + span, input:not(:-ms-input-placeholder) + span {
opacity:1;
transform: scale(0.75) translateY(-100%) translateX(-30px);
}
1> Robert Stanl..:
:placeholder-shown
在这种情况下,您可以使用CSS伪选择器来检测何时移动假占位符.见下面的例子:
label {
margin:20px 0;
position:relative;
display:inline-block;
}
span {
padding:10px;
pointer-events: none;
position:absolute;
left:0;
top:0;
transition: 0.2s;
transition-timing-function: ease;
transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
opacity:0.5;
}
input {
padding:10px;
}
input:focus + span, input:not(:placeholder-shown) + span {
opacity:1;
transform: scale(0.75) translateY(-100%) translateX(-30px);
}
/* For IE Browsers*/
input:focus + span, input:not(:-ms-input-placeholder) + span {
opacity:1;
transform: scale(0.75) translateY(-100%) translateX(-30px);
}
2> LGSon..:
使用给定的链接CSS等,只需移动floating-label
内部blocking-span
.
通过使用position: relative
在div
该floating-label
仍将重新定位就好像它是外blocking-span
div {
position: relative; /* make label relate to div */
padding-top: 10px; /* make space for label */
}
.inputText {
font-size: 14px;
width: 200px;
height: 25px;
}
.floating-label {
position: absolute;
pointer-events: none;
left: 15px;
top: 18px;
transition: 0.2s ease all;
}
input:focus ~ .floating-label,
input:not(:focus):valid ~ .floating-label {
top: -6px;
}
Your email address