2015-09-04 23 views
0

如果td包含輸入,則顯示瀏覽器強制最小高度爲19px。A​​包含<input>具有不想要的最小高度

input{ 
    height: 1px; 

} 
td{ 
    border: 1px solid red; 
    height: 1px; 
} 

<table> 
    <tr> 
    <td><input type = "text" /></td> 
    </tr> 
</table> 

看到這裏演示: http://jsfiddle.net/Rs2eT/160/

我的問題是:

  1. 爲什麼TD高度被迫19px?

  2. 如何強制更小的td高度?

謝謝。

+0

在哪個瀏覽器中嘗試?因爲它對我來說顯得很好... –

回答

0

你行高,默認情況下隱含的單元格填充。見琴:http://jsfiddle.net/Rs2eT/161/

input{ 
 
    height: 1px; 
 
    
 
} 
 
td{ 
 
    border: 1px solid red; 
 
    height: 1px; 
 
    padding:0; /*there is padding that isn't specified in the declaration*/ 
 
    line-height:1px; /*td presumes line height of 1em on all contents */ 
 
}
<table> 
 
    <tr> 
 
     <td><input type = "text" /></td> 
 
    </tr> 
 
</table>

0

您是否嘗試過line-height

input{ 
    height: 1px; 

} 
td{ 
    border: 1px solid red; 
    height: 1px; 
    line-height: 1px; 
} 
-1
input{ 
    height:19px; 
    display:block; 
    border:none; 
} 
+0

@Seb正在尋求一種讓TD更短的方法。抱怨是,包含輸入的TD的*表觀*最小高度是19px。 –

+0

「19px的最小高度」不會更短 –

+0

他們希望它更短。 「**瀏覽器的最小高度爲19px **」的意思是「**我不希望我的元素高19px,但我似乎無法使它縮短**」。如果您閱讀OP的後續問題「**爲什麼td高度被強制爲19px?**」和「**如何強制td的較小高度**」,您可以看出他們的高度較小在之後。 –

0

的line-height:1px的

應該解決您的問題。瀏覽器有默認的行高。

相關問題