好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

浅谈css当中:focus-within的好玩之处

相信有些人看到过这个B站输入密码就遮 眼睛 的这个图

这里我们用:focus-w IT hin玩一把

布局是这样的

外面有一个ctn 可以忽略,就是一个居中固定位置而已

xp assword在没点击之前里面的[suo]这个图是隐藏的

xPassword 同级屁股后的[r6m]此时是显示的

当我们 一点 击xPassword后同级 第一张 图‘r6m’隐藏

:focus-within ~ img 的 ~ 这个符号是同级屁股后第一个的 意思

同时xPassword里面的一张图‘suo’的这个dis play 为显示!这时就成了你输密码我就装作看不见

<div class="ctn">
   
  <div class="xPassword">
    <input  ty PE ="password" placeholder="请输入密码" class="input">
    <img src="http://suo.im/5UnnjN" alt=""> 
  </div>
    
  <img src="http://r6m.cn/csAC" alt=""> 
    
</div>

.ctn {
     position: relative;
    width: 318px;
    m arg in: 100px auto;
    h ei ght: 370px;
    padding: 20px;
    box -s izing: border-box;
    background:  # fff;
    z -i ndex: 10;
    box-shadow: 0 0 15px #c fc f CF ;
    
}
.ctn h2 {
  font- Size:  20px;
   font-weight : bold;
  mar gin -bottom: 30px;
}
.ctn input {
  padding: 10px;
  width: 100%;
  border: 1px solid #e9e9e9;
  border-radius: 2px;
  outline: none;
  box-sizing: border-box;
  font-size: 16px;
}
img {
    position: absolute;
    top: -23%;
    left: 50%;
    width: 80px;
    height: auto;
    transform: translate(-50%, 0);
}

.xPassword img {
  display: none;
  width: 103px;
  height: auto;
  top: -26%;
}

//以上毫无 价值 ,可以忽略,下方两个才是重点



.xPassword:focus-within ~ img {
  display: none;
}

.xPassword:focus-within img {
  display: block;
}

到此这篇关于 浅谈 css当中:focus-within的好玩之处的 文章 就介绍到这了,更多相关css :focus-within内容请搜索以前的文章或继续浏览下面的相关文章,希望大家以后多多支持!

总结

以上是 为你收集整理的 浅谈css当中:focus-within的好玩之处 全部内容,希望文章能够帮你解决 浅谈css当中:focus-within的好玩之处 所遇到的问题。

如果觉得 网站内容还不错, 推荐好友。

查看更多关于浅谈css当中:focus-within的好玩之处的详细内容...

  阅读:16次