前提・実現したいこと
WordpressのContact form7にてお問い合わせフォームを作成中です。
それ自体はいいのですが、デザイン上でplaceholder内に必須マーク(※)があり、これの色だけが違うという状態で再現に手間取っています。
placeholderの色を一部だけ変えるというのがCSS上で無理だったため、jsにて挑戦中なのですがうまくいきません
解決策を模索して、擬似的にcssの疑似要素で「※」を入れていまして(label要素にrelativeを入れabsoluteで位置を調整しています。)
文字が入力されることでhissuクラスをとり、文字が入力されてない状態になるとまたhissuクラス付与、
入力ミス等で元の画面に戻された際、文字が入力済みの箇所があるとhissuクラスはとる
という挙動で考えています。
javascript
1 2$('.hissu').each(function () { 3var $this = $(this); 4$(this).find('.input').on('keypress', function () { 5 if ($(this).val()) { 6 $this.removeClass('.hissu'); 7 } 8 else { 9 $this.addClass('.hissu'); 10 } 11}); 12 if ($(this).val()) { 13 $this.removeClass('.hissu'); 14 } 15 else { 16 $this.addClass('.hissu'); 17 } 18});
css
1.hissu::before{ 2content: '※'; 3position:absolute; 4top: 5px; 5left: 45px; 6color: #3377EE; 7}
html
1<label class="hissu"><input type="text" id="namae" name="namae" value="" placeholder="お名前"></label>
どなたかご教授願えればと思います。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/21 09:33