CSS (Cascading Style Sheets) Flashcards
CSS rule
A web developer uses CSS to write a list of rules. A CSS rule consists of a selector followed by a declaration block between braces ({ }).
CSS selector
A CSS selector specifies the HTML elements to which the specific style rule applies.
declaration block
A declaration block contains one or more declarations separated by semicolons (;).
declaration
A CSS styling declaration is a CSS property followed by a colon (:) and the property value.
inline style
An inline style places CSS declarations inside a tag’s style attribute.
embedded stylesheet
An embedded stylesheet places CSS rules in an HTML document’s head using <style> tags.</style>
external stylesheet
An external stylesheet places CSS rules in a separate file that is imported into an HTML document with a <link></link> tag.
element selector
The element selector matches elements with the specified element names.
Ex: p { color: blue; } selects all p elements.
class selector
The class selector, specified with a period character followed by the class name, matches elements that have the specified class name.
Ex: .notice { color: blue; } selects all elements with a class=”notice” attribute.
ID selector
The ID selector, specified with a hash character followed by the ID name, matches the element that has the specified ID.
Ex: #byLine { color: blue; } selects the element with the id=”byLine” attribute.
descendant selector
The descendant selector, specified with a selector followed by a space and another selector, matches elements that are contained in other elements.
Ex: h2 em { color: blue; } selects em elements contained in h2 elements.
pseudo-class selector
The pseudo-class selector, specified with a colon character followed by a pseudo-class name, matches elements based on user behavior or element metainformation.
Ex: :hover { color: blue; } selects elements under the mouse cursor.
class attribute
An HTML tag’s class attribute specifies the classes to which the tag belongs, with each class name separated by a space. Ex: <span> has two classes, highlight and first. While HTML elements’ IDs are unique, many elements may use the same HTML class name.</span>
universal selector
The universal selector, specified using an asterisk character (*), matches all elements in the web page. The universal selector is implied when an element name is not specified. Ex: The CSS selectors .highlight and *.highlight match exactly the same elements, where the universal selector is implied in .highlight and explicit in *.highlight.
multiple selector
The multiple selector, specified using a comma (,) to separate selectors, matches all listed elements to apply a style rule. Ex: ul, ol {
background-color: gray;
color: white;
font-weight: bold;
}
child selector
The child selector, specified using a greater than character (>) between two selectors, matches any elements where the second element is a direct child of the first element.
Sibling elements
Sibling elements are elements that share the same parent element.
general sibling selector
The general sibling selector, specified using a tilde character (~) between two selectors, matches the second element if the second element occurs after the first element and both elements are siblings.
adjacent sibling
The adjacent sibling selector, specified using a plus character (+) between two selectors, matches an element that immediately follows another element, where both elements have the same parent. Ex: The adjacent selector h1 + p in the figure below matches the first paragraph immediately following the <h1> header element, where both the paragraph and heading share the same section element parent.
attribute selector
The attribute selector, specified with an attribute name and optional value comparison enclosed in square brackets ([ and ]), matches elements with the specified attribute or the specified attribute and value. Ex: a[target] selector matches anchor elements with a target attribute specified.
pseudo element selector
The pseudo element selector, specified with two colon characters (::) followed by a pseudo-element, matches parts of elements. The pseudo-element selectors allow styles to apply to the first line or first letter of text of an element or to text that is selected by the user, or allow additional content to be inserted before or after an element.
::after
Add content after the matched element. li::after { content: “<” }
::before
Add content before the matched element. li::before { content: “***” }
::first-line
Match the first line of text in a block element. p::first-line { color: red }