| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/HTML/Reference/Elements/button | [Back] [Original] |
Get to know MDN better
<button class="favorite styled" type="button"></button>
.styled {
border: 0;
line-height: 2.5;
padding: 0 20px;
font-size: 1rem;
text-align: center;
color: white;
text-shadow: 1px 1px 1px black;
border-radius: 10px;
background-color: tomato;
background-image: linear-gradient(
to top left,
rgb(0 0 0 / 0.2),
rgb(0 0 0 / 0.2) 30%,
transparent
);
box-shadow:
inset 2px 2px 3px rgb(255 255 255 / 0.6),
inset -2px -2px 3px rgb(0 0 0 / 0.6);
}
.styled:hover {
background-color: red;
}
.styled:active {
box-shadow:
inset -2px -2px 3px rgb(255 255 255 / 0.6),
inset 2px 2px 3px rgb(0 0 0 / 0.6);
}
autofocuscommand <button> commandfor
"show-modal" <dialog> HTMLDialogElement.showModal() <dialog>
"close" <dialog>
HTMLDialogElement.close() <dialog>
value returnValue
"request-close" cancel <dialog> close
close Event.preventDefault() cancel <dialog>
HTMLDialogElement.requestClose() <dialog>
value returnValue
"show-popover""hide-popover""toggle-popover" 2 (--) CommandEvent
commandfor<button> command commandfor ID popovertarget
disabledform <form> <form> id <button> <form>
<button> <form> <form> <form>
formaction URL action
formenctype<form> type="button"
formmethod<form> type="button" HTTP
formnovalidateformtarget_self: _blank: _parent: _self _top: () _self interestfor name value
popovertarget<button> ID popovertarget 2
aria-details aria-expanded (AT) popovertargetaction <button>
typesubmit: <form> reset: <input type="reset"> ()button: value name
close request-close value <dialog> returnValue
formaction <form> form id
<button> <input> HTML <i> <br> <img> ::after ::before
type button
<button type="button"> JavaScript
display: flow-root display: inline display: inline-block
<button>
<button name="favorite">
<svg fill="black" viewBox="0 0 42 42">
<path
d="M21,1c1.081,0,5.141,12.315,6.201,13.126s13.461,1.053,13.791,2.137 c0.34,1.087-9.561,8.938-9.961,10.252c-0.409,1.307,
3.202,13.769,2.331,14.442c-0.879,0.673-11.05-6.79-12.361-6.79 c-1.311,0-11.481,7.463-12.36,6.79c-0.871-0.674,2.739-13.136,
2.329-14.442c-0.399-1.313-10.3-9.165-9.96-10.252 c0.33-1.084,12.731-1.326,13.791-2.137S19.91,1,21,1z"></path>
</svg>
</button>
4444 CSS
margin CSS
ARIA aria-pressed aria-checked aria-selected ARIA button
:focus-visible <button> :focus :focus :focus-visible
(Web Content Accessibility Guidelines, WCAG) 4.5:1 3:1 ( bold 18.66px 24px )
type="button"
JavaScript commandcommandfor
<button type="button" name="button"></button>
request-close command 2
<button type="button" commandfor="mydialog" command="show-modal">
</button>
<dialog id="mydialog">
<div class="wrapper">
<form>
<fieldset>
<legend></legend>
<div>
<input type="radio" id="no" name="close" value="no" checked />
<label for="no"></label>
</div>
<div>
<input type="radio" id="yes" name="close" value="yes" />
<label for="yes"></label>
</div>
</fieldset>
</form>
<button commandfor="mydialog" command="request-close">
</button>
<p class="warning" hidden></p>
</div>
</dialog>
.warning {
color: tomato;
}
const dialog = document.querySelector("dialog");
const radio = document.querySelector("form").elements["close"];
const warning = document.querySelector(".warning");
dialog.addEventListener("cancel", (e) => {
if (!e.cancelable) return;
if (radio.value === "no") {
warning.hidden = false;
e.preventDefault();
} else {
warning.hidden = true;
}
});
<dialog> command="show-modal"
command="request-close" commandfor="mydialog" <dialog> <dialog> <dialog> command="close"
<dialog> cancel cancelable
cancelable
yes no hidden preventDefault() <dialog> close value value close returnValue
returnValue value
close dialog.returnValue
HTML commandfor
commandfor
command "close" value "cancel" "delete" returnValue
<button commandfor="confirm-dialog" command="show-modal"></button>
<dialog id="confirm-dialog">
<header>
<h1>?</h1>
</header>
<p></p>
<footer>
<button commandfor="confirm-dialog" command="close" value="cancel">
</button>
<button commandfor="confirm-dialog" command="close" value="delete">
</button>
</footer>
</dialog>
<pre id="log"></pre>
#log {
height: 20px;
}
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = text;
}
close returnValue
const dialog = document.getElementById("confirm-dialog");
dialog.addEventListener("close", () => {
switch (dialog.returnValue) {
case "cancel":
log("");
break;
case "delete":
log("");
break;
default:
log(": ", dialog.returnValue);
}
});
<button> select 0 1 <selectedcontent>
|
|
| ARIA |
button
|
| ARIA |
checkbox, combobox,
link, menuitem,
menuitemcheckbox,
menuitemradio, option,
radio, switch,
tab
|
| DOM | HTMLButtonElement |
| HTML # the-button-element |
<a><abbr><acronym><address><area><article><aside><audio><b><base><bdi><bdo><big><blockquote><body><br><button><canvas><caption><center><cite><code><col><colgroup><data><datalist><dd><del><details><dfn><dialog><dir><div><dl><dt><em><embed><fencedframe><fieldset><figcaption><figure><font><footer><form><frame><frameset><geolocation><h1><head><header><hgroup><hr><html><i><iframe><img><input><ins><kbd><label><legend><li><link><main><map><mark><marquee><menu><meta><meter><nav><nobr><noembed><noframes><noscript><object><ol><optgroup><option><output><p><param><picture><plaintext><pre><progress><q><rb><rp><rt><rtc><ruby><s><samp><script><search><section><select><selectedcontent><slot><small><source><span><strike><strong><style><sub><summary><sup><table><tbody><td><template><textarea><tfoot><th><thead><time><title><tr><track><tt><u><ul><var><video><wbr><xmp><input> <input type="button"><input type="checkbox"><input type="color"><input type="date"><input type="datetime-local"><input type="email"><input type="file"><input type="hidden"><input type="image"><input type="month"><input type="number"><input type="password"><input type="radio"><input type="range"><input type="reset"><input type="search"><input type="submit"><input type="tel"><input type="text"><input type="time"><input type="url"><input type="week"><script> | Web Proxy Viewer | New URL | Original Page |