CSS & HTML tips
CSS
Background
1 | body { |
is the shorthand for:
1 | body { |
It does not matter if one of the property values is missing, as long as the other ones are in this order.
Link LVHA rule
a:link
- a normal, unvisited linka:visited
- a link the user has visiteda:hover
- a link when the user mouses over ita:active
- a link the moment it is clicked
When setting the style for several link states, there are some order rules:
a:hover
MUST come aftera:link
anda:visited
a:active
MUST come aftera:hover
inline-block
Center text in div
Using flexbox:
1 | <div class="box"> |
window.onload vs document.onload
window.onload
:By default, it is fired when the entire page loads, including its content (images, CSS, scripts, etc.).
In some browsers it now takes over the role of document.onload and fires when the DOM is ready as well.document.onload
: It is called when the DOM is ready which can be prior to images and other external content is loaded.
In chrome, console.log(document.onload)
returns null. So just use window.onload
.
Block formatting context
HTML
XHTML
- A term that was historically used to desribe HTML documents written to conform with XML syntax rules.
HTML document:
1 | <!-- Content-Type: text/html --> |
1 | <!-- Content-Type: application/xhtml+xml --> |
- XHTML is stricter, must be ‘well-formed’
- Was developed to make HTML more extensible and flexible with other.
- XHTML is friendly to machine, so it is easier to parse and analyze, good for SEO and screen readers.
- In comparison with XHTML, HTML is more ‘presentation based’.
- Read this for further details.
CSS & HTML tips