CSS Full Course for Beginners | Complete All-in-One Tutorial | 11 Hours
https://m.youtube.com/watch?v=Xc6G3oV24yE
CSS (Cascading Style Sheets), mainly used for HTML although possible to use for XML.
Three ways to apply style:
<link rel="stylesheet" href="/css/style.css">
<style></style>
in head, syntax exactly same as external.<p style="color: blue">
, better to prevent this for separation of concern.Final defined styles will override the previous one.
The previous one will only be persisted when specified as !important
, where should be prevented most of the time, as the code should have designed properly without overrules.
The W3C CSS Validation Service
Three common levels of selector:
p {…}
..toc {…}
, where in HTML, <nav class="toc">
. The ideal way, as more specific than generic element. A class can appear multiple times in HTML.#toc {...}
, where in HTML, <nav id="toc">
. Less ideal as too specific, where an ID should only appear once in HTML. ID is more useful for operations inside HTML/JS, not for CSS.Use <span class="...">...</span>
inline, for special inline styles.
h2 {
border-bottom: 1px solid #999;
}
.toc {
color: gray;
border: 1px solid #999;
}
p code {
/* All code inside paragraph will be blue */
color: blue;
}