בחירת הילד האחרון
חלק מהיחידה שליטה ב-CSS במסלול ה-HTML של Coddy. שיעור 14 מתוך 43.
הפסאודו־מחלקה :last-child בוחרת רכיבים שהם הילד האחרון של ההורה שלהם.
לדוגמה:
<div class="parent">
<p>First paragraph</p>
<p>Middle paragraph</p>
<p>Last paragraph</p>
</div>כדי לעצב רק את הפסקה האחרונה, השתמשו במחלקה המדומה :last-child:
p:last-child {
color: red;
font-weight: bold;
}לאחר החלת CSS זה, רק "Last paragraph" יהיה אדום ומודגש, כי הוא הילד האחרון של רכיב ה־div האב.
אתגר
קלצרו כלל CSS לעיצוב רכיב <p> האחרון בכל קבוצת פסקאות.
- עצבו אותו עם צבע רקע כחול (#046ae0) וטקסט לבן .
- הגדירו את עובי הגופן של הפסקה האחרונה למודגש.
נסו בעצמכם
<!DOCTYPE html>
<html>
<head>
<title>Targeting the Last Child</title>
<style>
/* Write your CSS rule here */
</style>
</head>
<body>
<div>
<h2>Exploring the Universe</h2>
<p>The universe is vast, with countless stars and galaxies waiting to be discovered.</p>
<p>New technologies allow us to explore deeper into space, revealing its many secrets.</p>
<p>We continue to learn more about distant planets and the possibility of life beyond Earth.</p>
</div>
<div>
<h2>The Deep Ocean</h2>
<p>Our oceans are mysterious, covering most of Earth, yet we know so little about them.</p>
<p>Many species live in extreme conditions, some of which are still being discovered today.</p>
<p>Exploring the ocean depths gives us insights into life at the planet's most remote locations.</p>
</div>
</body>
</html>השיעור הזה כולל חידון קצר. התחילו את השיעור כדי לענות עליו ולעקוב אחרי ההתקדמות.
כל השיעורים ביחידה שליטה ב-CSS
3פסאודו־מחלקות מבניות
פסאודו־מחלקות מבניותבחירת הילד הראשוןבחירת הילד האחרוןכוחם של דפוסים: שימוש ב־nth-childאתגר סיכוםתרגלו בעצמכם: Web אונליין