CSS <td style="中的元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19620682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:50:48  来源:igfitidea点击:

Elements inside <td style="

cssstyles

提问by Leandro Guedes

I'm trying to put the colspan, valignand alignin the following piece

我试图把colspan,valignalign在下面的一块

<td style="background-color:#000333" colspan="4" valign="middle" align="center">

<td style="background-color:#000333" colspan="4" valign="middle" align="center">

all inside the style="...", to have something like:

所有在style="...",里面都有类似的东西:

<td style="background-color:#000333;colspan:4;valign:'middle'; align:'center'>

<td style="background-color:#000333;colspan:4;valign:'middle'; align:'center'>

Is there any way to do this?

有没有办法做到这一点?

回答by v010dya

You will be unable to achieve colpan results with CSSI stand corrected, you can in CSS3. But text-align:centerwill get and vertical-align:middlefor vertical alignment.

您将无法使用 CSS 获得 colpan 结果我的立场更正了,你可以在 CSS3 中。但text-align:center会得到和vertical-align:middle垂直对齐。

With that said, please consider using proper CSS rather than stuffing things into the style tags, that will make your (and everybody else's) job much easier in the future. That is as simple as saying

话虽如此,请考虑使用适当的 CSS 而不是将东西塞进样式标签,这将使您(和其他所有人)的工作在未来变得更加轻松。就是这么简单

<td class='myclass'>

and then inside your CSS file

然后在你的 CSS 文件中

td.myclass
{
  text-align:center;
  vertical-align:middle;
}

回答by Jukka K. Korpela

You cannot do that because there is no way in CSS to do the job of colspan(except in a special case where its value equals the total number of columns, and even then only using a proposed CSS extension that does not work consistently across modern browsers, not to mention old browsers).

你不能这样做,因为在 CSS 中没有办法完成colspan(除非在它的值等于总列数的特殊情况下,即使这样也只能使用在现代浏览器中不能一致工作的建议的 CSS 扩展,更不用说旧浏览器了)。