5. CSS Fundamentals Flashcards
A CSS ____ consists of a selector followed by a declaration block between braces ({})
rule
A CSS ____ specifies the HTML elements to which the specific style rule applies
selector
A ____ contains one or more declarations separated by semicolons (;)
declaration block
A CSS styling ____ is a CSS property followed by a colon (:) and the property value
declaration
What are the three ways that CSS can be applied to HTML?
- inline style (CSS declarations are placed inside of an elements “style” attribute)
- embedded stylesheet (places CSS rules in an HTML document’s head using a <style> element)
- external stylesheet (places CSS rules in a separate file that is imported into an HTML document with a <link> element)
The style declarations from a parent element ____ down and are applied to any child elements, a concept called ____
cascade, inheritance
When a style conflict occurs between a parent element and a child element, which styling takes precedence?
The child element’s styling
When a style conflict occurs between an embedded or external stylesheet and an inline style, which styling takes precedence?
The inline style
What are the three different types of CSS selectors, and how are they written?
- element selector
p { color: blue; } - class selector
.notice { color: blue; } - id selector
#byLine { color: blue }
How do you specify an element’s class in HTML?
<p class=”gr”>Moon</p>
How do you indicate that an element belongs to more than one class?
<span class=”highlight first”>
The space separates the two class names
How do you specify an element’s id in HTML?
<p id=”second”>Blade Runner</p>
** An id can only be used in a single element, whereas a class can be used in multiple elements
What is a descendant selector? How is it written, and what does it do?
It matches elements that are contained in other elements.
It is written as a selector followed by a space followed by another selector.
Example:
h2 em { color: blue; }
The ____ selector matches elements based on user behavior or element metainformation
pseudo-class
How is a pseudo-class selector written?
Element followed by a colon followed by a pseudo-class
a:hover {
}
How can you write a selector that selects only elements that have a particular class?
Element followed by a period followed by the class name
span.highlight
What are some common pseudo-classes?
:disabled - Element is disabled
:hover - Mouse is hovering over element
:empty - Element has no child elements
:lang(language) - Element contains text in a specified language
:nth-child(n) - Element is the parent element’s nth child
The ____ selector matches all elements in the webpage.
universal
How is the universal selector specified?
With an asterisk
*.highlight
The universal selector is implied when an element name is not specified.
The ____ selector matches all listed elements to apply a style rule.
multiple
How is a multiple selector specified?
With a comma separating selectors
ul, ol {
background-color: gray;
}
The ____ selector matches any elements where the second element is a direct child of the first element.
child
How is the child selector specified?
With a greater than sign
p > em {
background-color: yellow;
}
How is the child selector (>) different from the descendant selector ( )?
The matching child element in the child selector must be a direct child of the matching parent element.
____ elements are elements that share the same parent element.
Sibling
The general sibling selector is specified with the ____ character between two selectors, and it matches the second element if the second element occurs ____ the first element and both elements are ____.
~, after, siblings
h1 ~ p {
border-top: 1px solid gray;
}
Any number of other elements can be placed between two general sibling elements
The ____ sibling selector, specified using a ____ character between two selectors, matches an element that ____ follows another element, where both elements have the same parent
adjacent, plus (+), immediately
____ are CSS selectors that match specific relationships between other selectors.
Combinators
The descendant, child, adjacent sibling, and general sibling selectors are all combinators
What type of selector is the following?
a[target=”_blank”]
Attribute selector
The attribute selector can be more specific by matching elements with attributes having a specific value. Ex: a[target=”_blank”] attribute selector matches anchor elements with a target attribute value of _blank.
Which attribute selector comparator matches an element when its attribute has the exact value specified?
=
[target=”_blank”]
Which attribute selector comparator matches an element when the attribute contains the whole word specified?
~=
[alt~=”sad”]
Which attribute selector comparator matches an element when the attribute begins with a value?
^=
[class^=”nav”]