代码之家  ›  专栏  ›  技术社区  ›  Bennett Dill

覆盖继承的CSS高度

  •  0
  • Bennett Dill  · 技术社区  · 15 年前

    .tablestyle th { height:26px } ...

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

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

    height:auto ,但它似乎不尊重自动分配。如果我把 height: 200px 在“样式”属性中,它可以正常工作,转到200px。问题是,我真的需要的高度来确定的基础上的内容的th。。。


    这是一个表格数据输入表单,我们同样需要td标签。

    3 回复  |  直到 8 年前
        1
  •  3
  •   Gregoire    12 年前

    height: 500px !important;
    
        2
  •  0
  •   MattBelanger    15 年前
    min-height: 26px; 
    

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

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

        3
  •  0
  •   David Thomas    15 年前

    我意识到你的经历与我不同,但通常是一个表格单元格(无论 <th> <td> )将采用显示内容所需的任何高度,而不考虑与内容相关的样式规则 height overflow .

    您正在使用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> 并使用它来强制执行特定的高度/宽度;但它确实会使标记变得有些复杂。