{"id":3726,"date":"2023-07-18T00:58:22","date_gmt":"2023-07-18T00:58:22","guid":{"rendered":"https:\/\/nmi.cool\/advweb\/?page_id=3726"},"modified":"2025-08-29T23:43:36","modified_gmt":"2025-08-29T23:43:36","slug":"course-notes-css-intro","status":"publish","type":"page","link":"https:\/\/nmi.cool\/advweb\/unit-one-html-css\/week-two\/course-notes-css-intro\/","title":{"rendered":"Course Notes: CSS Intro"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\"><strong>SIMPLE SELECTORS<\/strong><\/h1>\n\n\n\n<p><strong>Element selectors<\/strong>: has no symbol, just the element name (<code>p<\/code>,&nbsp;<code>a,<\/code>&nbsp;<code>ul<\/code>,&nbsp;<code>li<\/code>,&nbsp;<code>h3<\/code>, etc), targets all elements of a given type<\/p>\n\n\n\n<p><strong>Class selectors<\/strong>: has a dot&nbsp;<code>.<\/code>&nbsp;followed by a class name, the class name can be anything but cannot have spaces, elements can have more than one class<\/p>\n\n\n\n<p><strong>ID selectors<\/strong>: has a pound&nbsp;<code>#<\/code>&nbsp;followed by an ID name of a given element, the ID name can be anything but cannot have spaces, each ID name must be unique within the document &#8211; unpredictable behavior occurs if multiple elements have the same ID<\/p>\n\n\n\n<p><strong>Universal selector<\/strong>: is the class name of a single star&nbsp;<code>*<\/code>&nbsp;that allows the selection of all elements in a page. Think twice before using this selector because its use in large web pages will make your page load slowly.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>ATTRIBUTE SELECTORS<\/strong><\/h1>\n\n\n\n<p><code>[attr]<\/code>&nbsp;selects all elements with the attribute [attr] whatever its value, name of the attr can be anything but cannot have spaces<\/p>\n\n\n\n<p><code>[attr=val]<\/code>&nbsp;selects all elements with the attribute [attr] but only if its value is val<\/p>\n\n\n\n<p><code>[attr~=val]<\/code>&nbsp;selects all elements with the attribute [attr] but only if val is one of a space-separated list of words contained in attr\u2019s value<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>PSEUDO-CLASSES &amp; PSEUDO-ELEMENTS<\/strong><\/h1>\n\n\n\n<p><strong>Pseudo-classes:<\/strong>&nbsp;how to edit how an element acts in a&nbsp;<em>certain state<\/em>, a colon \u2018:\u2019 and keyword following a selector (selector:keyword). Don\u2019t try to memorize all of the possible iterations, here are the ones you&#8217;ll use the most:<\/p>\n\n\n\n<p><code>a<\/code>&nbsp;{how the link will act while active]<\/p>\n\n\n\n<p><code>a:visited<\/code>&nbsp;{how the link will act after being clicked on}<\/p>\n\n\n\n<p><code>a:hover<\/code>&nbsp;{how the link will act while being hovered over with the cursor}<\/p>\n\n\n\n<p><code>a:active<\/code>&nbsp;{how the link will act while being clicked on}<\/p>\n\n\n\n<p><code>a:focus<\/code>&nbsp;{how the link will act when clicked on or while using tab to navigate page elements}<\/p>\n\n\n\n<p><strong>Pseudo-elements:<\/strong>&nbsp;how to select a certain part of an element, two colons \u2018::\u2019 and keyword following a selector ([element^=text::keyword) so selecting a specific type of element that\u2019s followed by specific text<\/p>\n\n\n\n<p><code>::first-letter<\/code>&nbsp;controls the first letter of a paragraph<\/p>\n\n\n\n<p><code>::first-line<\/code>&nbsp;controls the first line of a paragraph<\/p>\n\n\n\n<p><code>::selection<\/code>&nbsp;controls the part of a document that has been highlighted by the<\/p>\n\n\n\n<p>user<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>COMBINATORS AND GROUPS OF SELECTORS<\/strong><\/h1>\n\n\n\n<p><strong>Group of selectors<\/strong>&nbsp;(<strong>A, B<\/strong>) any element matching A and\/or B, separated with a comma because it\u2019s a list<\/p>\n\n\n\n<p><strong>Descendant combinatory<\/strong>&nbsp;(<strong>A B<\/strong>) any element matching B that is a child of an element matching A, nothing separating the elements because they\u2019re being combined<\/p>\n\n\n\n<p><strong>Child combinator<\/strong>&nbsp;(<strong>A &gt; B<\/strong>) any element matching B that\u2019s a&nbsp;<em>direct child<\/em>&nbsp;of an element matching A<\/p>\n\n\n\n<p><strong>Adjacent sibling combinatory<\/strong>&nbsp;(<strong>A + B<\/strong>) any element matching B that is the&nbsp;<em>next sibling&nbsp;<\/em>(next child of the same element) of an element matching A<\/p>\n\n\n\n<p><strong>General sibling combinatory<\/strong>&nbsp;(<strong>A ~ B<\/strong>) any element matching B that is one of the next&nbsp;<em>siblings<\/em>&nbsp;(next children *plural* of the same parent) of an element matching A<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>CSS VALUES AND UNITS<\/strong><\/h1>\n\n\n\n<p>Numeric values: specify an element\u2019s length, width, border thickness, or font size. The two numeric value units that are used:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>pixels (px)- absolute units, will always be the same size regardless of other settings. Used for margin, padding, etc border-width.<\/li>\n\n\n\n<li>(em) relative unit, 1em is the same as the font size of the current element. Example: could be used when creating a custom bullet to size to be scaled to fit the font size of the list<\/li>\n<\/ol>\n\n\n\n<p>Unit-less values: Used to completely remove the margin or padding of an element just use zero. Used to edit line height with the value acting as a multiplying factor. Also used to control the number of times an animation will play (animation-iteration-count).<\/p>\n\n\n\n<p>Percentages: specify an element\u2019s size relative to a parent container, percentage of their parent container\u2019s width, visual size will change as the window is resized<\/p>\n\n\n\n<p>Liquid layout- shifts as the browser viewport size changes, used to ensure that it will always fit the screen across various device screen sizes<\/p>\n\n\n\n<p>Fixed width layout- stays the same regardless<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>COLORS<\/strong><\/h1>\n\n\n\n<p><strong>Keywords<\/strong>&#8211; list of 165 different words that represent a color, pure colors such as red, blue, black, white, etc<\/p>\n\n\n\n<p><strong>Hexadecimal<\/strong>&#8211; can represent ANY color you want to use, consist of a pound symbol (#) followed by 6 hexadecimal numbers (values between 0 and f: 0123456789abcdef), pairs of values represent one of the color channels (red\/green\/blue) and the specific value out of all 256 available for each<\/p>\n\n\n\n<p><strong>RGB<\/strong>&#8211; rgb(_,_,_) function where each channel is represented by a decimal number 0-255<\/p>\n\n\n\n<p><strong>Opacity<\/strong>&#8211; the transparency of the selected element and its children<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>CASCADE AND INHERITANCE<\/strong><\/h1>\n\n\n\n<p><strong>CSS (Cascading Style Sheets)<\/strong>: cascade\/order of rules is key, what determines<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Importance&nbsp;<code>!important<\/code>&nbsp;this declaration will always win over all others, use sparingly<\/li>\n\n\n\n<li>Specify- how specific a selector is, or how many elements it&nbsp;<em>could<\/em>&nbsp;match\n<ul class=\"wp-block-list\">\n<li>High specificity= ID selector<\/li>\n\n\n\n<li>Mid specificity= class selector<\/li>\n\n\n\n<li>Low Specificity= element selectors<\/li>\n\n\n\n<li>Universal selector (*), combinator (+, &gt;, ~) have no effect on specificity<\/li>\n\n\n\n<li>Specificity goes down with the more elements it controls\/effects<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Source Order- if competing selectors have the same importance and specificity then source order decides which rule wins; source factor determines that a later rule wins over earlier rules<\/li>\n<\/ol>\n\n\n\n<p>Inheritance- some property values applied to an element will be inherited by that element\u2019s children and some wont, mainly common sense but you can <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_cascade\/Inheritance\" data-type=\"link\" data-id=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_cascade\/Inheritance\" target=\"_blank\" rel=\"noreferrer noopener\">find the list of which CSS rules get inherited<\/a>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>THE BOX MODEL<\/strong><\/h1>\n\n\n\n<p>Every element is structures within a rectangular box inside the document layout<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">BOX PROPERTIES<\/h4>\n\n\n\n<p>Content box- the actual content of the element (text, image, widget, etc)<\/p>\n\n\n\n<p>Width\/Height- set the width and height of the content box<\/p>\n\n\n\n<p><strong>Padding<\/strong>&#8211; the \u201cinner margin\u201d, space between the content box and the border<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Give one value to padding to effect all 4 sides of the box<\/li>\n\n\n\n<li><strong>padding-top<\/strong>,&nbsp;<strong>padding-right<\/strong>,&nbsp;<strong>padding-bottom<\/strong>,&nbsp;<strong>padding-left<\/strong>&nbsp;control each side separately<\/li>\n<\/ul>\n\n\n\n<p><strong>Border<\/strong>&nbsp;between the padding and the margin<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>default= zero (invisible)<\/li>\n\n\n\n<li>give a width, style, and color value to border to be applied to all 4 sides of the box<\/li>\n\n\n\n<li><strong>border-top,&nbsp;border-right<\/strong>,&nbsp;<strong>border-bottom<\/strong>,<strong>&nbsp;border-left<\/strong>&nbsp;control each side of the border separately<\/li>\n\n\n\n<li><strong>border-width<\/strong>&nbsp;controls the thickness of the border line<\/li>\n\n\n\n<li><strong>border-style<\/strong>&nbsp;controls the style, options: solid, dashed, dotted, double<\/li>\n\n\n\n<li><strong>border-color&nbsp;<\/strong>controls the color<\/li>\n<\/ul>\n\n\n\n<p><strong>Margin<\/strong>&#8211; surrounds the CSS box, space between the border and the next element\u2019s box<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Give one value to margin to effect all 4 sides of the box<\/li>\n\n\n\n<li><strong>margin-top<\/strong>,&nbsp;<strong>margin-right<\/strong>,&nbsp;<strong>margin-bottom<\/strong>, and&nbsp;<strong>margin-left&nbsp;<\/strong>control the different side margins separately<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">TYPES OF CSS BOXES<\/h4>\n\n\n\n<p><code>display: block<\/code>&nbsp;\/&nbsp;<code>inline<\/code>&nbsp;\/&nbsp;<code>inline-block<\/code><\/p>\n\n\n\n<p><strong>Block<\/strong>: defined as a box that\u2019s stacked upon other boxes<\/p>\n\n\n\n<p><strong>Inline<\/strong>: flows with the document text, will appear on the same line as surrounding text and will move text but cannot move block boxes, has line breaks<\/p>\n\n\n\n<p><strong>Inline-block<\/strong>: combination of inline &amp; block boxes, flows with surrounding text and inline elements but maintains the integrity of a block, it can be styled like block boxes, and does not break over lines<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>BACKGROUND CLIP<\/strong><\/h1>\n\n\n\n<p><strong>background-clip:<\/strong>&nbsp;sets whether an element\u2019s background color or image extends underneath its border<\/p>\n\n\n\n<p><strong>padding-box:<\/strong>&nbsp;background extends to the outer edge of the padding (but not underneath the border)<\/p>\n\n\n\n<p><strong>border-box:<\/strong>&nbsp;background extends to the outer edge of the border<\/p>\n\n\n\n<p><strong>content-box:<\/strong>&nbsp;background extends only within the content box<\/p>\n\n\n\n<p><strong>text:<\/strong>&nbsp;background paints the text itself<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SIMPLE SELECTORS Element selectors: has no symbol, just the element name (p,&nbsp;a,&nbsp;ul,&nbsp;li,&nbsp;h3, etc), targets all elements of a given type Class selectors: has a dot&nbsp;.&nbsp;followed by a class name, the class name can be anything but cannot have spaces, elements can have more than one class ID selectors: has a pound&nbsp;#&nbsp;followed by an ID name &hellip; <a href=\"https:\/\/nmi.cool\/advweb\/unit-one-html-css\/week-two\/course-notes-css-intro\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Course Notes: CSS Intro<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3686,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3726","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/nmi.cool\/advweb\/wp-json\/wp\/v2\/pages\/3726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nmi.cool\/advweb\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/nmi.cool\/advweb\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/nmi.cool\/advweb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nmi.cool\/advweb\/wp-json\/wp\/v2\/comments?post=3726"}],"version-history":[{"count":6,"href":"https:\/\/nmi.cool\/advweb\/wp-json\/wp\/v2\/pages\/3726\/revisions"}],"predecessor-version":[{"id":4376,"href":"https:\/\/nmi.cool\/advweb\/wp-json\/wp\/v2\/pages\/3726\/revisions\/4376"}],"up":[{"embeddable":true,"href":"https:\/\/nmi.cool\/advweb\/wp-json\/wp\/v2\/pages\/3686"}],"wp:attachment":[{"href":"https:\/\/nmi.cool\/advweb\/wp-json\/wp\/v2\/media?parent=3726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}