首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >属性在嵌套段落元素中不起作用。

属性在嵌套段落元素中不起作用。
EN

Stack Overflow用户
提问于 2015-10-11 04:05:09
回答 2查看 362关注 0票数 0

在下面的html代码中,段落(p)元素的颜色不随css的颜色属性而改变,*

,但是如果我用div元素替换p,它是正常工作的..

代码语言:javascript
运行
复制
enter code here

如何在Ubuntu14.04中安装Node.js和npm工具

如何在Ubuntu14.04中安装Node.js和npm工具

代码语言:javascript
运行
复制
<div>
    <h2>
        Introduction:
    </h2>
    <p style="color:red;">
    <h3>Node.js</h3>
    &nbsp;  &nbsp;  &nbsp;
    Nodejs is an open source , cross platform , JavaScript runtime environment  which is based on  <a href="https://developers.google.com/v8/"> Chrome's V8 JavaScript engine</a>.
    <br>
    Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.<br><br>

    It is used to develop scalable, real-time , network and server-side applications written in javascript and we can run that applications within Node.js runtime environment  on Mac OS X ,Windows ,Linux ,solaris and BSD.<br><br>

    Node.js provides an event-driven architecture and a non-blocking I/O API designed to optimize an application's throughput and scalability for real-time web applications. It uses Google V8 JavaScript engine to execute code, and a large percentage of the basic modules are written in JavaScript. Node.js contains a built-in library to allow applications to act as a web server without software such as Apache HTTP Server, Nginx or IIS.<br><br>

    Node.js can be combined with a browser, a document database (such as MongoDB or CouchDB) and JSON for a unified JavaScript development stack.<br><br>

    According to wikipedia,

    Node.js is used by IBM, Microsoft, Yahoo!, Walmart, LinkedIn, Rakuten, PayPal and GoDaddy .

    </p>

    <p>
        <h3>npm</h3>
    &nbsp; &nbsp; &nbsp;

    npm is the pre-installed package manager for the Node.js server platform. It is used to install Node.js programs from the npm registry, organizing the installation and management of third-party Node.js programs.
    </p>
</div>

**

上述代码的输出为 **

在用div元素替换上述代码中的第一个p元素之后

输出是

为什么颜色属性不是在p元素中工作,而是在div元素中工作(在上面的代码中)?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-11 04:10:35

<h3>是块元素,<p>不能包含块元素。当你写这个时:

代码语言:javascript
运行
复制
<p style="...">
    <h3>heading</h3>
    text
</p>

浏览器不允许<h3>存在于<p>中,因此它通过提前关闭<p>标记悄悄地修复了这个问题,产生了如下内容:

代码语言:javascript
运行
复制
<p style="...">
    </p><h3>heading</h3>
    text

当您使用<div>时,它可以正常工作,因为<div>可以包含其他块元素,比如<h3>

只需将<h3>移出<p>,它就会正常工作。

虽然我注意到把所有的文本放在一个<p>中并使用<br><br>来分隔段落是有点愚蠢的!您可能需要将每一段放在自己的<p>标记中,因为"p“是”p“的缩写:)

票数 8
EN

Stack Overflow用户

发布于 2015-10-11 04:09:33

尝试添加css规则,而不是使用内联styles (最好在包装在<style></style>中的<head>标记中):

代码语言:javascript
运行
复制
p {
  color: red;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33061407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档