The input box adapts automatically to the width

Source: Internet
Author: User
Keywords Web page production CSS Tutorials
Tags class content html set text type web web page

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:

&nbsp;&lt;&nbsp;! doctype&nbsp;html&gt;&nbsp;&lt;html&gt;&nbsp;&lt;head&gt;&nbsp;&lt;meta&nbsp;http-equiv= "Content-Type" &nbsp; Content= "Text/html;&nbsp;charset=utf-8" &gt;&nbsp;&lt;style&nbsp;type= "Text/css" &gt;&nbsp;h2&nbsp;{&nbsp;margin : 0;&nbsp;padding:10px&nbsp;0;&nbsp;font-size:14px;&nbsp; &nbsp;.mod-retweet&nbsp;{&nbsp;background: #E4EFF4; &nbsp;border:1px&nbsp;solid&nbsp; #A8D1E0; &nbsp;padding:3px&nbsp;5px&nbsp;5px;&nbsp;margin-top:5px;&nbsp;} &nbsp;.mod-retweet&nbsp;.mod-retweet-textarea&nbsp;{&nbsp;background-color:&nbsp; #FFFFFF; &nbsp;border:1px &nbsp;solid&nbsp; #64B2D1 &nbsp;margin-bottom:5px;&nbsp;overflow:hidden;&nbsp;padding:2px;&nbsp;position: RELATIVE;&NBSP;ZOOM:1&NBSP} &nbsp;.mod-retweet&nbsp;.mod-retweet-textarea&nbsp;textarea&nbsp;{padding:&nbsp;0; margin:&nbsp;0;&nbsp;border:0&nbsp;none;&nbsp;font-size:12px;&nbsp;height:80px;&nbsp;line-height:1.5em;&nbsp; WIDTH:100%;&NBSP;DISPLAY:BLOCK&NBSP} &nbsp;.mod-retweet&nbsp;.mod-retweet-textarea&nbsp;input&nbsp;{&nbsp; border:0&nbsp;NONE;&NBSP;FONT-SIZE:12PX;&NBSP;HEIGHT:20PX;&NBSP;LINE-HEIGHT:1.5EM;&NBSP;WIDTH:100%;&NBSP} &nbsp;&lt;/style &gt;&nbsp;&lt;title&gt; Analog width Adaptive input box &lt;/title&gt;&nbsp;&lt;/meta&gt;&lt;/head&gt;&nbsp;&nbsp;&lt;body&gt;&nbsp; &lt;h1&gt; Analog width Adaptive input box &lt;/h1&gt;&nbsp;&lt;div&nbsp;class= "Mod-retweet" &gt;&nbsp;&lt;h2&gt; Analog input Adaptive: &LT;/H2 &gt;&nbsp;&lt;div&nbsp;class= "Mod-retweet-textarea" &gt;&nbsp;&lt;input&nbsp;type= "text" &nbsp;name= "TextField" &nbsp;id= "TextField"/&gt;&nbsp;&lt;/div&gt;&nbsp;&lt;/div&gt;&nbsp;&lt;hr&nbsp;/&gt;&nbsp;&lt;div&nbsp;class= " Mod-retweet "&gt;&nbsp;&lt;h2&gt; analog textarea Adaptive: &lt;/h2&gt;&nbsp;&lt;div&nbsp;class=" Mod-retweet-textarea "&gt; &nbsp;&lt;textarea&nbsp;maxlength= "&nbsp;rows=" 5 "&nbsp;cols=" &nbsp;name= "Bookcontent" &gt;&lt;/textarea &gt;&nbsp;&lt;/div&gt;&nbsp;&lt;/div&gt;&nbsp;&lt;/body&gt;&nbsp;&lt;/html&gt;&nbsp;

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.