HTMLの事前タグ

WBOY
リリース: 2024-09-04 16:25:20
オリジナル
768 人が閲覧しました

Web ブラウザでは、テキストのスペース、改行、その他の書式設定文字は無視されます。何らかの形式が必要な場合は、タグまたは属性を毎回使用する必要があります。この欠点を取り除くために使用されます。 preタグはテキストの形式をそのまま維持するために使用されます。 CSSタグが適用されると変更されます。コンテンツのフォーマット済みテキストが表示されます。

構文:

HTML には、さまざまな目的のための多くのタグがあります。

例:


  • など

pre タグには、他の HTML タグと同様に、開始タグと終了タグがあります。

<pre class="brush:php;toolbar:false"> content of web 
ログイン後にコピー

上記の構文は、コンテンツのフォーマット済みテキストが必要な場合に使用されます。

HTML で Pre タグはどのように機能しますか?

以下は Pre タグの仕組みについての説明です:

1. HTML で Pre タグを使用する

コード:

<!DOCTYPE>
<html>
<head>
<title> using pre tag in html </title>
</head>
<body>
<pre class="brush:php;toolbar:false">
The Web browser is ignored space,   line breaks, and other formatting characters of text.
If you wanted some   format then tag or attribute must have used every time.
Pre tag in HTML used to remove this drawback. Pre tag used to keep text format as it is.
It is   changed when CSS tags are applied.
Pre tag in HTML shows the  preformatted text of the content.
ログイン後にコピー

出力:

HTMLの事前タグ

上記のコードの説明: 上記の例を示します。コンテンツの必要な部分にプレタグを適用すると、コンテンツはフォーマットされたままの状態で表示されます。 pre タグがテキストに適用される場合、スペースと次の行は無視されません。

2. HTML で Pre タグを使用しない

コード:

<!DOCTYPE>
<html>
<head>
<title> using pre tag in html </title>
</head>
<body>
The Web browser is ignored space, line breaks, and other
formatting characters of text.
If you wanted some format then tag or attribute must have
used every time.
This tag is used to remove this drawback. Pre tag used to
keep text format as it is. It is changed when CSS tags are applied.
This pre tag shows the preformatted text of the content.
</body>
</html>
ログイン後にコピー

出力:

HTMLの事前タグ

上記のコードの説明: 使用しない場合の上記の例を示します。スペース、改行、改行は自動的に無視されます。 Web ページには、要件に従ってコンテンツが表示されます。スペースを与えて改行するには、HTML タグを使用する必要があります。

3. HTML の他のタグを使用する

コード:

<!DOCTYPE>
<html>
<head>
<title> using pre tag in html </title>
</head>
<body>
The Web browser is ignored space,         line breaks, and other formatting characters of text.<br>
If you wanted some      format then tag or attribute must have used every time.<br>
This is used to remove its drawback. Pre tag used to keep text format as it is.<br> It is changed when CSS tags are applied. <br>
It shows preformatted text of the content.<br>
</body>
</html>
ログイン後にコピー

出力:

HTMLの事前タグ

上記のコードの説明: pre タグを使用しない上記の例を示します。ただし、pre タグを使用する代わりに、他の HTML タグを使用しています。
タグは改行に使用され、 スペースに使用される文字。

Preタグの使用

  • タグと属性を使用しない場合、Web ページはスペースと改行を無視します。ただし、各行でこれらの属性を使用する必要があります。
  • Pre タグは元のコンテンツ形式を保持します。
  • 開発者は、多くのタグを使用する代わりに、ブロックに 1 つのタグを使用できます。コーディングを減らして理解しやすくします。

Pre Tag は次の Web ブラウザをサポートしています:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • オペラ
  • サファリ

実装例

以下はその実装例です:

例 #1

CSS タグで Pre タグを使用します。

コード:

<!DOCTYPE>
<html>
<head>
<title> using pre tag with CSS </title>
<style>
pre {
font-family: Arial;
color: yellow;
border: solid black;
background-color: black;
}
</style>
</head>
<body>
<pre class="brush:php;toolbar:false">
The Web browser is ignored space, line breaks, and other formatting characters of text.
If you wanted some format then tag or attribute must have used every time.
This tag in HTML used to remove this drawback. Pre tag used to keep text format as it is.
It is changed when CSS tags are applied.
This tag in HTML shows the preformatted text of the content.
ログイン後にコピー

出力:

HTMLの事前タグ

上記のコードの説明: 上記の例では、CSS スタイル タグを使用していることを示します。 pre タグを使用した場合は、CSS スタイル タグでもコンテンツの形式を変更できます。スタイルタグは、CSS のフォント スタイル、境界線、テキストの色を使用しました。

例 #2

以下の例。これは、他の HTML タグと CSS の pre タグを組み合わせたものです。

コード:

<!DOCTYPE>
<html>
<head>
<title> using pre tag in html  with CSS </title>
<style>
pre {
font-family: Arial;
color: yellow;
border: solid black;
background-color:black;
}
</style>
</head>
<body>
<p>
The Web browser is ignored space, line breaks, and other formatting characters of text.
If you wanted some format then tag or attribute must have used every time.
This tag used to remove this drawback. Pre tag used to keep text format as it is.
It is changed when CSS tags are applied.
It shows the preformatted text of the content.
</p>
<pre class="brush:php;toolbar:false">
The Web browser is ignored space, line breaks, and other formatting characters of text.
If you wanted some format then tag or attribute must have used every time.
This tag in HTML used to remove this drawback. Pre tag used to keep text format as it is.
It is changed when CSS tags are applied.
This tag in HTML shows the preformatted text of the content.
ログイン後にコピー

出力:

HTMLの事前タグ

結論

開発者はこのタグを使用してコーディングを削減し、フォーマットされたコンテンツを取得します。ウェブは pre タグ内のコンテンツの形式を無視できません。

以上がHTMLの事前タグの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:php
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!