CSS Position: دليل شامل للتحكم في موضع العناصر والطبقات

CSS

CSS Position: دليل شامل للتحكم في موضع العناصر والطبقات
إتقان CSS Position - static، relative، absolute، fixed، sticky. تعلم التحكم الدقيق في موضع العناصر وإنشاء تأثيرات متقدمة.
#CSS#Position#Layout#Z-index#Absolute#Relative#Fixed#Sticky

CSS Position: دليل شامل للتحكم في موضع العناصر والطبقات

دليل تخصصي من علاء عامر – مطور ومصمم مواقع وتطبيقات محترف

CSS Position يوفر تحكماً دقيقاً في موضع العناصر. تعلم كيفية إنشاء تخطيطات معقدة وتأثيرات بصرية متقدمة.


1️⃣ أنواع Position الأساسية

نظرة عامة على القيم

.position-types {
  /* القيم المختلفة لـ position */
  position: static; /* الموضع الطبيعي (افتراضي) */
  position: relative; /* نسبة للموضع الأصلي */
  position: absolute; /* نسبة لأقرب حاوي positioned */
  position: fixed; /* نسبة لنافذة المتصفح */
  position: sticky; /* هجين بين relative و fixed */
}

/* خصائص الموضع */
.positioning-properties {
  top: 10px; /* من الأعلى */
  right: 20px; /* من اليمين */
  bottom: 15px; /* من الأسفل */
  left: 25px; /* من اليسار */
  z-index: 10; /* ترتيب الطبقات */
}

2️⃣ Static Position - الموضع الطبيعي

.static-example {
  position: static; /* افتراضي - لا حاجة لكتابته عادة */

  /* هذه الخصائص لا تعمل مع static */
  /* top: 10px;    ← لن يعمل */
  /* left: 20px;   ← لن يعمل */
  /* z-index: 5;   ← لن يعمل */
}

/* العناصر Static تتدفق طبيعياً */
.normal-flow {
  /* العناصر تظهر حسب ترتيبها في HTML */
  /* لا يمكن تحريكها من مكانها الطبيعي */
}

3️⃣ Relative Position - الموضع النسبي

.relative-example {
  position: relative;

  /* التحرك نسبة للموضع الأصلي */
  top: 20px; /* 20px من الأعلى */
  left: 30px; /* 30px من اليسار */

  /* العنصر يحتفظ بمساحته الأصلية في التدفق */
  /* العناصر الأخرى لا تتأثر */
}

/* استخدامات عملية للـ relative */
.card-with-badge {
  position: relative; /* مرجع للعناصر absolute بداخله */
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #e53e3e;
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

/* تأثير hover متقدم */
.hover-card {
  position: relative;
  transition: transform 0.3s ease;
}

.hover-card:hover {
  transform: translateY(-5px); /* بديل أفضل من top */
}

.hover-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 123, 255, 0.9);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.hover-card:hover .hover-overlay {
  opacity: 1;
}

4️⃣ Absolute Position - الموضع المطلق

.absolute-example {
  position: absolute;

  /* التحرك نسبة لأقرب حاوي positioned */
  top: 0;
  right: 0;

  /* العنصر يخرج من التدفق الطبيعي */
  /* لا يحتل مساحة في التخطيط */
}

/* حاوي positioned لعناصر absolute */
.positioned-container {
  position: relative; /* أو absolute أو fixed */
  /* العناصر absolute بداخله ستكون نسبة إليه */
}

/* استخدامات عملية */

/* أزرار إغلاق */
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  z-index: 1000;
}

.close-button {
  position: absolute;
  top: 15px;
  left: 15px;
  background: #f56565;
  color: white;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 18px;
}

/* توسيط مطلق */
.absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* يعمل مع أي حجم عنصر */
}

/* تخطيط الزوايا الأربع */
.corner-elements {
  position: relative;
  min-height: 300px;
  background: #f8f9fa;
  border: 2px solid #dee2e6;
}

.top-left {
  position: absolute;
  top: 10px;
  left: 10px;
}

.top-right {
  position: absolute;
  top: 10px;
  right: 10px;
}

.bottom-left {
  position: absolute;
  bottom: 10px;
  left: 10px;
}

.bottom-right {
  position: absolute;
  bottom: 10px;
  right: 10px;
}

/* تمدد كامل */
.absolute-stretch {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* يملأ الحاوي بالكامل */
}

5️⃣ Fixed Position - الموضع الثابت

