Como criar: mensagem de aviso
- Página anterior Cartão de produto
- Próxima página Caixa de mensagem
Aprenda a usar CSS para criar mensagens de aviso.
Aviso
As mensagens de aviso podem ser usadas para notificar o usuário sobre itens especiais: perigo, sucesso, informação ou aviso.
Crie uma mensagem de aviso
Primeira etapa - Adicionar HTML:
<div class="alert"> <span class="closebtn" onclick="this.parentElement.style.display='none';">×</span> Esta é uma caixa de alerta. </div>
Se você quiser fechar a mensagem de aviso, adicione uma tag com onclick
da propriedade <span>
Elemento, a propriedade indica "ao clicar em mim, ocultar meu elemento pai" - ou seja, o contêiner <div class="alert">
.
Dica:Use o entidade HTML "×" para criar o caractere "x".
Segunda etapa - Adicionar CSS:
Set the styles for 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 element onclick
properties to close different alerts.
And if you want the alerts to fade out slowly when clicked, add opacity and transition to alert
In class:
Example
<style> .alert { opacity: 1; transition: opacity 0.6s; /* 600 milliseconds fade out */ } </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++) { // Loop through all close buttons close[i].onclick = function(){ // Get the parent element of <span class="closebtn"> (<div class="alert">) var div = this.parentElement; // Set div's opacity to 0 (transparent) div.style.opacity = "0"; // 600 milliseconds later hide div (same as fade out time) setTimeout(function(){ div.style.display = "none"; }, 600); } } </script>
Páginas relacionadas
Tutorial:Como criar uma nota
- Página anterior Cartão de produto
- Próxima página Caixa de mensagem