css - 取消垂直对齐属性

标签 css styles vertical-alignment

有没有办法取消或克服垂直对齐属性?

我有一个网站,其样式表包含以下 CSS:

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, 
blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, 
img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, 
center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, 
tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, 
figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, 
video {
    margin: 0;
    padding: 0;
    border: 0;
    vertical-align: baseline;
    background: transparent;
}

由于此样式属性,我在页面上插入了一个表格,其内容以一种奇怪的方式显示(这意味着如果我在 Chrome 开发人员工具中取消选中“vertical-align: baseline”,它会完全按照我的要求显示).

如何在我的页面上复制它?

谢谢!

最佳答案

这是一个有趣的问题,因为它涉及到浏览器的默认样式表。

如果您查看规范 (http://www.w3.org/TR/CSS21/sample.html) 中给出的默认样式表,您会看到以下内容:

thead, tbody,
tfoot           { vertical-align: middle }
td, th, tr      { vertical-align: inherit }

因此,默认行为是表格单元格的内容在表格单元格中垂直居中。

在您的样式表中,您将 vertical-align 属性设置为 baseline对于 tbody , tfoot , thead , tr , thtd影响您的表格布局的元素。

您需要调整重置 vertical-align 属性的 CSS 规则,或者根据需要为表格样式添加其他规则。

在您的示例中,您可以简单地在您的之后添加上面给出的两个规则 原始规则。

或者,从原始规则集中删除 vertical-align 属性。

更具体地说,按如下方式更改您的 CSS 样式表:

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, 
blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, 
img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, 
center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, 
tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, 
figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, 
video {
    margin: 0;
    padding: 0;
    border: 0;
    vertical-align: baseline;
    background: transparent;
}
thead, tbody, tfoot { vertical-align: middle } /* add this rule*/
td, th, tr { vertical-align: inherit } /* add this rule */

通过添加两个附加规则。

关于css - 取消垂直对齐属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28109062/

相关文章:

html - Chrome 中图像周围的边框颜色 : Is this a bug?

php - 在 h2 中呼应 php

java - 为什么我的组件超出了边界,请帮助我将其与必要的代码对齐

css - 在 IE7 中如何将文本垂直对齐到固定高度容器中的底部

javascript - 错误 : "Please use POST request" with Form and Javascript

javascript - 带有 jquery 的 CSS 标签

html - 下拉菜单定位

css - 带圆 Angular 的 div 边框

wpf - 在 WPF 中,如何为我的自定义控件提供在设计模式中使用的默认样式?

css - 如何使用 spacer div 对齐右下角图像周围的文本(在 Safari 中不起作用)?