<ul class="list">
<li class="list__item">
<a class="my-button js-button" href="#">a要素で作ったボタン</a>
</li>
<li class="list__item">
<button class="my-button js-button" type="button">button要素で作ったボタン</button>
</li>
<li class="list__item">
<div class="my-button js-button">div要素で作ったボタン</div>
</li>
</ul>
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
background-color: #f7f7f7;
color: #333;
font-family:
'Helvetica Neue',
'Segoe UI',
'Hiragino Kaku Gothic ProN',
'Hiragino Sans',
Meiryo,
sans-serif;
padding: 5%;
}
.list__item {
max-width: 320px;
& + & {
margin-top: 1.5em;
}
}
.my-button {
appearance: none;
background-color: transparent;
border: 1px solid #878787;
color: #555;
cursor: pointer;
display: block;
font: inherit;
max-width: 320px;
padding: 1.2em 1.5em;
position: relative;
text-align: center;
text-decoration: none;
transition: background-color .3s, color .3s;
width: 100%;
&::after {
border: 4px solid transparent;
border-bottom: 4px solid;
border-radius: 2px;
border-right: 4px solid;
bottom: 4px;
content: '';
display: inline-block;
position: absolute;
right: 4px;
}
&.focus-visible {
background-color: #555;
color: #f7f7f7;
}
@media (hover) {
&:hover {
background-color: #555;
color: #f7f7f7;
}
}
}
.message-box {
background-color: #cd5c5c;
border-radius: 4px;
box-shadow: 0 10px 12px -8px rgba(0, 0, 0, .35);
color: #f7f7f7;
font-size: .8rem;
margin: 12px auto 0;
min-width: 196px;
padding: 1.4em 1.5em;
position: relative;
text-align: center;
width: 60%;
&::before {
border: 8px solid transparent;
border-bottom: 10px solid #cd5c5c;
bottom: 100%;
content: '';
left: calc(50% - 8px);
position: absolute;
}
}
.js-focus-visible :focus:not(.focus-visible) {
outline: none;
}
View Compiled
!function(){
const button = document.querySelectorAll('.js-button');
const messageBox = document.createElement('p');
messageBox.className = 'message-box';
messageBox.innerHTML = 'プッシュされました!';
button.forEach((el) => {
el.addEventListener('click', (e) => {
e.preventDefault();
e.currentTarget.parentNode.insertBefore(messageBox, e.currentTarget.nextElementSibling);
});
});
}();
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.