.fixed-example {
  position: fixed;

  /* التحرك نسبة لنافذة المتصفح */
  top: 20px;
  right: 20px;

  /* يبقى في نفس المكان عند التمرير */
  /* يخرج من التدفق الطبيعي */
}

/* استخدامات عملية للـ fixed */

/* شريط تنقل ثابت */
.fixed-navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  padding: 15px 20px;
  z-index: 100;
}

/* إضافة padding للجسم لتجنب التداخل */
body.has-fixed-navbar {
  padding-top: 70px; /* حسب ارتفاع الشريط */
}

/* زر العودة للأعلى */
.back-to-top {
  position: fixed;
  bottom: 30px;
  left: 30px;
  width: 50px;
  height: 50px;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  opacity: 0;
  visibility: hidden;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* شريط جانبي ثابت */
.fixed-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 300px;
  height: 100vh;
  background: #2d3748;
  color: white;
  padding: 20px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.fixed-sidebar.open {
  transform: translateX(0);
}

/* إشعار ثابت */
.fixed-notification {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #48bb78;
  color: white;
  padding: 15px 25px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 1000;
}

6️⃣ Sticky Position - الموضع اللزج

.sticky-example {
  position: sticky;
  top: 20px; /* المسافة من الأعلى عند الالتصاق */

  /* يتصرف كـ relative حتى يصل للموضع المحدد */
  /* ثم يصبح fixed في ذلك الموضع */
}

/* استخدامات عملية للـ sticky */

/* عناوين أقسام لزجة */
.sticky-section-header {
  position: sticky;
  top: 0;
  background: white;
  padding: 15px 20px;
  border-bottom: 1px solid #e0e6ed;
  font-weight: 600;
  z-index: 10;
}

/* جدول برؤوس لزجة */
.sticky-table {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid #e0e6ed;
  border-radius: 8px;
}

.sticky-table thead th {
  position: sticky;
  top: 0;
  background: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
  padding: 12px 15px;
  font-weight: 600;
  z-index: 10;
}

/* شريط تقدم لزج */
.sticky-progress {
  position: sticky;
  top: 0;
  height: 4px;
  background: #e0e6ed;
  z-index: 50;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #4299e1, #63b3ed);
  width: 0%;
  transition: width 0.3s ease;
}

/* قائمة تنقل لزجة */
.sticky-nav {
  position: sticky;
  top: 80px; /* تحت الشريط الثابت */
  background: white;
  border-bottom: 1px solid #e0e6ed;
  padding: 10px 0;
  z-index: 40;
}

.sticky-nav ul {
  display: flex;
  justify-content: center;
  gap: 30px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.sticky-nav a {
  text-decoration: none;
  color: #4a5568;
  font-weight: 500;
  padding: 8px 15px;
  border-radius: 6px;
  transition: all 0.3s ease;
}

.sticky-nav a:hover,
.sticky-nav a.active {
  background: #ebf8ff;
  color: #2b6cb0;
}

7️⃣ Z-index والطبقات

/* فهم z-index */
.z-index-examples {
  /* z-index يعمل فقط مع العناصر positioned */
  position: relative; /* أو absolute، fixed، sticky */

  /* قيم z-index */
  z-index: 1; /* طبقة أساسية */
  z-index: 10; /* طبقة متوسطة */
  z-index: 100; /* طبقة عالية */
  z-index: 1000; /* طبقة عالية جداً */
  z-index: -1; /* خلف العناصر العادية */
}

/* سياق الطبقات (Stacking Context) */
.stacking-context {
  position: relative;
  z-index: 1;
  /* ينشئ سياق طبقات جديد */
  /* العناصر الفرعية تُرقم نسبة إليه */
}

/* مثال عملي - نوافذ متداخلة */
.window-system {
  position: relative;
  height: 500px;
  background: #f0f4f8;
  overflow: hidden;
}

.window {
  position: absolute;
  background: white;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  min-width: 300px;
  min-height: 200px;
}

.window-1 {
  top: 50px;
  left: 50px;
  z-index: 1;
}

.window-2 {
  top: 100px;
  left: 150px;
  z-index: 2;
}

.window-3 {
  top: 150px;
  left: 250px;
  z-index: 3;
}

.window.active {
  z-index: 100; /* النافذة النشطة في المقدمة */
}

/* طبقات النظام */
.system-layers {
  /* طبقات مرتبة منطقياً */
  --layer-background: -10;
  --layer-content: 0;
  --layer-overlay: 10;
  --layer-dropdown: 100;
  --layer-tooltip: 200;
  --layer-modal: 1000;
  --layer-notification: 2000;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--layer-modal);
}

.modal-content {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: calc(var(--layer-modal) + 1);
}

8️⃣ مشروع عملي: واجهة تطبيق متقدمة

<!DOCTYPE html>
<html lang="ar" dir="rtl">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>واجهة تطبيق متقدمة</title>
    <link rel="stylesheet" href="advanced-interface.css" />
  </head>
  <body>
    <!-- شريط تقدم التحميل -->
    <div class="loading-progress" id="loadingProgress">
      <div class="progress-bar"></div>
    </div>

    <!-- شريط التنقل الثابت -->
    <nav class="fixed-navbar">
      <div class="navbar-content">
        <div class="logo">
          <h1>التطبيق المتقدم</h1>
        </div>
        <div class="nav-links">
          <a href="#home">الرئيسية</a>
          <a href="#features">المميزات</a>
          <a href="#about">من نحن</a>
          <a href="#contact">تواصل</a>
        </div>
        <button class="menu-toggle" id="menuToggle">☰</button>
      </div>

      <!-- تنقل فرعي لزج -->
      <div class="sticky-subnav">
        <div class="subnav-content">
          <a href="#section1" class="active">القسم الأول</a>
          <a href="#section2">القسم الثاني</a>
          <a href="#section3">القسم الثالث</a>
          <a href="#section4">القسم الرابع</a>
        </div>
      </div>
    </nav>

    <!-- المحتوى الرئيسي -->
    <main class="main-content">
      <!-- قسم البطل -->
      <section id="home" class="hero-section">
        <div class="hero-content">
          <h2>مرحباً بك في التطبيق المتقدم</h2>
          <p>تجربة مستخدم استثنائية مع تقنيات CSS متقدمة</p>
          <button class="cta-button">ابدأ الآن</button>
        </div>

        <!-- عناصر ديكورية مطلقة -->
        <div class="floating-elements">
          <div class="float-1">✨</div>
          <div class="float-2">🚀</div>
          <div class="float-3">💡</div>
          <div class="float-4">⭐</div>
        </div>
      </section>

      <!-- أقسام المحتوى -->
      <section id="section1" class="content-section">
        <div class="sticky-header">
          <h3>القسم الأول - المميزات</h3>
        </div>
        <div class="section-content">
          <!-- بطاقات مع تأثيرات hover -->
          <div class="feature-cards">
            <div class="feature-card">
              <div class="card-icon">🎨</div>
              <h4>تصميم متقدم</h4>
              <p>واجهات جميلة ومتجاوبة</p>
              <div class="card-overlay">
                <button class="overlay-btn">اعرف المزيد</button>
              </div>
            </div>

            <div class="feature-card">
              <div class="card-icon">⚡</div>
              <h4>أداء سريع</h4>
              <p>تحميل فائق السرعة</p>
              <div class="card-overlay">
                <button class="overlay-btn">اعرف المزيد</button>
              </div>
            </div>

            <div class="feature-card">
              <div class="card-icon">🔒</div>
              <h4>أمان عالي</h4>
              <p>حماية متقدمة للبيانات</p>
              <div class="card-overlay">
                <button class="overlay-btn">اعرف المزيد</button>
              </div>

              <!-- شارة جديد -->
              <div class="new-badge">جديد</div>
            </div>
          </div>
        </div>
      </section>

      <!-- أقسام أخرى مماثلة -->
      <section id="section2" class="content-section">
        <div class="sticky-header">
          <h3>القسم الثاني - التقنيات</h3>
        </div>
        <div class="section-content">
          <p>محتوى القسم الثاني...</p>
        </div>
      </section>
    </main>

    <!-- شريط جانبي منزلق -->
    <aside class="sliding-sidebar" id="slidingSidebar">
      <div class="sidebar-header">
        <h3>القائمة الجانبية</h3>
        <button class="close-sidebar" id="closeSidebar">×</button>
      </div>
      <div class="sidebar-content">
        <nav class="sidebar-nav">
          <a href="#home">الرئيسية</a>
          <a href="#features">المميزات</a>
          <a href="#about">من نحن</a>
          <a href="#contact">تواصل</a>
        </nav>
      </div>
    </aside>

    <!-- خلفية الشريط الجانبي -->
    <div class="sidebar-backdrop" id="sidebarBackdrop"></div>

    <!-- إشعارات ثابتة -->
    <div class="notification-container">
      <div class="notification success" id="notification">
        <div class="notification-icon">✅</div>
        <div class="notification-content">
          <h4>نجح!</h4>
          <p>تم حفظ التغييرات بنجاح</p>
        </div>
        <button class="notification-close">×</button>
      </div>
    </div>

    <!-- زر العودة للأعلى -->
    <button class="back-to-top" id="backToTop">
      <span>↑</span>
    </button>

    <!-- زر الوضع المظلم -->
    <button class="theme-toggle" id="themeToggle">
      <span class="theme-icon">🌙</span>
    </button>

    <script src="advanced-interface.js"></script>
  </body>
</html>
/* advanced-interface.css */
:root {
  --primary: #4299e1;
  --primary-dark: #2b6cb0;
  --success: #48bb78;
  --warning: #ed8936;
  --danger: #f56565;
  --dark: #2d3748;
  --light: #f7fafc;
  --white: #ffffff;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
  --border-radius: 8px;
  --transition: all 0.3s ease;

  /* طبقات النظام */
  --z-background: -1;
  --z-content: 1;
  --z-sticky: 10;
  --z-fixed: 100;
  --z-dropdown: 200;
  --z-overlay: 500;
  --z-modal: 1000;
  --z-tooltip: 2000;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Cairo", Arial, sans-serif;
  line-height: 1.6;
  color: var(--dark);
  background: var(--light);
  padding-top: 120px; /* مساحة للشريط الثابت */
}

/* شريط تقدم التحميل */
.loading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(66, 153, 225, 0.2);
  z-index: var(--z-tooltip);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  width: 0%;
  transition: width 0.5s ease;
}

