【问题标题】:Why is my <p> fonts black?为什么我的 <p> 字体是黑色的?
【发布时间】:2017-09-18 14:42:34
【问题描述】:

我的段落是黑色的,即使我指定了一种(支持)颜色。
错误似乎在哪里?
我如何解决它?
谢谢!

HTML 代码:

<div id="welcome">
    <p>
    <center><b><em> AaBbCcDdEeFfGgHh</em></b></center>
    </p>
</div>

CSS 代码:

body {
    background: -webkit-linear-gradient(left,#2e4053,#212F3C);
    background: -o-linear-gradient(left,#2e4053,#212F3C);
    background: -moz-linear-gradient(left,#2e4053,#212F3C);
    background: linear-gradient(left,#2e4053,#212F3C);
    background-color:#2e4053;
}

p{
    font-family:Noto Sans Sinhala;
    src: url('Font/NotoSansSinhala-Regular.ttf');
    font-style:     ;
    font-size:50%;
    color:#f4f6f7 !important;
    font-weight:500;
}

【问题讨论】:

  • 为什么要使用“font-style: ;”?

标签: html css notepad++


【解决方案1】:

这是因为&lt;center&gt; 是块级元素。 &lt;p&gt;(段落)元素内不能有块级元素。这样做的原因是段落标记的细微替代语法不包括结束标记。您可以编写如下的段落标签并对其进行验证:

<p>This is a paragraph element that doesn't have a closing tag.
<p>Here's another.  This is all valid HTML.

此功能的定义可以在“文本/html 中的标记遗漏”部分下找到in the w3c documnetation。因此,通常当段落标签碰到块级元素时,它假定标签已关闭。你的 HTML 然后变成这样:

<div id="welcome">
    <p></p>
    <center><b><em> AaBbCcDdEeFfGgHh</em></b></center>
    <p></p>
</div>

如您所见,这意味着您的em 在技术上不在段落内。建议您改用text-align:center CSS 属性作为&lt;center&gt; is deprecated

body {
    background: -webkit-linear-gradient(left,#2e4053,#212F3C);
    background: -o-linear-gradient(left,#2e4053,#212F3C);
    background: -moz-linear-gradient(left,#2e4053,#212F3C);
    background: linear-gradient(left,#2e4053,#212F3C);
    background-color:#2e4053;
}

p{
    font-family:Noto Sans Sinhala;
    src: url('Font/NotoSansSinhala-Regular.ttf');
    font-style:     ;
    font-size:50%;
    text-align: center;
    color:#f4f6f7;
    font-weight:500;
}
<div id="welcome">
    <p>
        <b><em> AaBbCcDdEeFfGgHh</em></b>
    </p>
</div>

【讨论】:

  • 谢谢! CSS 样式规则有效。保持良好的工作! ???
【解决方案2】:

您可以通过 2 种方式做到这一点。 1.尝试删除 id=welcome。 要么 在 css 中调用 id=welcome 并指定(支持的)颜色。 HTML 代码:

<div>
    <p>
         <center><b><em> AaBbCcDdEeFfGgHh</em></b></center>
    </p>
</div>

CSS 代码:

body {
    background: -webkit-linear-gradient(left,#2e4053,#212F3C);
    background: -o-linear-gradient(left,#2e4053,#212F3C);
    background: -moz-linear-gradient(left,#2e4053,#212F3C);
    background: linear-gradient(left,#2e4053,#212F3C);
    background-color:#2e4053;

}

 p {
    font-family:Noto Sans Sinhala;
    src: url('Font/NotoSansSinhala-Regular.ttf');
    font-style:     ;
    font-size:50%;
    color:#f4f6f7 !important;
    font-weight:500;

【讨论】:

  • 在发布之前检查一个人的答案是个好主意,所以它可以工作......这不是
猜你喜欢
  • 2019-11-27
  • 2011-11-20
  • 2019-04-26
  • 2014-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
相关资源
最近更新 更多