Html 使用 CSS 更改 TD Table/P 文本内的字体颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33945092/
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-29 18:34:01  来源:igfitidea点击:

Change font color inside TD Table / P text using CSS?

htmlcss

提问by Alexander Richard

I got problem to change font color inside td table. Because the pis auto generate PHP framework in my page.

我在 td 表中更改字体颜色时遇到问题。因为p是我页面中自动生成的 PHP 框架。

Here's sample of my html code.

这是我的 html 代码示例。

p {
    text-shadow: 2px 2px 5px red;
    font-size: 140%;
}

.gtext {
    color: blue;
    text-shadow: 2px 2px 5px blue;
    font-size: 140%;
}
<td class="gtext">
<p>Example of Font Color</p>
</td>

As you can see Phas own red color CSS, but I'm gonna change it to blue color, how to make it?

正如你所看到的P有自己的红色 CSS,但我要把它改成蓝色,如何制作?

Is there another way to change color inside of that TD tablewhich is Pinside?

有另一种方式给改色内TD表P里面?

Thanks in advance

提前致谢

回答by I am Cavic

I believe this would do it:

我相信这会做到:

.gtext > p {
    color: blue;
    text-shadow: 2px 2px 5px blue;
    font-size: 140%;
}

回答by Lidaranis

Have you tried this?

你试过这个吗?

.gtext p {
    color: blue;
    text-shadow: 2px 2px 5px blue;
    font-size: 140%;
}

回答by Gaurav Aggarwal

<table>
  <td class="gtext">
    <p>Example of Font Color</p>
  </td>
</table>

You are using <td>independently but it should come in <table>tag. No css change required just put <td>inside <table>

您正在<td>独立使用,但它应该带有<table>标签。无CSS变化所需要的只是把<td>里面<table>

回答by Suhail Keyjani

it work if td is inside tr and tr inside table,because html parser escape td if it out of table,may be your code doesnot generate table and tr

如果 td 在表内 tr 和 tr 内,它就可以工作,因为 html 解析器在 td 不在表内时会转义 td,可能是您的代码没有生成表和 tr

p {
    text-shadow: 2px 2px 5px red;
    font-size: 140%;
}

.gtext {
    color: blue;
    text-shadow: 2px 2px 5px blue;
    font-size: 140%;
}
<table>
<tr>
<td class="gtext">
<p>Example of Font Color</p>
</td>
</tr>
</table>


<!-----Without Table---->
<td class="gtext">
<p>Example of Font Color</p>
</td>