<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[[实践OK]input type=text 如何使得输入文字垂直居中，两头居中。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Sat, 22 Nov 2014 04:41:43 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	这个问题困扰了好久，昨天到网上查了很多资料，介绍了两种办法<br/>1：设置input的height和line-height，line-height比height稍小一些，但这种方式只在IE中生效，FireFox中文字仍然是<br/>&nbsp;&nbsp;&nbsp;&nbsp;顶部显示的<br/><br/>2：设置input的padding-top，padding-top=(height-line-height)/2,这种方法勉强可以是的文字想居中 位置靠近，但padding-top的值的慢慢的调节，调节了很久发现文字终于居中了，结果文本框的高度也变大了，一个很大的文本框看其来总有点不协调，请问大家是怎么调节&lt;input type=&quot;text&quot;&gt;使得文字居中的（&nbsp;&nbsp;vertical-align:middle 也试过，但是没有效果）<br/><br/>3:请问Dreamweaver中有没有专门用于显示文字的标签呢，就像asp.net中的label一样的，在表单中经常会看到&nbsp;&nbsp;“用户名：”+文本框&nbsp;&nbsp;，怎么让“用户名：”和后面的文本框垂直居中呢<br/><br/>欢迎各位高手指导，最好能亲手调试过在回答，能答多少就答多少，言之有理即可得分<br/><br/><br/>一、&lt;input type=&quot;text&quot; class=&quot;xxx&quot;&gt;<br/>.xxx &#123;text-align:center&#125;<br/><br/>实践证明确实能让文字在长的text文本框中居中：<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;input type=&quot;text&quot; class=&quot;search-field&quot; name=&quot;keyword&quot; style=&quot;width: 56%;padding-left:10px;&quot; value=&quot;∷∷∷∷∷∷∷ 自定义搜索 ∷∷∷∷∷∷∷&quot; onblur=&quot;if(this.value==&#039;&#039;) this.value=&#039;∷∷∷∷∷∷∷ 自定义搜索 ∷∷∷∷∷∷∷&#039;;&quot; onfocus=&quot;if(this.value==&#039;∷∷∷∷∷∷∷ 自定义搜索 ∷∷∷∷∷∷∷&#039;) this.value=&#039;&#039;;&quot; id=&quot;keyword&quot;&gt;

#keyword &#123;
&nbsp;&nbsp;&nbsp;&nbsp;text-align: center;
&nbsp;&nbsp;&nbsp;&nbsp;width: 52%;
&#125;
</textarea><br/>二、楼主你可以转换下思路<br/>文档类型用标准的<br/>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br/>input的高 font-size line-height 你都给他成一样的像素<br/>再给input加 相同像素的padding top bottom<br/>我就不信他不垂直居中<br/>没有实践这块，主要是找第一的这种情况。<br/>三、设置height 和 padding-top<br/>本人亲测 只有ie5.5不支持<br/>ie 6 7 8&nbsp;&nbsp;ff 3都行<br/>可是楼上的加上 padding-top 后，好好的input被撑的很大，不是预期的效果。。&nbsp;&nbsp;不太可取。。<br/><br/>四、height:20px;line-height:20px;<br/>input &#123; solid #999;height:22px; background:#ffffff; line-height:22px; margin:0px; padding:0px;/*表单输入框内文字居中*/ vertical-align:middle;/*表单控件上下居中对齐*/&#125;<br/><br/>五、先用切图工具测量出文字距离input上边框的高，然后设置input的height和padding-top,相应的再把input的高减去所设置的padding-top值。这样就不会使得input的高增大，注意input的高设置的高要比测量的input的高小5-6px。<br/><br/><br/>六、将 input 的height 与行高line-height设置相同的值就可以了<br/><br/>摘录自：http://bbs.csdn.net/topics/320085516<br/><br/><br/>[讨论] input文本输入框的文字居中处理：<br/><br/>考虑到有些人会把文本输入框文字居中兼容性问题忽略掉，做了代码如下，搞了一些分析：<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;input测试&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
/*reset.css*/
body&#123;width:960px;margin:10px auto;padding:0;font:12px/1.5 Arial, Helvetica, sans-serif;&#125;
input &#123; padding:0; &#125;
/***---测试高度解析，文本居中差异以及提示输入线差异---***/
.gb_sear input &#123; font:16px &quot;宋体&quot;, arial; /*font:16px arial;*/ height:28px; line-height:28px&#92;9; _line-height:29px; width:14em; padding-left:4px; border:1px solid #ace; overflow:hidden; outline:none; &#125;
.gb_sear label &#123; display:inline-block; position:relative; top:2px; *top:-4px;
&#125;
/***---无关测试样式---***/
h1&#123;padding:10px 0;font-size:14x;color:#f60;margin:0 0 20px 0;line-height:1.5;border-bottom:1px dashed #999;&#125;
.test,.test_result&#123;border:1px solid #666;padding:10px;margin-top:10px;&#125;
.test_result li&#123;line-height:1.7;color:#800000;&#125;
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;test&quot;&gt;
&nbsp;&nbsp;&lt;h1&gt;input文本居中测试&lt;/h1&gt;
&nbsp;&nbsp;&lt;div class=&quot;gb_sear&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;label for=&quot;search&quot;&gt;请输入搜索关键字:&lt;/label&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type=&quot;text&quot; id=&quot;search&quot;/&gt;
&nbsp;&nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;test_result&quot;&gt;
&nbsp;&nbsp;&lt;h1&gt;测试结论&lt;/h1&gt;
&nbsp;&nbsp;&lt;ul&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&quot;宋体&quot;在行高的表现上，浏览器解析效果相当一致，除了那傻逼的IE6，用在表单文本输入框上亦是如此。使用arial则会出现兼容问题。&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;非IE的标准浏览器，在对input文本输入框中的文字进行居中时，不必设置line-height。而chrome浏览器在遇到line-height声明时还会产生难看的输入提示线（位置和高度都不好看）。&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;无论字体设置多大，使用什么字体族，IE6文本居中都会“出错”。一个好的解决方法是，对于IE6，把通用的line-height值增加一个像素，居中效果就相当完美了。&lt;/li&gt;
&nbsp;&nbsp;&lt;/ul&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</textarea><br/><br/><br/>我在chrome下测试 并不是居中的。<br/>不会吧，我测试用的是chrome 12.0版本，没有问题。<br/>你能给个截图不？，千万别说上下行空白只差一个像素，那不是问题。<br/>如果差两个的话，那就是问题了。<br/><br/>建议在input标签的时候用line-height加padding来实现高度，不要固定死height，否则比较麻烦<br/><br/><br/>如果你加了line-height，那么在谷歌浏览器下，输入框提示线很丑的。<br/>另外，不定高度， ，没必要这么去考虑吧，这里可以给死，改动改这里没必要。<br/>刚才试了下，不写死height，font-size+padding-top+padding-bottom=height这样还可以，就是ie8下，开始的 ...<br/><br/>在chrome浏览器下，回复都不关闭窗口，也没有任何提示都不知道能不能发了，只好用firefox啦，哎……<br/><br/>摘处：http://bbs.blueidea.com/thread-3033907-1-1.html
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践OK]input type=text 如何使得输入文字垂直居中，两头居中。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>