JSFiddle - React, Tailwind, and code Playground
HTML
<div class="alert alert-primary">
歡迎您點擊「抖內」按鈕,以實際行動支持我們。
<button onclick="remove_alert()" class="btn-close btn-close-primary">✘</button>
</div>
<hr>
<div class="alert alert-success">
您已成功下訂單!以下為您的訂單詳細資訊。
<button onclick="remove_alert()" class="btn-close btn-close-success">✘</button>
</div>
<hr>
<div class="alert alert-danger">
抱歉,系統發生錯誤,請稍後重新嘗試。
<button onclick="remove_alert()" class="btn-close btn-close-danger">✘</button>
</div>
<hr>
<div class="alert alert-warning">
請注意,以下內容包含「劇透」爆雷資訊。
<button onclick="remove_alert()" class="btn-close btn-close-warning">✘</button>
</div>
CSS
.alert{
width: 500px;
height: 40px;
text-align: center;
line-height: 40px;
font-family: Comic Sans MS , Microsoft JhengHei;
border-radius: 10px;
}
.alert:hover{
box-shadow: 0px 2px 2px 0px #b1b1b1;
}
.alert-primary{
border: 3px solid #2894FF;
color: #0066CC;
background-color: #d0e8ff;
}
.alert-success{
border: 3px solid #1AFD9C;
color: #00BB00;
background-color: #d0ffd6;
}
.alert-danger{
border: 3px solid #EA0000;
color: #D9006C;
background-color: #ffd0d0;
}
.alert-warning{
border: 3px solid #FFA042;
color: #D94600;
background-color: #ffefd0;
}
.btn-close{
background-color: transparent;
border: 0;
font-family: Comic Sans MS , Microsoft JhengHei;
transition: 0.3s;
}
.btn-close:hover{
font-weight: bold;
transform: scale(1.5);
}
.btn-close:active{
transform: scale(1.2);
}
.btn-close-primary{
color: #0066CC;
}
.btn-close-success{
color: #00BB00;
}
.btn-close-danger{
color: #D9006C;
}
.btn-close-warning{
color: #D94600;
}
JavaScript
function remove_alert(){
var remove_alert = event.target.closest('div');
remove_alert.remove();
}