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

Implementation steps for enabling docker remote service link on cloud centos

Here we introduce the centos server with docker i...

MySQL encoding utf8 and utf8mb4 utf8mb4_unicode_ci and utf8mb4_general_ci

Reference: MySQL character set summary utf8mb4 ha...

Use JavaScript to create page effects

11. Use JavaScript to create page effects 11.1 DO...

Detailed process of Vue front-end packaging

Table of contents 1. Add packaging command 2. Run...

A brief discussion on CSS cascading mechanism

Why does CSS have a cascading mechanism? Because ...

Detailed explanation of Promises in JavaScript

Table of contents Basic usage of Promise: 1. Crea...

MySQL 5.7.21 installation and configuration tutorial

The simple installation configuration of mysql5.7...

Vue-CLI3.x automatically deploys projects to the server

Table of contents Preface 1. Install scp2 2. Conf...

Detailed tutorial on installing and using Kong API Gateway with Docker

1 Introduction Kong is not a simple product. The ...

More elegant processing of dates in JavaScript based on Day.js

Table of contents Why use day.js Moment.js Day.js...

VMware configuration hadoop to achieve pseudo-distributed graphic tutorial

1. Experimental Environment serial number project...