topskill.dev
CoursesTracks
0
All courses/CSSCSS Selectors Target Exhibit Details
CSS Foundations
3 / 10
← CSS
○CSS Rule Style an Exhibit Card○Write Your First CSS Rule●CSS Selectors Target Exhibit Details○Target Exhibit Details○Apply CSS Three Sources○Apply CSS Three Ways○Specificity Resolve a Style Conflict○Resolve Specificity○Inheritance and the cascade✦Module Quiz
○Color Palette○Color Palette○Background Layer○Background Layer○Type Rhythm○Type Rhythm○Borders and Shadows○Borders and Shadows✦Module Quiz
○Box Model Seed Packet Card○Space a Seed Packet○Display Swap Table Labels○Arrange Swap Table Labels○Positioning Pickup Pin○Pin the Pickup Location○Sizing and Overflow○Size a Seed-Swap Notice○Sticky scroll headings✦Module Quiz
○Advanced Selectors Book Cart Sign○Target a Book Cart Sign○Pseudo-Classes Night Cart States○Style Night Cart States○Pseudo-Elements○Add a Book-Quote Mark✦Module Quiz
○Lantern Market navigation○Lantern Market navigation✦Module Quiz
○Community garden request card○Community garden request card✦Module Quiz
○Flex Direction○Flex Direction○Main-Axis Spacing○Main-Axis Spacing○Cross-Axis Alignment○Cross-Axis Alignment○Wrapping and Flex Items○Wrapping and Flex Items○Flexbox Navigation○Flexbox Navigation✦Module Quiz
○Grid Tracks○Grid Tracks○Grid Gaps○Grid Gaps○Grid Placement○Grid Placement○Responsive Grid○Responsive Grid✦Module Quiz
○River radio schedule○Harbor radio schedule✦Module Quiz
○Field note color system○Field note color system○Transforms○Rotate a Field Note○Resilient styles✦Module Quiz
○Kite festival signal○Garden festival signal✦Module Quiz
○Garden forecast○Harbor forecast○Fluid sizing○Fluid weather bulletin○Images that fit✦Module Quiz
○Seed inventory table○Tool checkout table✦Module Quiz
○Community maker profile○Maker profile sheet✦Module Quiz

CSS Selectors Target Exhibit Details

Choose which elements change

The Moon Jelly card has two paragraphs, but only one is a care note. A selector lets you choose how widely a rule applies. Look at the tags and attributes in index.html before opening style.css.

css
p { line-height: 1.6; }
.note { background-color: #fff4cc; }
#specimen-title { color: #7a1fa2; }

p is an element selector: it matches both paragraphs. line-height sets the height of each text line. A unitless 1.6 makes it 1.6 times the element's font size, separating the lines in the longer paragraph.

.note is a class selector. The dot means “match elements whose class list includes the name note”; the HTML uses class="note", without a dot. Classes can be reused. Here the class rule paints only the care note yellow. Its supplied padding adds space around the words inside that background.

#specimen-title is an ID selector. It matches id="specimen-title" on the heading. Use an ID for one unique element in a document. The # here belongs to a selector; the # in the color value introduces a hex color code.

Try the selection

Run the page. Both paragraphs have the line-height rule, but only the care note is yellow. Change .note to p in the background rule and Run again: both paragraphs gain that background. Restore .note before the Sea Star exercise.

Hint 1
1 / 1
HINT 1

This completed example is for reading and previewing before the exercise.

Files
  • ⋄index.html
  • ⋄style.css
Loading editor…