溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

css中:focus-within怎么用

發(fā)布時間:2021-03-17 11:24:25 來源:億速云 閱讀:118 作者:清風 欄目:web開發(fā)

這篇文章主要為大家展示了css中:focus-within怎么用,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶大家一起來研究并學習一下“css中:focus-within怎么用”這篇文章吧。

這里我們用:focus-within玩一把

css中:focus-within怎么用

布局是這樣的

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

xPassword在沒點擊之前里面的“suo”這個圖是隱藏的

xPassword 同級屁股后的“r6m”此時是顯示的

當我們一點擊xPassword后同級第一張圖‘r6m’隱藏

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

同時xPassword里面的一張圖‘suo’的這個display為顯示!這時就成了你輸密碼我就裝作看不見

css中:focus-within怎么用

<div class="ctn">
   
  <div class="xPassword">
    <input  type="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;
    margin: 100px auto;
    height: 370px;
    padding: 20px;
    box-sizing: border-box;
    background: #fff;
    z-index: 10;
    box-shadow: 0 0 15px #cfcfcf;
    
}
.ctn h3 {
  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%;
}

//以上毫無價值,可以忽略,下方兩個才是重點



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

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

以上就是關于“css中:focus-within怎么用”的內容,如果改文章對你有所幫助并覺得寫得不錯,勞請分享給你的好友一起學習新知識,若想了解更多相關知識內容,請多多關注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI