- Name the three ways to add CSS. Which is best for a large site, and why?
- Rank these by specificity:
p,.note,#title, inline style. - What is the difference between
:hoverand::before? - What does
box-sizing: border-boxdo? - Write a media query that turns the background grey on screens narrower than 600px.
- Which Flexbox property centres items along the main axis? Along the cross axis?
- What does
col-12 col-md-4mean in Bootstrap?
Show answers
Inline (
styleattribute), internal (<style>in the head) and external (a.cssfile linked with<link rel='stylesheet'>). External is best for a large site: one file styles every page, so a change is made once; the browser caches it so pages load faster; and content (HTML) stays separate from presentation (CSS).From highest to lowest: inline style (1,0,0,0) โ **
#title(ID, 0,1,0,0) โ.note(class, 0,0,1,0) โp** (element, 0,0,0,1).!importantoverrides all of these, but avoid it.:hoveris a pseudo-class: it selects an existing element when it is in a certain *state* (the mouse is over it).::beforeis a pseudo-element: it creates a virtual *part* (generated content) as the first child of the element, and it needs acontentproperty to appear.It makes
widthandheightinclude the padding and border. With the defaultcontent-box, awidth: 300pxbox with20pxpadding and a2pxborder is actually 344px wide; withborder-boxit stays 300px, which makes layouts much easier to calculate.- CSS
@media (max-width: 599.98px) { body { background: grey; } }max-width: 600pxis also accepted in exams; it includes exactly 600px as well. justify-content: centercentres items along the main axis (horizontal forflex-direction: row).align-items: centercentres them along the cross axis (vertical for a row). Both are set on the flex container.The element takes all 12 columns (full width) on extra-small and small screens, and 4 of 12 columns (one third of the row) from the
mdbreakpoint (768px) and wider. Three such columns sit side by side on a tablet or desktop and stack on a phone.