第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

CSS 效果在 React 應(yīng)用程序中不起作用

CSS 效果在 React 應(yīng)用程序中不起作用

桃花長(zhǎng)相依 2023-10-17 15:55:58
我在反應(yīng)應(yīng)用程序中實(shí)現(xiàn)了一個(gè)表單,它有兩個(gè)字段,一個(gè)用于用戶名,一個(gè)用于密碼。兩者的文本字段上都有標(biāo)簽。一旦用戶單擊文本字段,標(biāo)簽就會(huì)向上移動(dòng)一點(diǎn),并且尺寸也會(huì)減小并改變顏色。我已經(jīng)有一個(gè) HTML 和 css 模型,它工作正常,但是一旦我在 React 應(yīng)用程序中實(shí)現(xiàn)它,它就不起作用,并且顏色已經(jīng)更改,而無(wú)需單擊文本字段h1 {  color: white;  text-shadow: 1px 1px 2px black, 0 0 25px blue, 0 0 5px darkblue;  font-size: 60px;  text-align: center;}.box {   position: absolute;   top: 50%;   left: 50%;   transform: translate(-50%, -50%);   width: 500px;   padding: 40px;   background: rgba(0,0,0,.7);   box-sizing: border-box;   box-shadow: 0 15px 25px rgba(0,0,0, .5);   border-radius: 10px;}.box h2  {   margin: 0 0 0px;   padding: 0;   color: white;   text-align: center;  } .box .inputBox{    position: relative;  } .box .inputBox input{    width: 100%;    padding: 10px 0;    font-size: 16px;    color: white;    margin-bottom: 30px;    border: none;    border-bottom: 1px solid white;    outline: none;    background: transparent; }  .box .inputBox label{     position: absolute;     top: 0;     left: 0;     padding: 10px 0;     font-size: 16px;     color: white;     pointer-events: none;     transition: .5s;    }.box .inputBox input:focus ~ label, //this is the code for the special effects.box .inputBox input:valid ~ label  {    top: -18px;    left: 0;    color: #5100c9;    font-size: 12px;  }.box input[type="submit"]{    background: transparent;    border: none;    outline: none;    color: white;    background: #5100c9;    padding: 10px 20px;    cursor: pointer;    border-radius: 5px;  }   .box input[type="submit"]:hover{       font-weight: bold;     }
查看完整描述

1 回答

?
料青山看我應(yīng)如是

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊

我制作了一個(gè)codepen來(lái)測(cè)試這一點(diǎn),并且可以看到 css 中的這一行導(dǎo)致了問(wèn)題:

.box?.inputBox?input:focus?~?label,
.box?.inputBox?input:valid?~?label

該行中的第二個(gè)選擇器 (?.box .inputBox input:valid ~ label) 始終為 true,因?yàn)?/p>

:valid選擇器僅適用于有限制的表單元素,例如具有 min 和 max 屬性的輸入元素、具有合法電子郵件的電子郵件字段或具有數(shù)值的數(shù)字字段等。

這會(huì)導(dǎo)致label無(wú)論焦點(diǎn)與否,總是向上滑動(dòng)并變成藍(lán)色。

我只是, .box .inputBox input:valid ~ label?從你的 css 中刪除,如 codepen 中所示。

您的下一個(gè)挑戰(zhàn)將是label當(dāng)輸入失去焦點(diǎn)時(shí)防止移動(dòng)回其原始位置。我認(rèn)為這就是您試圖通過(guò)我刪除的行來(lái)完成的任務(wù),但這不是答案。


查看完整回答
反對(duì) 回復(fù) 2023-10-17
  • 1 回答
  • 0 關(guān)注
  • 165 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)