css - 在表格单元格内使用 DIV

标签 css html

this table ,不仅单元格 B 有标题和内容,单元格 A 和 C 也有。

enter image description here

我使用 DIV 设置标题和内容的尝试只取得了部分成功。观察到 font-weight,但没有观察到 vertical-align。为什么?

CSS

<style type="text/css">
    td {
        text-align: left;
    }
    .heading {
        vertical-align: top;
        font-weight: bold
    }
    .content {
        vertical-align: middle;
    }
</style>

HTML

<table width="300px" height="300px" border="1">
    <tr>
        <td rowspan="2">A</td>
        <td>
            <div class="heading">Heading of Cell B</div>
            <div class="content">Content of Cell B</div>
        </td>
    </tr>
    <tr>
        <td>C</td>
    </tr>
</table>

最佳答案

垂直对齐应居中

 verticle-align: middle;

这会将文本放在中间。虽然你必须知道它是放在行的中间(而不是容器)所以你需要一个行高

 line-height: xxx;

或者使用 div 并模拟表格:http://jsfiddle.net/rf2kC/

关于css - 在表格单元格内使用 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20499906/

相关文章:

php - 如何正确地将自定义样式应用于现有的 wordpress 菜单

html - 将鼠标悬停在 span 上以获取工具提示 div

python - 如何增加 flask 形式的 bool 字段的大小?

javascript - 在 jQuery 中引用 CSS 属性

html - 防止可折叠导航栏包裹在图像下?

css - Nodejs - Stylus 没有从 'styl' 文件创建 css 文件

css - 如何将我的 div float 在我的内容的最底部

html - 文字居中的框覆盖

html - 更改 HTML 中的换行符

javascript - 如何通过使用 javascript 获取类名来更改 HTML 样式(不允许使用 jQuery)?