2012-10-27 108 views
0

我試過下面的HTML代碼。HTML div寬度和文本框寬度不相等

但無法理解爲什麼文本框和div寬度不一樣大小。

這是我試過的。

<style> 
.test 
{ 
    border:1px solid red;width:100px;height:30px;padding:3px; 
} 
</style> 

<div class="test">div</div> 
<input type="text" value="text box" class="test" /> 

下面我介紹了firefox。

enter image description here

+2

http://jsfiddle.net/c4tQB/他們不一樣嗎? – kritya

+0

但在Firefox中看到的差異。請問我可以知道 –

+0

某些瀏覽器會添加額外的填充和邊距,所以請使用重置 '* {margin:0;填充:0; }' – twodayslate

回答

0

它在FF,IE,鉻罰款。除去padding:3px;

代碼這樣的事情後嘗試:

<style> 
    .test 
    { 
     border:1px solid red;width:100px;height:30px; 
    } 
</style> 

讓我知道它會幫助你或不?

+0

更好地設置填充爲零。輸入通常默認擁有自己的填充 – bukart