我們使用標籤來定義程式設計或數學運算式中的變數。它也用於格式化文件中的文字。該標籤內的內容通常以斜體字顯示。
<var>Variable…</var>
以下是使用HTML中的標籤執行變數格式化的範例 -
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="description" content="meta tag in the web document"> <meta name="keywords" content="HTML,CSS"> <meta name="author" content="lokesh"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <p> <var>a</var> = float(input('Enter a value: ')) <br> <var>b </var>= float(input('Enter b value: ')) <br> <var>c </var>= float(input('Enter c value: ')) <br> # calculate the semi-perimeter <br> <var>s </var>= (<var>a</var> +<var> b</var> +<var> c</var>) / 2 <br> # calculate the area <br> area = (<var>s</var>*(<var>s</var>-<var>a</var>)*(<var>s</var>-<var>b</var>)*(<var>s</var>-<var>c</var>)) ** 0.5 <br> print('The area of the triangle is %0.2<var>f</var>' %area) </p> </body> </html>
您可以嘗試執行以下程式碼,使用HTML中的標籤進行變數格式化 -
<!DOCTYPE html> <html> <head> <title>HTML var Tag</title> </head> <body> <p>The equations: <var>2x</var> - <var>3z </var> = <var>5y</var> + 2 and <var>2x</var> + <var>5z</var> = <var>2y</var> + 7 </p> </body> </html>
我們可以使用樣式表覆蓋字體樣式。範例程式碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="description" content="meta tag in the web document"> <meta name="keywords" content="HTML,CSS"> <meta name="author" content="lokesh"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> var{ font-family: cursive; } </style> </head> <body> <p> <var>a</var> = float(input('Enter a value: ')) <br> <var>b </var>= float(input('Enter b value: ')) <br> <var>c </var>= float(input('Enter c value: ')) <br> # calculate the semi-perimeter <br> <var>s </var>= (<var>a</var> +<var> b</var> +<var> c</var>) / 2 <br> # calculate the area <br> area = (<var>s</var>*(<var>s</var>-<var>a</var>)*(<var>s</var>-<var>b</var>)*(<var>s</var>-<var>c</var>)) ** 0.5 <br> print('The area of the triangle is %0.2<var>f</var>' %area) </p> </body> </html>
以上是我們如何在HTML中使用標籤進行變數格式化?的詳細內容。更多資訊請關注PHP中文網其他相關文章!