我想打一個表格單元格內的一個簡單的搜索方式:爲什麼按鈕(以及圖像)傾向於在文本行下潛入?
<td style="vertical-align: center">
<div id="search">
<form action="search" method="get">
Search:
<input type="text" value="enter something" class="autoempty" />
<button type="submit"></button>
</form>
</div>
</td>
按鈕應該有一個搜索圖標,使用這個CSS:
div#search button {
/*reset the normal button behavior*/
padding: 0px;
border-width: 0px;
border-style: none;
background-color: transparent;
/*Make it square*/
width: 30px;
height: 30px;
/*set background*/
background-image: url("../images/search_grey.png");
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
/*fancy cursor*/
cursor: pointer;
}
這是什麼樣子:
顏色顯示由Firebug顯示的元素尺寸。淺藍色是<td>
元素。
我希望vertical-align
屬性可以修復它,但它沒有。我在將<img>
標籤添加到文本時也遇到同樣的問題。
由於圖像的高度超過了搜索領域的高度 - 因此使其膨脹。 –