Long time ago saw Ytzong's "width of the adaptive input box" This article, feeling very good, very detailed, Yui grid decision width, the content decision height is indeed very practical.
Personally think that this method of Ytzong has two points very troublesome:
<b><b><input type= "text" ></b></b> need to set 2 layer B label;
• Formula:. Fluid-input-inner{padding-right: Input box left box + input box right border + input box left padding + input box right padding} also very troublesome often forget.
Some time ago in a project really useful to, colleagues peck Rice bird simulation of an adaptive width of the input box, the principle and ytzong is roughly the same, but solved the above two points of trouble. There are, of course, inadequacies.
Look at the code:
< ! doctype html> <html> <head> <meta http-equiv= "Content-Type" Content= "Text/html; charset=utf-8" > <style type= "Text/css" > h2 { margin : 0; padding:10px 0; font-size:14px; .mod-retweet { background: #E4EFF4; border:1px solid #A8D1E0; padding:3px 5px 5px; margin-top:5px; } .mod-retweet .mod-retweet-textarea { background-color: #FFFFFF; border:1px solid #64B2D1 margin-bottom:5px; overflow:hidden; padding:2px; position: RELATIVE;&NBSP;ZOOM:1&NBSP} .mod-retweet .mod-retweet-textarea textarea {padding: 0; margin: 0; border:0 none; font-size:12px; height:80px; line-height:1.5em; WIDTH:100%;&NBSP;DISPLAY:BLOCK&NBSP} .mod-retweet .mod-retweet-textarea input { border:0 NONE;&NBSP;FONT-SIZE:12PX;&NBSP;HEIGHT:20PX;&NBSP;LINE-HEIGHT:1.5EM;&NBSP;WIDTH:100%;&NBSP} </style > <title> Analog width Adaptive input box </title> </meta></head> <body> <h1> Analog width Adaptive input box </h1> <div class= "Mod-retweet" > <h2> Analog input Adaptive: </H2 > <div class= "Mod-retweet-textarea" > <input type= "text" name= "TextField" id= "TextField"/> </div> </div> <hr /> <div class= " Mod-retweet "> <h2> analog textarea Adaptive: </h2> <div class=" Mod-retweet-textarea "> <textarea maxlength= " rows=" 5 " cols=" name= "Bookcontent" ></textarea > </div> </div> </body> </html>
The
can find a nasty place to be:
The border of the textarea and input text entry boxes is simulated with the border of the container that is nested in its outer layer, and the border of the textarea and input text input box border:0 none. So webkit the input box focus, the border of the input frame inside the simulation frame, a little uncomfortable experience.
• It is also worth noting that the padding and margin of textarea must be reset to 0, otherwise there will be small bugs in WebKit and opera.