在下面的html代码中,段落(p)元素颜色不随css的color属性而改变 ,*
但如果我用div元素替换p它正常工作..
enter code here
Run Code Online (Sandbox Code Playgroud)
如何在Ubuntu 14.04中安装Node.js和npm Tool
<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>
Run Code Online (Sandbox Code Playgroud)
**
用div元素替换上面代码中的第一个p元素后
为什么color属性不在p元素中工作但在div元素中工作(在上面的代码中)?
<h3>是块元素,<p>不能包含块元素.当你写这个:
<p style="...">
<h3>heading</h3>
text
</p>
Run Code Online (Sandbox Code Playgroud)
浏览器不允许<h3>存在于其中<p>,因此它通过提前关闭标记来悄悄修复此问题<p>,产生如下内容:
<p style="...">
</p><h3>heading</h3>
text
Run Code Online (Sandbox Code Playgroud)
它使用时工作正常<div>,因为<div>可以包含其他块元素<h3>.
只需移动<h3>外部,<p>它应该工作正常.
虽然我注意到将所有文本放在一个单独的段落<p>并用于<br><br>分隔段落是有点愚蠢的!您可能希望将每个段落放在自己的<p>标记中,因为这是"p"的缩写:)