本文介绍了在悬停一个伪元素时,使另一个伪元素显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图生成一个屏幕,其中使用:之前
和:之后
伪元素,
我有一个包装在一个输入(允许伪元素
s
+ ----------------------------------- +
| + ------------------------------- + |
| | | | < - wrapper div
| + ------------------------------- +< - input element
+ ------ ----------------------------- +
$ b
+ -
$ b ---------------------------------- ++ ------- +
| + ------------------------------- + | |¯¯¯| |
| | | | / |
| + ------------------------------- + | ! |< - 伪元素
+ ----------------------------------- ++ - ------ +
我想要能够悬停这个伪元素,其他伪元素出现。
.wrap {position:relative; height:30px; width:200px; display:inline-block;}。wrap input {position:absolute; top:0;左:0;高度:100%; width:100%;}。wrap:after {content:?; position:absolute; top:0;左:100%; height:30px; width:30px; font-size:30px; text-align:center;}。wrap:before {content:; position:absolute; top:100%;左:0; height:60px; width:100%;背景:番茄; opacity:0.2;}
< div class = > < input placeholder =input elementtype =text/>< / div>
$ b
从上面的代码片段设计,是否有一种方法使:之前
元素更改它不透明,当我只悬停:后
元素,而不是 wrap
div本身(注意:html不能更改,因此为什么这个问题)?
我尝试使用类似:
$ b b .wrap:not(input):hover:before {
$ b b
将 90%
的输入宽度改为
>解决方案 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;背景:番茄;} span:after {content:A Question Mark;位置:相对; display:inline-block; top:0;左:0; height:60px; width:100px;背景:番茄;不透明度:0; transition:all 0.8s; font-size:16px;} span:hover:after {opacity:1;}
< input placeholder =input elementtype =text/>< span>?< / span>
>
令人失望的伪装元素设计令人失望。
I was trying to generate a screen in which utilises the :before
and :after
pseudo elements, but I'm wondering if such functionality is actually possible.
I have a wrapper div which is wrapped around an input (allowing for pseudo element
s on this wrapper).
something like:
+-----------------------------------+
| +-------------------------------+ |
| | | | <-- wrapper div
| +-------------------------------+ <-- input element
+-----------------------------------+
However, I was looking to have a pseudo element positioned after the div.
+-----------------------------------++-------+
| +-------------------------------+ | |¯¯¯| |
| | | | / |
| +-------------------------------+ | ! |<--pseudo element
+-----------------------------------++-------+
I was wanting to be able to hover this pseudo element, and have the other pseudo element appear.
.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;
}
<div class="wrap">
<input placeholder="input element" type="text" />
</div>
From the above snippet design, is there a way of making the :before
element change its opacity when i hover only the :after
element, and not the wrap
div itself (note: html cannot be changed, hence why this question)?
I tried using something like:
.wrap:not(input):hover:before{
after changing the width of the input to 90%
, but this didn't make a difference
解决方案
It seems the because pseudo elements are not 'real' elements, it means that the (currently) cannot be used in this way. Instead, using a 'real' element would allow for this, and so I have chosen to use a span element until this feature may or may not be implemented.
The current implementation displays:
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;
}
<input placeholder="input element" type="text" />
<span>?</span>
Much to the disappointment of my beloved pseudo element design.
这篇关于在悬停一个伪元素时,使另一个伪元素显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!