A brief discussion on the fun of :focus-within in CSS

A brief discussion on the fun of :focus-within in CSS

I believe some people have seen this picture of covering their eyes when entering the password on B station

Here we use :focus-within to play a bit

The layout is like this

There is a ctn outside which can be ignored, it is just a fixed position in the center

The "suo" icon in xPassword is hidden before clicking on it.

The "r6m" after the xPassword is displayed at this time

When we click xPassword, the first image of the same level 'r6m' is hidden

:focus-within ~ img的~ 這個符號是同級屁股后第一個的意思

At the same time, a picture of 'suo' in xPassword is displayed! At this time, you enter the password and I pretend not to see it.

<div class="ctn">
   
  <div class="xPassword">
    <input type="password" placeholder="Please enter your password" class="input">
    <img src="http://suo.im/5UnnjN" alt=""> 
  </div>
    
  <img src="http://r6m.cn/csAC" alt=""> 
    
</div>
.ctn {
     position: relative;
    width: 318px;
    margin: 100px auto;
    height: 370px;
    padding: 20px;
    box-sizing: border-box;
    background: #fff;
    z-index: 10;
    box-shadow: 0 0 15px #cfcfcf;
    
}
.ctn h2 {
  font-size: 20px;
  font-weight: bold;
  margin-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%;
}

//The above are worthless and can be ignored. The following two are the key points. xPassword:focus-within ~ img {
  display: none;
}

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

This is the end of this article about the fun of :focus-within in CSS. For more relevant CSS :focus-within content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope that everyone will support 123WORDPRESS.COM in the future!

<<:  Solution to the problem that Xshell cannot connect to the virtualBox virtual machine

>>:  Introduction to TypeScript interfaces

Recommend

How to modify the location of data files in CentOS6.7 mysql5.6.33

Problem: The partition where MySQL stores data fi...

Detailed explanation of Mysql self-join query example

This article describes the Mysql self-join query....

Mac installation mysqlclient process analysis

Try installing via pip in a virtual environment: ...

Tutorial on installing PHP on centos via yum

First, let me introduce how to install PHP on Cen...

MySQL 5.7.23 decompression version installation tutorial with pictures and text

It is too troublesome to find the installation tu...

Graphic tutorial on installing Ubuntu 18.04 on VMware 15 virtual machine

In the past few years, I have been moving back an...

ThingJS particle effects to achieve rain and snow effects with one click

Table of contents 1. Particle Effects 2. Load the...

How to create LVM for XFS file system in Ubuntu

Preface lvm (Logical Volume Manager) logical volu...

Detailed explanation of basic data types in mysql8.0.19

mysql basic data types Overview of common MySQL d...

Summary of uncommon js operation operators

Table of contents 2. Comma operator 3. JavaScript...

MySQL 5.7.16 ZIP package installation and configuration tutorial

This article shares the installation and configur...

How to modify the default storage location of Docker images (solution)

Due to the initial partitioning of the system, th...