Today's class covered CSS Selectors and styling techniques. No in-class coding activity - just lecture and Quiz 1.
Slides: CSS Selectors Presentation
p { } - targets all elements of that type.alert { } - targets elements with that class#navbar { } - avoid using (too specific)h2, .alert, #navbar { } - same styles to multiple selectorsp.alert { } or .alert.success { } - must match bothheader p { } - any p inside headerheader > p { } - direct children onlyli:hover { }, li:focus { } - interactive statesRule: If two rules apply, the more specific rule wins.
Best Practice: Be as general as you can, but as specific as you need to be.
2em = 2x parent size2rem = 2x root size (usually 32px)50% = half of parentBest Practice: Use rem or em instead of px for accessibility.
display: inline - flows with text, can't set width/heightdisplay: block - takes full width, starts new linedisplay: inline-block - inline flow but can set dimensionsIdeal for centering elements and creating column layouts.
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.child {
flex-grow: 1;
}
Note: Don't use Flexbox for simple stacking or spacing that browsers handle by default.
Name classes by their purpose:
.forum-post, .side-nav, .avatar-icon, .breaking-newsName classes by function, combine multiple:
.font-large, .bg-secondary, .small, .roundedPattern: block__element--modifier
<form class="form form--theme-xmas form--simple">
<input class="form__input" type="text">
<input class="form__submit form__submit--disabled" type="submit">
</form>