実現したいこと
https://codepen.io/takeradi/pen/mPyYeq
こちらのcodepenのような動きにしたいと考えています
labelの箇所がうまく動いてくれないのが現状です
HTML
1<p class="text-input"> 2 <label class="test" for="input1">Name</label> 3 <input type="text" name="log" placeholder="名前を入力" id="input1" autocomplete="username" value="" size="20" /> 4</p>
css
1.text-input { 2 position: relative; 3 margin-top: 50px; 4} 5#input1 { 6 display: inline-block; 7 width: 500px; 8 height: 40px; 9 box-sizing: border-box; 10 outline: none; 11 border: 1px solid lightgray; 12 border-radius: 3px; 13 padding: 10px 10px 10px 100px; 14 transition: all 0.1s ease-out; 15} 16 17#input1 + .test { 18 position: absolute; 19 top: 0; 20 left: 0; 21 bottom: 0; 22 height: 40px; 23 line-height: 40px; 24 color: white; 25 border-radius: 3px 0 0 3px; 26 padding: 0 20px; 27 background: #E03616; 28 transform: translateZ(0) translateX(0); 29 transition: all 0.3s ease-in; 30 transition-delay: 0.2s; 31} 32 33#input1:focus + .test { 34 transform: translateY(-120%) translateX(0%); 35 border-radius: 3px; 36 transition: all 0.1s ease-out; 37}
やったこと
検証ツールで下記のcssのコードが機能してなさそうなのが原因だと思いました。
しかしどうやっても動かない状況です
codepenのように
.test→labelに変更しても動かないです
css
1#input1 + .test { 2 position: absolute; 3 top: 0; 4 left: 0; 5 bottom: 0; 6 height: 40px; 7 line-height: 40px; 8 color: white; 9 border-radius: 3px 0 0 3px; 10 padding: 0 20px; 11 background: #E03616; 12 transform: translateZ(0) translateX(0); 13 transition: all 0.3s ease-in; 14 transition-delay: 0.2s; 15} 16 17#input1:focus + .test { 18 transform: translateY(-120%) translateX(0%); 19 border-radius: 3px; 20 transition: all 0.1s ease-out; 21}
どなたか教えていただけますと幸いです。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/30 07:52