چگونه ایجاد شود: پیامهای هشدار
- صفحه قبل کارت محصول
- صفحه بعدی پیامهای یادآوری
یاد بگیرید که چگونه با استفاده از CSS پیامهای هشدار ایجاد کنید.
هشدار
پیامهای هشدار میتوانند برای اطلاعرسانی به کاربر در مورد موضوعات خاص استفاده شوند: خطر، موفق، اطلاعات یا هشدار.
پیام هشدار ایجاد کنید
مرحله اول - اضافه کردن HTML:
<div class="alert"> <span class="closebtn" onclick="this.parentElement.style.display='none';">×</span> این یک جعبه هشدار است. </div>
اگر میخواهید بتوانید پیام هشدار را ببندید، یک علامت نگارشی با onclick
ویژگیها <span>
عنصر، این ویژگی نشاندهنده این است که "وقتی روی من کلیک میکنید، عنصر والد من را پنهان کنید" - به عبارت دیگر، محفظه <div class="alert">
.
توجه:از نمادهای HTML "×" برای ایجاد حرف "x" استفاده کنید.
مرحله دوم - اضافه کردن CSS:
Set the style of the alert box and close button:
/* Alert message box */ .alert { padding: 20px; background-color: #f44336; /* Red */ color: white; margin-bottom: 15px; } /* Close button */ .closebtn { margin-left: 15px; color: white; font-weight: bold; float: right; font-size: 22px; line-height: 20px; cursor: pointer; transition: 0.3s; } /* When the mouse moves over the close button */ .closebtn:hover { color: black; }
multiple alerts
If there are multiple alert messages on the page, you can add the following script to <span>
of the onclick
properties to close different alerts.
And if you want to fade out slowly when clicking on the alerts, add opacity and transition to alert
In class:
Example
<style> .alert { opacity: 1; transition: opacity 0.6s; /* Fade out in 600 milliseconds */ } </style> <script> // Get all elements with class="closebtn" var close = document.getElementsByClassName("closebtn"); var i; // Loop through all close buttons for (i = 0; i < close.length; i++) { // Traverse all close buttons close[i].onclick = function(){ // Get the parent element of <span class="closebtn"> (<div class="alert">) var div = this.parentElement; // Set the opacity of div to 0 (transparent) div.style.opacity = "0"; // 600 milliseconds after, hide div (same as fade out time) setTimeout(function(){ div.style.display = "none"; }, 600); } } </script>
صفحات مرتبط
- صفحه قبل کارت محصول
- صفحه بعدی پیامهای یادآوری