Skip to main content
The Alert component displays a fixed-position notification banner in the bottom-right corner of the page. It’s used to show the educational disclaimer about the site not being official.

Features

  • Fixed positioning in bottom-right corner
  • Dismissible with close button
  • Slide-in animation on page load
  • Gradient background with border
  • Responsive design
  • Custom styling with glassmorphism effect

Usage

src/layouts/Layout.astro
---
import Alert from "../components/Alert.astro";
---

<Alert />

Component Code

src/components/Alert.astro
<div class="alert-container">
  <div class="alert-content">
    <button class="close-button" 
            onclick="this.parentElement.parentElement.style.display='none';">
      ×
    </button>
    <p class="mb-0">
      <span class="warning-text">⚠️ This is not the official website!</span>
      This page was created for educational purposes only. Visit the official website at: 
      <a href="https://www.robtopgames.com/"
         target="_blank"
         rel="noopener noreferrer">www.robtopgames.com</a>
    </p>
  </div>
</div>

Positioning

The alert is positioned fixed in the bottom-right corner:
.alert-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  animation: slideIn 0.5s ease-out;
}
  • Bottom: 20px from bottom edge
  • Right: 20px from right edge
  • Z-index: 1000 (appears above other content)

Close Button

The alert can be dismissed with an inline click handler:
<button class="close-button" 
        onclick="this.parentElement.parentElement.style.display='none';">
  ×
</button>
When clicked, the alert is hidden by setting display: none on the container.

Styling Features

Gradient Background

.alert-content {
  background: linear-gradient(45deg, #1a1a1a, #2a2a2a);
  border: 2px solid #4caf50;
  border-radius: 10px;
  padding: 15px 20px;
  color: white;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

Close Button Styling

.close-button {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(76, 175, 80, 0.1);
  border: 1px solid #4caf50;
  border-radius: 50%;
  color: #4caf50;
  font-size: 18px;
  cursor: pointer;
  width: 24px;
  height: 24px;
  transition: all 0.3s ease;
}

.close-button:hover {
  background: rgba(76, 175, 80, 0.2);
  color: #66bb6a;
  transform: scale(1.1);
}
Features:
  • Circular shape
  • Green theme matching alert border
  • Scale effect on hover
  • Positioned absolutely in top-right corner

Slide-In Animation

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}
The alert slides in from the right when the page loads.

Warning Text

.warning-text {
  color: #4caf50;
  font-weight: bold;
  margin-right: 8px;
}
a {
  color: #4caf50;
  text-decoration: none;
  font-weight: bold;
  transition: color 0.3s ease;
}

a:hover {
  color: #66bb6a;
  text-decoration: underline;
}

Responsive Behavior

The alert has a max-width to prevent it from being too large:
.alert-content {
  max-width: 400px;
}
On mobile devices, consider adding media queries:
@media (max-width: 576px) {
  .alert-container {
    bottom: 10px;
    right: 10px;
    left: 10px;
  }
  
  .alert-content {
    max-width: 100%;
    font-size: 0.85rem;
  }
}

Customization

Making it Reusable

To accept custom message and styling as props:
src/components/Alert.astro
---
interface Props {
  message: string;
  type?: 'info' | 'warning' | 'error' | 'success';
  dismissible?: boolean;
}

const { 
  message, 
  type = 'warning',
  dismissible = true 
} = Astro.props;

const colors = {
  info: '#2196F3',
  warning: '#4caf50',
  error: '#f44336',
  success: '#4caf50'
};

const borderColor = colors[type];
---

<div class="alert-container">
  <div class="alert-content" style={`border-color: ${borderColor}`}>
    {dismissible && (
      <button class="close-button" 
              onclick="this.parentElement.parentElement.style.display='none';">
        ×
      </button>
    )}
    <p class="mb-0" set:html={message} />
  </div>
</div>
Usage:
<Alert 
  message="<strong>Notice:</strong> Maintenance scheduled for tonight."
  type="info"
  dismissible={true}
/>

Persistent Dismissal

To remember the user dismissed the alert using localStorage:
src/components/Alert.astro
<div class="alert-container" id="site-alert">
  <div class="alert-content">
    <button class="close-button" onclick="dismissAlert()">
      ×
    </button>
    <p class="mb-0">
      <span class="warning-text">⚠️ This is not the official website!</span>
      This page was created for educational purposes only.
    </p>
  </div>
</div>

<script>
  function dismissAlert() {
    const alert = document.getElementById('site-alert');
    if (alert) {
      alert.style.display = 'none';
      localStorage.setItem('alertDismissed', 'true');
    }
  }

  // Check if alert was previously dismissed
  if (localStorage.getItem('alertDismissed') === 'true') {
    const alert = document.getElementById('site-alert');
    if (alert) {
      alert.style.display = 'none';
    }
  }
</script>

Accessibility

Enhanced accessibility version:
src/components/Alert.astro
<div class="alert-container" role="alert" aria-live="polite">
  <div class="alert-content">
    <button class="close-button" 
            onclick="this.parentElement.parentElement.style.display='none';"
            aria-label="Close notification">
      ×
    </button>
    <p class="mb-0">
      <span class="warning-text">⚠️ This is not the official website!</span>
      This page was created for educational purposes only. Visit the official website at: 
      <a href="https://www.robtopgames.com/"
         target="_blank"
         rel="noopener noreferrer"
         aria-label="Visit official RobTop Games website">www.robtopgames.com</a>
    </p>
  </div>
</div>
  • Header - Site header component
  • Footer - Site footer component
  • SEO - Meta tags for SEO

Build docs developers (and LLMs) love