2016-09-13 23 views
0

こんにちはスタックオーバーフロー!テキストの入力を重視した枠線の拡大

inputfocusの場合にこのborder-bottomを引き続き表示したいと思います。

.expand input { 
 
    padding: 10px; 
 
    border: none; 
 
    background: #eee; 
 
} 
 

 
.expand { 
 
    display: inline-block; 
 
} 
 

 
.expand:after { 
 
    display: block; 
 
    content: ""; 
 
    border-bottom: 3px solid #2bcf67; 
 
    transform: scaleX(0); 
 
    transition: transform 0.5s; 
 
    transform-origin: 0% 50%; 
 
} 
 

 
.expand:focus:after { 
 
    transform: scaleX(1); 
 
}
<div class="expand" tabindex="0"> 
 
    <input type="text" name="" id="" placeholder="Your text"> 
 
    Click here 
 
</div> 
 

 
<p>I would like to have same effect but clicking on text input</p>

+1

あなたがすることはできません、親セレクタを必要としますこれはCSSにはないものです。汚れた修正が必要です。 – Roberrrt

+0

@mdm純粋なCSSでは不可能な周囲のdivはありません(擬似要素も* input *で使用できないため)。しかし、それはjQueryで実現することができます。 –

答えて

1

<input>要素がpseudoelementsを持つことはできませんが、あなたはあなたのための境界線であることをダミー<div>要素を使用することができます。http://jsfiddle.net/QrrpB/2492/

.expand input { 
 
    background: #eee; 
 
    padding: 10px; 
 
    border: none; 
 
} 
 

 
.expand { 
 
    display: inline-block; 
 
    position: relative; 
 
} 
 

 
.border { 
 
    display: block; 
 
    position: absolute; 
 
    height: 3px; 
 
    width: 100%; 
 
    top: 100%; 
 
    background: #2bcf67; 
 
    transform: scaleX(0); 
 
    transition: transform 0.5s; 
 
    transform-origin: 0% 50%; 
 
} 
 

 
input:focus + .border, .expand:focus .border { 
 
    transform: scaleX(1); 
 
}
<div class="expand" tabindex="0"> 
 
    <input type="text" name="" id="" placeholder="Your text"> 
 
    <div class="border"></div> 
 
    click 
 
</div>

1

Pseudo-elementsのみcontainer要素でサポートされています。それらがレンダリングされる方法は、子要素としてコンテナ自体の中にあるためです。 inputは他の要素を含むことができないため、サポートされていません。ここで

はdiv要素を拡大 内のすべてのinputをラップするので

0

を擬似要素をだからではなく、使用方法についてW3C specificationで、jQueryがないこと、今、ここにあなたのために:http://jsfiddle.net/QrrpB/2467/

シモンズ:私はあなたが望んでいたことを正しく理解していますように。

+0

私はこの 'border-bottom'を、' input'が 'focus'になる時に見えるようにしたいと思います。 'div'を使っていても。申し訳ありませんが私はこれを明確に説明していない場合:) – rndm

+0

あなたは、**ホバリングとフォーカス**の両方で、または**フォーカス**だけで効果をしたいですか? –

+0

**フォーカス**のみ – rndm

関連する問題