html - Figured borders for text input with css -


i need style text input input

the requiremets are:

  1. fluid width (stretches container width)
  2. border color changes on focus
  3. border color changes on error

is there simple way css?

what i've come quite complex, requires js , works not smoothly -

<div class="inpt"><input type="text" /></div>  jquery(".inpt").delegate("*", "focus blur", function() {     var elem = jquery(this);     var elem2 = jquery(this).parent();     settimeout(function() {         elem2.toggleclass("focused", elem.is(":focus"));     }, 0); }); 

http://jsfiddle.net/4skv9/

i had wrap input in div , style div using images on :before , :after
:active doesn't work div in case , had toggle class script.

i feel there must simple solution i'm missing. can suggest better?

this solution uses jquery detect focus on <input> , add/remove .focused class on parent container.

both left , right arrrows made of css 2 <span> elements , :before / :after.

the input responsive , adapts width of it's container.

fiddle

html :

<div class="inpt">      <span class="left arrow"></span>     <input type="text" />      <span class="right arrow"></span> </div> 

css :

.inpt {     position:relative;     margin:5%;     width:50%; } .left, .right {     position: absolute;     top:14px; } .right {     right:0; } .arrow:after, .arrow:before {     top: 50%;     border: solid transparent;     content:" ";     height: 0;     width: 0;     position: absolute;     pointer-events: none; } .arrow:after {     border-color: rgba(255, 255, 255, 0);     border-width: 12px;     margin-top: -12px; } .arrow:before {     border-color: rgba(220, 228, 228, 0);     border-width: 15px;     margin-top: -15px; } .left:after, .left:before {     right: 100%; } .left:after {     border-right-color: #fff; } .left:before {     border-right-color: #dce4e4; } .right:after, .right:before {     left: 100%; } .right:after {     border-left-color: #fff; } .right:before {     border-left-color: #dce4e4; } .focused input {     border-color: #afddda; } .focused .right:before {     border-left-color: #afddda; } .focused .left:before {     border-right-color: #afddda; } input {     border-top: 2px #dce4e4 solid;     border-bottom: 2px #dce4e4 solid;     border-left:none;     border-right:none;     padding:2px 10px 0px;     height: 29px;     display: block;     outline: 0;     width: 100%;     margin: 6px 0;     box-sizing:border-box; } 

jquery

$('input').focus(function () {     $(this).parent().addclass('focused'); });  $('input').blur(function () {     $(this).parent().removeclass('focused'); }); 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -