CSS Flashcards
Explain the CSS “box model” and the layout components that it consists of.
Provide some usage examples.
The CSS box model is a rectangular layout paradigm for HTML elements that consists of content, padding, border, and margin.
How would you select every <a> element whose href attribute value begins with “https”?</a>
a[href^=”https”]
How would you select every <a> element whose href attribute value ends with “.pdf”.</a>
a[href$=”.pdf”]
How would you select every <a> element whose href attribute value contains the substring “css”.</a>
a[href*=”css”]
How would you add automatic numbering to headers?
#page { counter-reset: heading; }
h1:before {
content: counter(heading)”) “;
counter-increment: heading;
}
h1 {
counter-reset: subheading;
}
h2:before {
content: counter(heading)”.” counter(subheading)”) “;
counter-increment: subheading;
}
What is the difference between position:relative
and position:absolute
?
The word relative in position:relative
means that it is “relative to itself”. If you put position:relative
on an element it will not affect it’s positioning at all. It will remain exactly as it would be if you left it as the default state. At this point you are able to move the element in any direction from it’s original position using top:
, right:
, bottom:
and left:
. position:relative
also introduces the ability to us z-index
, which decides which elements overlap others.
If you want to place an element wherever you want it, you might use position:absolute
. The first thing that happens is that the element will be removed from the flow of elements on the page. Using position:absolute
you can now position the element anywhere relative to the next parent of the element that has position:relative
(or absolute
). You position the element using top:
, right:
, bottom:
and left:
. position:absolute
also brings z-index
into play.