覆盖继承的CSS高度

时间:2009-08-14 19:31:40

标签: css layout html-table

我为表定义了一种样式。然后我有.tablestyle th { height:26px } ...

我现在需要在表格中有一个特定的(一个不是全部)自动确定其高度。

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

长的东西需要x的高度,其中x> 26px,但未知......我已经尝试在第一个标签上添加一个样式属性height:auto,但它似乎不尊重自动分配。如果我将height: 200px放在样式属性中,它可以正常工作,转到200px。问题是我真的需要根据th ...的内容确定高度。

我意识到我可以制作更具体的风格,我很好。我想尽可能简单地只装饰受影响的标签,而不是创建一个单独的样式。

其他信息:
这是一个表格数据输入表格,我们也同样需要td标签。

3 个答案:

答案 0 :(得分:3)

尝试在css属性的末尾添加!important

height: 500px !important;

答案 1 :(得分:0)

min-height: 26px; 

除IE之外的所有内容都可以使用。对于IE,我通常使用一些jQuery:

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

我想,我的代码没有摆在我面前。

答案 2 :(得分:0)

我意识到您的体验与我自己的体验不同,但通常表格单元格(<th><td>)将采用显示内容所需的任何高度,无论样式如何 - 与heightoverflow相关的规则。

您使用的是doctype吗?我通常在我的页面中使用<!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>中并使用它来强制执行特定的高度/宽度;但它确实会使你的标记复杂化。