← المستوى 1 – البنّاء

الدرس 10 من 12 ⏱ 35 دقيقة

البطاقات ومعرض الصور

ابنِ أكثر قطعتين شعبيتين في المواقع الحديثة: بطاقات المحتوى وشبكة الصور.

شاهد معي: بطاقة

البطاقة مستطيل أبيض بظل يحمل صورة ونص معاً. تعرفها من YouTube وNetflix والمتاجر. البطاقة مجرد صندوق ببعض الخصائص:

<div class="card">
  <img src="images/photo.jpg" alt="Photo description">
  <h3>Card heading</h3>
  <p>Short text for the card.</p>
</div>
.card {
  background-color: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

شيئان جديدان:

شاهد معي: بطاقات جنباً إلى جنب

الآن حيلة تعرفها – flexbox. لفّ البطاقات في صندوق واضبطه على flex:

<div class="cards">
  <div class="card">…</div>
  <div class="card">…</div>
  <div class="card">…</div>
</div>
.cards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.cards .card {
  flex: 1;             /* cards fairly share the available space */
  min-width: 200px;    /* but none will ever be narrower than 200px */
}

flex-wrap: wrap + min-width = على الكمبيوتر البطاقات جنباً إلى جنب، على الهاتف تتراص. لقد بنيت موقعاً responsive – يتكيّف مع أي شاشة.

دورك الآن 💪

أضف قسم بطاقات إلى موقعك – ثلاث على الأقل جنباً إلى جنب. ما يذهب عليها يعتمد على مشروعك:

🏫 موقع المدرسة – الحل (بطاقات المعلمين)
<h2>Our Teachers</h2>
<div class="cards">
  <div class="card">
    <h3>Ms. Turner</h3>
    <p>4th grade homeroom. Teaches English and art. Loves cats.</p>
  </div>
  <div class="card">
    <h3>Mr. Bennett</h3>
    <p>Math and P.E. Runs the floorball club.</p>
  </div>
  <div class="card">
    <h3>Principal Adams</h3>
    <p>Running the school for 10 years. Plays the piano.</p>
  </div>
</div>
🙋 الموقع الشخصي – الحل (بطاقات الهوايات)
<h2>My Hobbies</h2>
<div class="cards">
  <div class="card">
    <img src="images/soccer.jpg" alt="Me during a match">
    <h3>Soccer</h3>
    <p>I play forward for the youth team. 12 goals this year!</p>
  </div>
  <div class="card">
    <img src="images/minecraft-build.jpg" alt="My castle in Minecraft">
    <h3>Minecraft</h3>
    <p>I build huge castles. This one took a month.</p>
  </div>
  <div class="card">
    <h3>Coding</h3>
    <p>I'm building this very website right now. And this is just the start.</p>
  </div>
</div>
🌍 يوميات سفر – الحل (بطاقات الرحلات)
<h2>Our Trips</h2>
<div class="cards">
  <div class="card">
    <img src="images/mountains.jpg" alt="View from the summit">
    <h3>The Mountains</h3>
    <p>A three-day hike. Best part: wild berries and the lookout tower.</p>
  </div>
  <div class="card">
    <img src="images/sea.jpg" alt="A bay in Greece">
    <h3>Greece</h3>
    <p>A week at the beach. We saw dolphins!</p>
  </div>
  <div class="card">
    <img src="images/dc.jpg" alt="View from a monument in Washington, D.C.">
    <h3>Washington, D.C.</h3>
    <p>Museums, monuments, and way too much walking.</p>
  </div>
</div>
⚽ موقع النادي – الحل (بطاقات اللاعبين)
<h2>Roster</h2>
<div class="cards">
  <div class="card">
    <h3>Jake · goalkeeper 🧤</h3>
    <p>Team captain. 5 clean sheets this season.</p>
  </div>
  <div class="card">
    <h3>Owen · midfield ⚡</h3>
    <p>Fastest player on the team. 8 assists.</p>
  </div>
  <div class="card">
    <h3>Tom · forward 🎯</h3>
    <p>Top scorer. 14 goals this season.</p>
  </div>
</div>

نفس CSS يعمل لكل مشروع:

.cards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.cards .card {
  flex: 1;
  min-width: 200px;
}

.card {
  background-color: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

إضافة: معرض صور

لديك الكثير من الصور؟ شبكة صور أبسط – فقط استخدم aspect-ratio وobject-fit لإبقائها بنفس الحجم:

<div class="gallery">
  <img src="images/p1.jpg" alt="…">
  <img src="images/p2.jpg" alt="…">
  <img src="images/p3.jpg" alt="…">
  <img src="images/p4.jpg" alt="…">
</div>
.gallery {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.gallery img {
  width: 180px;
  aspect-ratio: 1;      /* a square */
  object-fit: cover;    /* the photo fills the square and gets cropped, not squished */
}

تحقق من نفسك: موقعك له بطاقات بظلال جنباً إلى جنب. صغّر نافذة المتصفح لعرض الهاتف – البطاقات تتراص. هذا responsive design، وأنت أنجزته للتو.

ما ستخرج به من هذا الدرس