HTMLボタンタグ

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBオリジナル
2024-09-04 16:29:55953ブラウズ

HTML ボタン タグを使用すると、HTML ドキュメントを使用して Web ページ上にアクティブなボタン コントロールを作成できます。この要素はbodyタグ内で宣言されます。なぜボタン要素が必要なのでしょうか?通常、ユーザーが Web ページにアクセスするときに最も一般的なことは、Web サイト上のどこかをクリックして、次の URL ページに移動することです。これを行うには、Button 要素だけでは実行できません。これは、Web フォームにデフォルトの送信ボタンのクリックがあるフォーム アクションによって作成されます。

ボタンは

構文:

他の HTML タグと同様、ボタン タグにも開始タグと終了タグの両方があり、ボタンのタイプは属性を使用して定義されます。

<button>
// some stuff like content / image
</button>

HTML ボタンタグの属性

必須の属性がないため、特別な属性は使用されていません。代わりに、type=” 属性を持つ通常のボタンとして使用されます。 「この要素でさえ、ボタン タグの変更を変更するプロパティを使用して CSS を使用してスタイル設定されています。これらのプロパティは、CSS フォント ファミリ、Font-weight、Text-decoration、および font-Style です。 Background-color などの色付けプロパティと、text-overflow や text-indent などのレイアウト プロパティ。

S.no Attribute Name Description Example
1 autofocus  It is considered a Boolean attribute.
2 disabled Making a button non-clickable.
3 Form It Creates a form
4 formaction It specifies the current location for submitting the form data.
5 formnovalidate  It appears in gray and gives non-validation features.
6 Formmethod It specifies the methods while referring to the next web  page(get the post of HTTP methods)
7 formtarget  It specifies the target path for the server response when a form action is done.
8 formenctype It has been used when a form is submitted to the webserver for the response; it activates the type of content used.
8 name  It specifies the button name used in the form element, which is used by form inputs.
9 type  It specifies the type of button being used. It has three default values submit, reset, and text.
10 value It gives an initial value when a button is used along with the form data
11 tabindex It specifies the tab key and the order does the preference.
12 onclick When a button is pressed, it runs a small javascript code behind it.

Examples to Implement in HTML Button Tag

Below are examples of implementing an HTML Button Tag:

Example #1

Code:



<title> HTML button tag Example</title>


<h2>HTML button tag Example </h2>

Employee Name:

Output:

HTMLボタンタグ

Example #2

Code:



<h3> <center> Example using CSS </center>
<h3>


Normal Class
<button type="button">Add to the First class</button>
<hr>
Economic Class
<button type="button" style="color: pink;"><b> Book Economic Class </b></button>
<hr>
Bussiness class
<button type="button" style="color: orange;"><b> Book Bussiness  Class </b></button>
<hr>
Departure
<button type="button" style="font: bold 12px Open Sans;">Norway </button><br>

</h3>
</h3>

Output:

HTMLボタンタグ

Example #3

With CSS: Here, we have used padding and margin property. Here are some ways to look at the page better. To create a button with rounded corners, use border-radius.

Code:

<style>
body {
color: #000;
height: 90vh;
background: linear-gradient(-90deg, #a1c3d1 0%, #c48b9e 100%) no-repeat;
text-align: center;
}
input {
width: 280px;
display: block;
margin: 2rem auto;
border: 3px solid #fbc7ff;
padding: 7px;
background: transparent;
border-radius: 25px;
outline: none;
}
::placeholder {
color: #00ced1;
}
.btn {
background:#96f905;
border: none;
height: 3rem;
border-radius: 20px;
width: 220px;
display: block;
color: #96f905;
outline: none;
margin: 2rem auto;
}
</style>

<h1>HTML Form action Using Button</h1>

Output:

HTMLボタンタグ

Note: You can also increase the button size by giving . btn in the above code is the bootstrap function class.

Example #4

The below example shows how to use the attribute autofocus with button element; in an example, when a page Loads, it focuses on the first HTML control.

Code:



<title>
Button Demo
<button>autofocus Attribute
</button>
</title>


<h1 style="color: blue;">
EDUCBA Web Tutorial
</h1>
<h2> Button Tag
<button>autofocus Attribute
</button>
</h2>
<h2> Button Tag
<button>autofocus Attribute
</button>
</h2>
<button id="GFG" autofocus>
Press
</button>
<br>

Output:

HTMLボタンタグ

Example #5

onclick attribute demo. In the below example, I have used JavaScript to take action in the button; meanwhile, it alerts a dialog box with a text message. We use a JavaScript function to make the critical decision by activating the button with onclick().

Code:



<title>HTML  On Click Button Demo</title>


<h3> HTML  On Click Button Demo</h3>
<button onclick="alert('Hi Welcome to EDUCBA!')"> Press me... </button>

Output: Before the button press

HTMLボタンタグ

Alert Message – After the Button click

HTMLボタンタグ

Example #6

Code:



<script type="text/javascript" src="scripts.js">
</script>
<link rel="stylesheet" href="styles.css">
<script type="text/javascript" src="scripts.js"></script>
<link rel="stylesheet" href="styles.css">


<p>The button loads to the next web page!</p>
<a href="https://www.educba.com" target="_blank">
<button>Submit!</button>
</a>

Output:

HTMLボタンタグ

Conclusion  

In summary, we have learned about the HTML Button tag. This tag initiates an action and submits content within an HTML document. Important aspects of the website create an easy button, CSS, and JavaScript to look colorful. You can also learn many options related to buttons.

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

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
前の記事:HTML記事タグ次の記事:HTML記事タグ