为什么这个列表文本不能继承p的蓝色?

时间:2021-08-11 03:39:26

It seems inheritance works for color but when I try to inherit the color its anchestor p, the list cannot take the color..Why does inheritance not work in this case?

看起来继承对颜色是有效的,但是当我试图继承颜色时,它的锚定值p,列表不能取颜色。为什么继承在这种情况下不起作用?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>CSS (1)</title>
    <style type="text/css">
      p#parag{color:#009;}
    </style>
  </head>

  <body>
    <p id="parag">
      <ul id="nav">
        <li>test</li>
      </ul>
    </p>
  </body>
</html>

2 个解决方案

#1


6  

<ul> is a block-level element.

    是块级元素。

<p> cannot contain block-level elements - from the HTML 4.01 spec:

不能包含块级元素——从HTML 4.01规范:

The P element represents a paragraph. It cannot contain block-level elements (including P itself).

P元素表示一个段落。它不能包含块级元素(包括P本身)。

So the browser is attempting to fix this error and produces this HTML:

所以浏览器试图修正这个错误并生成这个HTML:

<p id="parag"></p>
<ul id="nav">
  <li>test</li>
</ul>
<p></p>

The solution is to simply change the <p> to a <div>.

解决方案是将

改为

#2


1  

<ul> (block level) is not valid within a <p> tag - no block levels allowed within <p> tags!

    (块级)在

    标签内无效——

    标签内不允许有块级!

http://webdesign.about.com/od/htmltags/p/bltags_paragrap.htm

http://webdesign.about.com/od/htmltags/p/bltags_paragrap.htm

#1


6  

<ul> is a block-level element.

    是块级元素。

<p> cannot contain block-level elements - from the HTML 4.01 spec:

不能包含块级元素——从HTML 4.01规范:

The P element represents a paragraph. It cannot contain block-level elements (including P itself).

P元素表示一个段落。它不能包含块级元素(包括P本身)。

So the browser is attempting to fix this error and produces this HTML:

所以浏览器试图修正这个错误并生成这个HTML:

<p id="parag"></p>
<ul id="nav">
  <li>test</li>
</ul>
<p></p>

The solution is to simply change the <p> to a <div>.

解决方案是将

改为

#2


1  

<ul> (block level) is not valid within a <p> tag - no block levels allowed within <p> tags!

    (块级)在

    标签内无效——

    标签内不允许有块级!

http://webdesign.about.com/od/htmltags/p/bltags_paragrap.htm

http://webdesign.about.com/od/htmltags/p/bltags_paragrap.htm