2009-08-14 112 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>包裹细胞内容物并用它来执行特定的高度/宽度;但它确实有点让你的标记复杂化。