-3

誰かが私に次のことを説明できますか;

次のコードでは、Firefox、Chrome、Opera ですべてのテキストが赤くなっています。(コード)

<html>
    <head><title>HTML TEST</title></head>
    <body>
        Test One
        <html style="color:red">Test Two</html>
    </body>
</html>

html実際には body タグ内に要素を追加してはならないことはわかっていますが、ブラウザbodyが 2 番目のテキストではなくテキストの色を変更する原因は何htmlですか?

最初に追加style=blueすると、すべてのテキストが青色になります。 html

繰り返しますが、これは実際的な問題ではないことは理解しています。ブラウザがそのような動作をする理由を知りたいだけです。

4

2 に答える 2

2

Firefox では firebug を使用するか、Chrome では f12 を押して、ブラウザがコードをどのように解釈しているかを確認します。<html>Firefox と Chrome の両方で、タグが 1 つしかないことがわかります。興味深いことに、@ Ragarokkr の回答スタイリングとは対照的に、外側のタグは内側のタグよりも優先されます。

于 2013-02-05T00:42:53.210 に答える
0

From doing further testing;

If there is no style attribute associated with the root level html then any preceeding html elements will be removed and their style added to the root level html element.

Once there is a style attribute associated with the root level html element then no styling changes will matter.

For example in my linked code change the first html element to have style="" after it and the writing will be black.

It is an interesting property.

于 2013-02-05T00:56:43.280 に答える