2009-08-14 117 views
0

我有一個爲表格定義的樣式。然後我有一個.tablestyle th { height:26px } ...覆蓋繼承的CSS高度

我現在有一個需要有一個特定的(一個並非所有)在表中自動確定其高度。

<table class="tablestyle"> 
<tr><th>Normal Stuff</th></tr> 
<tr><th>Long Stuff</th></tr> 
</table> 

長了東西屆需要X,高度,其中x> 26px,但未知...我已經試過將一個樣式屬性個標籤說height:auto,但它似乎沒有榮譽不自動分配。如果我將height: 200px放在style屬性中,它可以正常工作,達到200px。問題是,我真的需要的高度來決定根據內容的第...

我意識到,我可以做出更具體的風格,我很好。我希望如果可能的話,只是簡單地修飾受影響的標籤,而不是創建單獨的樣式。

附加信息:
這是針對表格數據輸入表單的,我們對td標籤也有同樣的需求。

回答

3

嘗試添加!重要在你的CSS屬性

height: 500px !important; 
0
min-height: 26px; 

年底將工作的一切,但IE瀏覽器。對於IE,我通常使用一些jQuery:

if ($('stuff').height() < 26) { $('stuff').height(26); } 

我想,我沒有我的代碼在我面前。

0

我知道你的經歷是我自己的不同,但通常一個表單元格(無論<th><td>)將採取什麼高度需要顯示的內容,不管涉及heightoverflow樣式規則。

您使用的是文檔類型?我通常在我的頁面中使用<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">,並且演示頁面(在this page處)似乎支持這一點。

那裏使用的標記下面的頁面:

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 

<head> 
    <title></title> 
    <link rel="stylesheet" type="text/css" href="css/stylesheet.css" /> 

    <style type="text/css" media="all"> 

table {width: 80%; 
    margin: 1em auto; 
    } 

    tr,th,td 
     {height: 40px; 
     } 

    th, td {border: 1px solid #f90; 
     } 

    </style> 

</head> 

<body> 

<table> 

<thead> 
<tr><th>Names</th><th>Description</th><th>Actor</th></tr> 
</thead> 

<tbody> 
<tr><td>Number One</td><td>The assumed leader of the Village</td><td>Perhaps Patrick McGoohan</td></tr> 
<tr><td>Number Two</td><td>There are two Number Twos with repeat appearances: Leo McKern appeared in three episodes, and Colin Gordon in two. With the exception of "Fall Out", this was the result of the actors performing their roles in two consecutive episodes filmed back to back. Colin Gordon was filmed in "The General" followed immediately with "A. B. and C." McKern was featured in the series' second transmitted episode, "The Chimes of Big Ben," and then featured in the next production episode to be filmed "Once Upon a Time." Three actors who portray Number Twos also appear in other episodes, possibly as different characters — Georgina Cookson ("A. B. and C." as party guest and "Many Happy Returns" as Mrs Butterworth/No. 2), Kenneth Griffith ("The Girl Who Was Death" as Schnipps/No. 2 and "Fall Out" as The Judge) and Patrick Cargill ("Many Happy Returns" as Thorpe, and "Hammer Into Anvil" as No. 2) — although this is ambiguous, particularly in the case of Kenneth Griffith's character.</td><td>Patrick McGoohan</td></tr> 
</tbody> 

</table> 

</body> 

</html> 

可以想象,可以在一個<span>包裹細胞內容物並用它來執行特定的高度/寬度;但它確實有點讓你的標記複雜化。