## CSS The class selector The class selector is a way to select all of the elements with the specified class name, and apply styles to each of the matching elements. Declare a CSS class by using a dot (.) followed by the class name. You make up the class name yourself. After the class name you simply enter the properties/values that you want to assign to your class. The browser will look for all tags in the page that have a class attribute containing that class name. **.class-name { property:value; }** If you want to use the same class name for multiple elements, but each with a different style, you can prefix the dot with the HTML element name. For example: **p.large { font-size: 2em;}** The class name can't contain a space, but it can contain hyphens or underscores. Any tag can have multiple space-separated class names. ### CSS ID Selectors The id selector is a way to select only the element with the specified id, and apply styles to that element. The selector must start with a pound sign (#) and then the value of the id attribute. The browser will then look for a tag in the page that has an id attribute equal to that id. The spelling and the casing must be exactly the same - #soongone is different from #SoonGone. The page should not have multiple tags with the same id every id should be unique. **#id-name { property:value; }** Again, similar to classes, if you want to use the same id name for multiple elements, but each with a different style, you can prefix the hash with the HTML element name. **p#intro { font-size: 2em; }** Note: ID applies to EVERY single thing with that specified element, while class applies only to the classes you gave to everything, so ID would make every h2 purple in ID for example, but class would only make the one h2 you gave the class to purple. ### CSS: The element selector The element selector is a way to select all the elements with a given tag name in a document, and apply the same styles to each element with the tag name. Note that you should only write the tag name, and not write brackets around the tag name — h1, not . ### CSS: The descendant selector The descendant selector is a way to select elements that are located somewhere underneath other elements, according to the tree structure of the webpage. This selector is actually multiple selectors combined together, but separated by a space. The first selector is the "ancestor", the element(s) that must be located higher in the tree, and the second selector is the "descendant", the element(s) that must be located somewhere underneath the ancestor in the tree. To understand ancestor/descendant relationships, you need to think about the webpage is a tree. ### Pseudo-classes A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, :hover can be used to change a button's color when the user's pointer hovers over it. /\* Any button over which the user's pointer is hovering \*/ **Button:hover{** **color:blue;** **}** Pseudo-classes let you apply a style to an element not only in relation to the content of the document tree, but also in relation to external factors like the history of the navigator (:visited, for example), the status of its content (like :checked on certain form elements), or the position of the mouse (like :hover, which lets you know if the mouse is over an element or not). A few common pseudo-classes are * :link * :visited * :hover * :active * :first-child * :nth-child Syntax: **selector: pseudo-class{** **property:value;** **}** ### Single Or Double Colon For Pseudo-Elements? The double colon (::) was introduced in CSS3 to differentiate pseudo-elements such as ::before and ::after from pseudo-classes such as :hover and :active. All browsers support double colons for pseudo-elements except Internet Explorer (IE) 8 and below. Some pseudo-elements, such as ::backdrop, accept only a double colon. ## Dynamic pseudo-classes These are the link-related pseudo-class states. Each of these states can be applied to an element, usually . They include, \:link - This only selects tags with href attributes. It will not work if it is missing. \:active - Selects the link while it is being activated (being clicked on or otherwise activated). For example, for the ―pressed‖ state of a button-style link. \:visited - Selects links that have already been visited by the current browser. \:hover - This is the most commonly used state. When the mouse cursor rolls over a link, that link is in its hover state and this will select it. Referring to index.html, it can like to change the background of
\