/* الشريط الثابت */
.fixed-navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-bottom: 1px solid #e2e8f0;
  box-shadow: var(--shadow);
  z-index: var(--z-fixed);
}

.navbar-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  max-width: 1200px;
  margin: 0 auto;
}

.logo h1 {
  color: var(--primary);
  font-size: 1.5rem;
}

.nav-links {
  display: flex;
  gap: 30px;
}

.nav-links a {
  text-decoration: none;
  color: var(--dark);
  font-weight: 500;
  transition: var(--transition);
  position: relative;
}

.nav-links a::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--primary);
  transition: width 0.3s ease;
}

.nav-links a:hover::after {
  width: 100%;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}

/* التنقل الفرعي اللزج */
.sticky-subnav {
  position: sticky;
  top: 70px;
  background: var(--white);
  border-bottom: 1px solid #e2e8f0;
  z-index: var(--z-sticky);
}

.subnav-content {
  display: flex;
  justify-content: center;
  gap: 40px;
  padding: 15px 30px;
  max-width: 1200px;
  margin: 0 auto;
}

.subnav-content a {
  text-decoration: none;
  color: #718096;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--border-radius);
  transition: var(--transition);
}

.subnav-content a:hover,
.subnav-content a.active {
  background: #ebf8ff;
  color: var(--primary);
}

