jbu*_*483 10 css hover css3 pseudo-element
我试图生成一个使用:before和:after伪元素的屏幕,但我想知道这样的功能是否真的可行.
我有一个包装器div,它包裹在一个输入(允许pseudo element在这个包装器上的s).
就像是:
+-----------------------------------+
| +-------------------------------+ |
| | | | <-- wrapper div
| +-------------------------------+ <-- input element
+-----------------------------------+
Run Code Online (Sandbox Code Playgroud)
但是,我希望在div之后放置一个伪元素.
+-----------------------------------++-------+
| +-------------------------------+ | |¯¯¯| |
| | | | / |
| +-------------------------------+ | ! |<--pseudo element
+-----------------------------------++-------+
Run Code Online (Sandbox Code Playgroud)
我想要能够悬停这个伪元素,并出现其他伪元素.
.wrap {
position: relative;
height: 30px;
width: 200px;
display: inline-block;
}
.wrap input {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
.wrap:after {
content: "?";
position: absolute;
top: 0;
left: 100%;
height: 30px;
width: 30px;
font-size: 30px;
text-align: center;
}
.wrap:before {
content: "";
position: absolute;
top: 100%;
left: 0;
height: 60px;
width: 100%;
background: tomato;
opacity:0.2;
}Run Code Online (Sandbox Code Playgroud)
<div class="wrap">
<input placeholder="input element" type="text" />
</div>Run Code Online (Sandbox Code Playgroud)
从上面的片段设计,:before当我只悬停:after元素而不是wrapdiv本身时,有没有一种方法可以让元素改变它的不透明度(注意:html不能改变,因此为什么这个问题)?
我尝试过使用类似的东西:
.wrap:not(input):hover:before{
Run Code Online (Sandbox Code Playgroud)
更改输入的宽度后90%,但这没有什么区别
看来因为伪元素不是“真实”元素,这意味着(当前)不能以这种方式使用。相反,使用“真实”元素可以实现这一点,因此我选择使用 span 元素,直到该功能可能会或可能不会实现。
当前的实现显示:
input {
position: relative;
display: inline-block;
height: 30px;
vertical-align: top;
}
span {
position: relative;
height: 30px;
width: 30px;
display: inline-block;
text-align: center;
border-radius: 50%;
font-size: 25px;
line-height: 30px;
background: tomato;
}
span:after {
content: "A Question Mark";
position: relative;
display: inline-block;
top: 0;
left: 0;
height: 60px;
width: 100px;
background: tomato;
opacity: 0;
transition: all 0.8s;
font-size: 16px;
}
span:hover:after {
opacity: 1;
}Run Code Online (Sandbox Code Playgroud)
<input placeholder="input element" type="text" />
<span>?</span>Run Code Online (Sandbox Code Playgroud)
让我心爱的伪元素设计非常失望。