开发者

How to display preformatted data in headings?

开发者 https://www.devze.com 2023-03-16 06:19 出处:网络
I am new to HTML. I was trying the following code to work but it did not. Can anyone please help me out why <pre> tag is not working inside <h> tags? I also tried to code tag but it din\'t

I am new to HTML. I was trying the following code to work but it did not. Can anyone please help me out why <pre> tag is not working inside <h> tags? I also tried to code tag but it din't worked too.

<!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" xml:lang="en" lang="en"> 
        <head>
                <title> Checking Different Headings | Isnt it fun?</title>
        </head>
        <body>
                <h1>  This is a title</h1>
                <h2>  What is life? </h2>
                <h3>  Paragraphs are written using <pre> <p&开发者_StackOverflow中文版gt;</pre>tags </h3>
        </body>
</html>


The pre element is not what you want there.

If you are trying to show <p>, you should use &lt;p&gt;.

The HTML angle brackets (less and greater than characters) are encoded, so they are no longer meaningful in HTML tags.

Otherwise, the HTML parser believes your <p> is a p element.


Try this:

<!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" xml:lang="en" lang="en"> 
        <head>
                <title> Checking Different Headings | Isnt it fun?</title>
        </head>
        <body>
                <h1>  This is a title</h1>
                <h2>  What is life? </h2>
                <h3>  Paragraphs are written using </h3> <pre> <p></pre> <h3>tags </h3>
        </body>
</html>

However, the contents in the <pre> tag will not be shown inline with <h3> also, it wont match the font size. You may want to use CSS to change how to display the <pre> tag with <h3>

0

精彩评论

暂无评论...
验证码 换一张
取 消