/* المحتوى الرئيسي */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* قسم البطل */
.hero-section {
  position: relative;
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: var(--white);
  border-radius: var(--border-radius);
  margin-bottom: 40px;
  overflow: hidden;
}

.hero-content {
  position: relative;
  z-index: var(--z-content);
}

.hero-content h2 {
  font-size: 3rem;
  margin-bottom: 20px;
  animation: fadeInUp 1s ease;
}

.hero-content p {
  font-size: 1.2rem;
  margin-bottom: 30px;
  animation: fadeInUp 1s ease 0.2s both;
}

.cta-button {
  background: var(--white);
  color: var(--primary);
  border: none;
  padding: 15px 30px;
  border-radius: var(--border-radius);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  animation: fadeInUp 1s ease 0.4s both;
}

.cta-button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* العناصر العائمة */
.floating-elements {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.floating-elements > div {
  position: absolute;
  font-size: 2rem;
  opacity: 0.7;
  animation: float 6s ease-in-out infinite;
}

.float-1 {
  top: 20%;
  left: 10%;
  animation-delay: 0s;
}

.float-2 {
  top: 60%;
  right: 15%;
  animation-delay: 1s;
}

.float-3 {
  bottom: 30%;
  left: 20%;
  animation-delay: 2s;
}

.float-4 {
  top: 40%;
  right: 30%;
  animation-delay: 3s;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-20px);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* أقسام المحتوى */
.content-section {
  margin-bottom: 60px;
}

.sticky-header {
  position: sticky;
  top: 120px;
  background: var(--white);
  padding: 20px 0;
  border-bottom: 3px solid var(--primary);
  margin-bottom: 30px;
  z-index: var(--z-sticky);
}

.sticky-header h3 {
  font-size: 2rem;
  color: var(--primary);
}

.section-content {
  padding: 20px 0;
}

/* بطاقات المميزات */
.feature-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 30px;
}

