CSS Flashcards
What is CSS?
CSS is a language for specifying how documents are presented to users.
How does CSS affect documents?
We browsers apply CSS rules to a document to affect how they are displayed.
What is a document?
Usually a text file structured using a markup language like HTML, SVG or XML.
From what is formed a CSS rule?
A CSS rule is formed from:
- A set of properties, which have values set to update how the HTML content is displayed.
- A selector, which selects the element(s) you want to apply the updated properties values to.
How does the browser combine a document’s content with its style information?
- The browser converts HTML and CSS into the DOM, representing the document in the computer’s memory.
- The browser displays the content of the DOM.
What are the 3 different ways to apply CSS to the HTML?
- External stylesheet ==> advised: referenced with < link rel=”stylesheet” href=”path/to/css” >
- Internal stylesheet: place the CSS rules within a < style > element.
- Inline styles affecting one element only: < element style=”CSS properties…” >
How is formed a CSS rules?
- A property paired with a value is called a CSS declaration.
- CSS declarations are put within CSS declaration blocks.
- CSS declaration blocks are paired with selectors to produce CSS rules.
What happens if a property is unknown or a value is invalid for a given property?
The declaration is deemed invalid and is ignored by the browser’s CSS engined.
What is the standard spelling for CSS?
US spelling.
What happens if a single selector in a chain or group of selectors is invalid?
The group of selectors is still valid, except for the invalid selector.
What are “at-rules” or @ rules?
They are used in CSS to convey metadata, conditional information or other descriptive information.
What about the syntax and semantics of @ rules?
Each type of @ rule has its own internal syntax and semantics.
What are nested statements?
Nested statements are a specific subset of @ rule, the syntax of which is a nested block of CSS rules that will only be applied to the document if a specific ocndition is matched.
What are the different types of @ rules used with nested statements?
- @media: content is applied only if the device which runs the browser matches the expression.
- @supports: content is applied only if the browser actually supports the tested feature.
- @document: content is applied only if the current page matches some condition.
What does one need to be careful with whitespaces when within CSS?
Whitespaces around the properties and their values ==> margin: 0 auto; is right and margin: 0auto; is wrong.
How to write comments in CSS?
Comments start with /* and end with */.
What are shorthand properties?
Properties that allow to set several property values in a single line.
What are the different types of selectors?
- Simple selectors.
- Attribute selectors.
- Pseudo-classes.
- Pseudo-elements.
- Combinators.
- Multiple selectors.
What is a simple selector?
A selector that matches one or more elements based on element:
- type: h1 { … }
- class: .className { … } ==> Note the .
- id: #someID { … } ==> Note the #
What is a attribute selector?
A selector that matches one or more elements based on their attributes/attribute value. Their generic syntax consists of square brackets [] containing an attribute name foolowed by an optional condition to match against the value of the attribute.
What is a pseudo-class selector?
A selector that matches one or more elements that exist in a certain state.
What is a pseudo-element selector?
A selector that matches one or more parts of content that are in a certain position in relation to an element.
What are combinators?
A mean to combine two or more selectors for even more specific selections.
How can you apply the same CSS rule to multiple selectors without rewriting it multiple times?
Put these multiple selectors separated by a comma as you would you with one selector.
What is a class name?
A class name is any value, without spaces, placed within an HTML class attribute.
What is the relationship between elements and class values?
- Multiple elements can have the same class value.
- A single element can have multiple class values separated by white spaces.
What is an ID for elements?
It is a unique ID name set with the id attribute. It is the most efficient way to select a single element.
What does the universal selector (*) do?
It selects all elements in a page. often used in combination with other selectors. Not advised in general because of its impact on performance.