在下面的html代码中,段落(p)元素的颜色不随css的颜色属性而改变,*
,但是如果我用div元素替换p,它是正常工作的..
enter code here
如何在Ubuntu14.04中安装Node.js和npm工具
如何在Ubuntu14.04中安装Node.js和npm工具
<div>
<h2>
Introduction:
</h2>
<p style="color:red;">
<h3>Node.js</h3>
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>
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元素中工作(在上面的代码中)?
发布于 2015-10-11 04:10:35
<h3>是块元素,<p>不能包含块元素。当你写这个时:
<p style="...">
<h3>heading</h3>
text
</p>浏览器不允许<h3>存在于<p>中,因此它通过提前关闭<p>标记悄悄地修复了这个问题,产生了如下内容:
<p style="...">
</p><h3>heading</h3>
text当您使用<div>时,它可以正常工作,因为<div>可以包含其他块元素,比如<h3>。
只需将<h3>移出<p>,它就会正常工作。
虽然我注意到把所有的文本放在一个<p>中并使用<br><br>来分隔段落是有点愚蠢的!您可能需要将每一段放在自己的<p>标记中,因为"p“是”p“的缩写:)
发布于 2015-10-11 04:09:33
尝试添加css规则,而不是使用内联styles (最好在包装在<style></style>中的<head>标记中):
p {
color: red;
}https://stackoverflow.com/questions/33061407
复制相似问题