.feature-card {
  position: relative;
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 30px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: var(--transition);
  overflow: hidden;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
}

.card-icon {
  font-size: 3rem;
  margin-bottom: 20px;
}

.feature-card h4 {
  font-size: 1.3rem;
  margin-bottom: 15px;
  color: var(--dark);
}

.feature-card p {
  color: #718096;
  line-height: 1.6;
}

/* تأثير overlay للبطاقات */
.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(66, 153, 225, 0.95);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: var(--transition);
}

.feature-card:hover .card-overlay {
  opacity: 1;
}

.overlay-btn {
  background: var(--white);
  color: var(--primary);
  border: none;
  padding: 12px 24px;
  border-radius: var(--border-radius);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.overlay-btn:hover {
  transform: scale(1.05);
}

/* شارة جديد */
.new-badge {
  position: absolute;
  top: 15px;
  right: 15px;
  background: var(--danger);
  color: var(--white);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* الشريط الجانبي المنزلق */
.sliding-sidebar {
  position: fixed;
  top: 0;
  right: -350px;
  width: 350px;
  height: 100vh;
  background: var(--white);
  box-shadow: var(--shadow-lg);
  transition: right 0.3s ease;
  z-index: var(--z-modal);
}

.sliding-sidebar.open {
  right: 0;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #e2e8f0;
}

.close-sidebar {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #718096;
}

.sidebar-content {
  padding: 20px;
}

.sidebar-nav a {
  display: block;
  padding: 15px 0;
  text-decoration: none;
  color: var(--dark);
  border-bottom: 1px solid #e2e8f0;
  transition: var(--transition);
}

.sidebar-nav a:hover {
  color: var(--primary);
  padding-right: 10px;
}

/* خلفية الشريط الجانبي */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: var(--z-overlay);
}

.sidebar-backdrop.active {
  opacity: 1;
  visibility: visible;
}

/* حاوي الإشعارات */
.notification-container {
  position: fixed;
  top: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-tooltip);
  width: 400px;
  max-width: 90vw;
}

.notification {
  display: flex;
  align-items: center;
  gap: 15px;
  background: var(--white);
  padding: 20px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  border-right: 4px solid var(--success);
  margin-bottom: 10px;
  transform: translateY(-100px);
  opacity: 0;
  transition: all 0.3s ease;
}

.notification.show {
  transform: translateY(0);
  opacity: 1;
}

.notification-icon {
  font-size: 1.5rem;
}

.notification-content h4 {
  margin-bottom: 5px;
  color: var(--dark);
}

.notification-content p {
  color: #718096;
  font-size: 0.9rem;
}

.notification-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  margin-right: auto;
  color: #718096;
}

/* زر العودة للأعلى */
.back-to-top {
  position: fixed;
  bottom: 30px;
  left: 30px;
  width: 50px;
  height: 50px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: var(--transition);
  opacity: 0;
  visibility: hidden;
  z-index: var(--z-fixed);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

/* زر تبديل الوضع */
.theme-toggle {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 50px;
  height: 50px;
  background: var(--dark);
  color: var(--white);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: var(--transition);
  z-index: var(--z-fixed);
}

.theme-toggle:hover {
  transform: scale(1.1);
}

/* التصميم المتجاوب */
@media (max-width: 768px) {
  body {
    padding-top: 70px;
  }

  .nav-links {
    display: none;
  }

  .menu-toggle {
    display: block;
  }

  .sticky-subnav {
    top: 70px;
  }

  .subnav-content {
    flex-wrap: wrap;
    gap: 20px;
  }

  .hero-content h2 {
    font-size: 2rem;
  }

  .feature-cards {
    grid-template-columns: 1fr;
  }

  .notification-container {
    width: 90%;
  }
}

الخلاصة

في هذا الدرس تعلمنا:

أنواع Position الخمسةRelative وAbsolute positioningFixed وSticky positioningZ-index وإدارة الطبقاتمشروع واجهة متقدمة شامل

في الدرس القادم سندرس التصميم المتجاوب وMedia Queries.

📩 تحتاج مساعدة في Position؟

aboutservicesprojectsBlogscontact