On hovering one pseudo element, make the other pseudo element appear?

一世执手 提交于 2019-12-04 03:19:21

I know it's not exactly what you asked for but until css can select parents (it's comming) you could just add one more html element:

<div class="wrap">
    <div class="inner_wrap">
      <input placeholder="input element" type="text" />
    </div>
</div>

css:

.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;
}
.inner_wrap:before {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  height: 60px;
  width: 100%;
  background: tomato;
  opacity:0.2;
    display:none;
}
.wrap:hover .inner_wrap:before{
    display:block;
}
.wrap .inner_wrap:hover:before{
    display:none;
}

http://fiddle.jshell.net/0vwn1w9t/

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!