Podcast
Questions and Answers
Which of the following is NOT a location where CSS style rules can be defined?
Which of the following is NOT a location where CSS style rules can be defined?
- Internal JavaScript File (correct)
- Embedded Style Sheet
- External Style Sheet
- Inline Styles
Inline styles are generally preferred for web development because they promote maintainability and reduce bandwidth usage.
Inline styles are generally preferred for web development because they promote maintainability and reduce bandwidth usage.
False (B)
What is the primary advantage of using external style sheets for web development?
What is the primary advantage of using external style sheets for web development?
maintainability
Style rules placed within an HTML element via the ______
attribute are known as inline styles.
Style rules placed within an HTML element via the ______
attribute are known as inline styles.
Which type of CSS is most efficient for styling multiple pages on a website?
Which type of CSS is most efficient for styling multiple pages on a website?
What is the purpose of CSS selectors?
What is the purpose of CSS selectors?
Embedded styles are ideal for consistently styling multiple HTML documents in a large website.
Embedded styles are ideal for consistently styling multiple HTML documents in a large website.
Match the CSS style location with its characteristic:
Match the CSS style location with its characteristic:
Which of the following statements best describes the use of RGBA in CSS?
Which of the following statements best describes the use of RGBA in CSS?
Absolute units of measurement are recommended for defining style sheets for printing.
Absolute units of measurement are recommended for defining style sheets for printing.
Which type of selector is most commonly used by web developers to select elements contained within another element?
Which type of selector is most commonly used by web developers to select elements contained within another element?
Explain the difference between relative and absolute units in CSS.
Explain the difference between relative and absolute units in CSS.
The ___
unit is equal to the computed value of the font-size property of the element on which it is utilized.
The ___
unit is equal to the computed value of the font-size property of the element on which it is utilized.
A child selector in CSS selects all elements that are descendants of a specified element, regardless of the level of nesting.
A child selector in CSS selects all elements that are descendants of a specified element, regardless of the level of nesting.
Which of the following CSS units is classified as an absolute unit in CSS3?
Which of the following CSS units is classified as an absolute unit in CSS3?
In CSS, what is the term used to describe selectors that target elements based on their relationship to other elements in the document tree?
In CSS, what is the term used to describe selectors that target elements based on their relationship to other elements in the document tree?
The ________ selector is used to select an element that is directly after another specified element.
The ________ selector is used to select an element that is directly after another specified element.
What is the primary purpose of the HSL color model in CSS?
What is the primary purpose of the HSL color model in CSS?
Which selector targets all paragraph <p>
elements that share the same parent as an <h3>
element?
Which selector targets all paragraph <p>
elements that share the same parent as an <h3>
element?
The '%' unit in CSS is always relative to another value.
The '%' unit in CSS is always relative to another value.
The descendant selector only selects elements that are direct children of the specified element.
The descendant selector only selects elements that are direct children of the specified element.
Match each CSS unit with its correct description:
Match each CSS unit with its correct description:
Match the CSS selectors with their descriptions:
Match the CSS selectors with their descriptions:
What does the CSS selector div > h2
target?
What does the CSS selector div > h2
target?
Which of the following is NOT a reason why conflicts occur in CSS?
Which of the following is NOT a reason why conflicts occur in CSS?
In CSS, the term 'Cascade' is used to describe what?
In CSS, the term 'Cascade' is used to describe what?
The visual metaphor of a mountain stream progressing downstream over rocks represents how HTML elements are rendered in a browser.
The visual metaphor of a mountain stream progressing downstream over rocks represents how HTML elements are rendered in a browser.
Which of the following is NOT one of the cascade principles that CSS uses to resolve conflicts?
Which of the following is NOT one of the cascade principles that CSS uses to resolve conflicts?
In CSS, many properties, such as font, color, list, and text properties, affect not only themselves but also their ______.
In CSS, many properties, such as font, color, list, and text properties, affect not only themselves but also their ______.
Which of the following categories of CSS properties are generally NOT inheritable?
Which of the following categories of CSS properties are generally NOT inheritable?
All CSS properties are inheritable by default.
All CSS properties are inheritable by default.
Match each CSS property type with its inheritance behavior:
Match each CSS property type with its inheritance behavior:
Which CSS property is not typically inherited by default?
Which CSS property is not typically inherited by default?
It is impossible to force inheritance of CSS properties that are normally not inheritable.
It is impossible to force inheritance of CSS properties that are normally not inheritable.
What CSS keyword can be used to make a non-inherited property become inherited?
What CSS keyword can be used to make a non-inherited property become inherited?
Using CSS, to force an element to inherit a normally non-inheritable property from its parent, you can set the property's value to __________.
Using CSS, to force an element to inherit a normally non-inheritable property from its parent, you can set the property's value to __________.
Given the following CSS:
`div {
font-weight: bold;
margin: 50px;
border: 1pt solid green;
}
p {
border: inherit;
margin: inherit;
}
`
If a <p>
element is nested inside a <div>
element, what will be the margin and border of the <p>
element?
Given the following CSS:
`div { font-weight: bold; margin: 50px; border: 1pt solid green; }
p { border: inherit; margin: inherit; } `
If a <p>
element is nested inside a <div>
element, what will be the margin and border of the <p>
element?
Which CSS property is inheritable by default?
Which CSS property is inheritable by default?
Specificity determines which style rule takes precedence when multiple rules could apply to the same element.
Specificity determines which style rule takes precedence when multiple rules could apply to the same element.
How does a browser determine which style rule takes precedence when multiple rules apply to the same element?
How does a browser determine which style rule takes precedence when multiple rules apply to the same element?
The more ______ the selector, the more it takes precedence.
The more ______ the selector, the more it takes precedence.
Given the following CSS:
body { color: red; }
div { color: magenta; }
p { color: green; }
What color will text within a <p>
element inside a <div>
element be?
Given the following CSS:
body { color: red; }
div { color: magenta; }
p { color: green; }
What color will text within a <p>
element inside a <div>
element be?
Which of the properties is non- inheritable in CSS by default?
Which of the properties is non- inheritable in CSS by default?
A style rule defined for the body
element will always override any conflicting styles defined for child elements.
A style rule defined for the body
element will always override any conflicting styles defined for child elements.
Match the CSS concepts with their descriptions:
Match the CSS concepts with their descriptions:
Flashcards
Pseudo Selectors
Pseudo Selectors
Selects elements based on their position in the document tree, like first-child or last-child.
Contextual Selectors
Contextual Selectors
Selects elements based on their relationship to other elements (ancestors, descendants, or siblings).
Descendant
Descendant
An element that is contained within another element, no matter how deeply nested.
Child
Child
Signup and view all the flashcards
Adjacent Sibling
Adjacent Sibling
Signup and view all the flashcards
General Sibling
General Sibling
Signup and view all the flashcards
Descendant Selector
Descendant Selector
Signup and view all the flashcards
Descendant Selector Example: div p
Descendant Selector Example: div p
Signup and view all the flashcards
RGBa
RGBa
Signup and view all the flashcards
HSL
HSL
Signup and view all the flashcards
Relative Units
Relative Units
Signup and view all the flashcards
Absolute Units
Absolute Units
Signup and view all the flashcards
em Unit
em Unit
Signup and view all the flashcards
% (Percentage) Unit
% (Percentage) Unit
Signup and view all the flashcards
ex Unit
ex Unit
Signup and view all the flashcards
ch Unit
ch Unit
Signup and view all the flashcards
CSS Style Locations
CSS Style Locations
Signup and view all the flashcards
Inline Styles
Inline Styles
Signup and view all the flashcards
Embedded Style Sheet
Embedded Style Sheet
Signup and view all the flashcards
External Style Sheet
External Style Sheet
Signup and view all the flashcards
Why use External Style Sheets?
Why use External Style Sheets?
Signup and view all the flashcards
CSS Selectors
CSS Selectors
Signup and view all the flashcards
CSS Selectors selection types.
CSS Selectors selection types.
Signup and view all the flashcards
CSS Rules
CSS Rules
Signup and view all the flashcards
Why CSS Conflict?
Why CSS Conflict?
Signup and view all the flashcards
Cascade in CSS
Cascade in CSS
Signup and view all the flashcards
Cascade Principles
Cascade Principles
Signup and view all the flashcards
Inheritance
Inheritance
Signup and view all the flashcards
Inheritable Properties
Inheritable Properties
Signup and view all the flashcards
Non-Inheritable Properties
Non-Inheritable Properties
Signup and view all the flashcards
CSS Inheritance
CSS Inheritance
Signup and view all the flashcards
Inherited vs. Non-inherited Properties
Inherited vs. Non-inherited Properties
Signup and view all the flashcards
Forcing Inheritance
Forcing Inheritance
Signup and view all the flashcards
Border Property
Border Property
Signup and view all the flashcards
Margin Property
Margin Property
Signup and view all the flashcards
Inheritable vs Non-Inheritable properties
Inheritable vs Non-Inheritable properties
Signup and view all the flashcards
CSS Specificity
CSS Specificity
Signup and view all the flashcards
Specificity Weight
Specificity Weight
Signup and view all the flashcards
Selector Specificity Examples
Selector Specificity Examples
Signup and view all the flashcards
Overriding Styles
Overriding Styles
Signup and view all the flashcards
Most specific selector styling
Most specific selector styling
Signup and view all the flashcards
Color example
Color example
Signup and view all the flashcards
Study Notes
CSS Introduction
- CSS is a W3C standard to describe the presentation of HTML elements
- CSS allows to assign font properties, colours, sizes, borders, background images, and the position of elements
- CSS is a language and can be added directly to any HTML element (via the style attribute) within the element, or in a separate CSS file
- Using CSS offers the ability to have degree of formatting control better than HTML, more accessible sites, faster download times, page adoption for different output mediums, and web sites that are significantly more maintainable
CSS Syntax
- A CSS document has style rules made of selectors, properties, and values
- A rule consists of a selector that identifies the HTML element or elements that will be affected, followed by property and value pairs called a declaration
- A series of declarations is also named the declaration block
- A declaration block can be together on a single line, or spread across multiple lines
- White space is ignored
- Each declaration is terminated with semi-colon
- Selectors tell the browser which elements in the HTML document will be affected
- Every CSS rule begins with a selector
- Thinking of selectors is that they are a pattern to select the HTML elements
- Each CSS declaration need a property
- CSS2.1 Recommendation has over a hundred property names
Commonly Used Properties
- Property types include:
- Fonts: Includes font, font-family, font-size, font-style, font-weight, and @font-face
- Text: Includes letter-spacing, line-height, text-align, text-decoration, text-indent
- Colour and Background: Includes background, background-color, background-image, background-position, background-repeat, and colour
- Borders: Includes border, border-color, border-width, border-style, border-top, border-top-color, border-top-width, etc.
- Spacing: Includes padding, padding-bottom, padding-left, padding-right, padding-top, margin, margin-bottom, margin-left, margin-right, and margin-top
- Sizing: Includes height, max-height, max-width, min-height, min-width, and width -Layout: Includes bottom, left, right, top, clear, display, float, overflow, position, visibility, and z-index
- Lists: Includes list-style, list-style-image, and list-style-type
Values
- Each CSS declaration contains a value for a property
- The unit of any given value is dependent upon the property
- Some values are from a predefined list of keywords
- Other values are length measurements, percentages, numbers without units, colour values and URLs
- CSS supports different ways of describing colours:
- Name: Using one of 17 standard colour names or one of 140 standard names in CSS3
- RGB: Using numbers between 0 and 255 to describe the Red, Green, and Blue values for the colour
- Hexadecimal: Using a six-digit hexadecimal number to describe the colour; hexadecimal number is preceded by a hash symbol (#)
- RGBa: To add an alpha or degree of transparency value; transparency is a value between 0.0 (fully) and 1.0 (opaque)
- HSL: To specify a colour using Hue Saturation and Light values
- Relative units are based on other elements whereas absolute units have a real-world size
- It is recommended not to use absolute units unless defining a style sheet for printing
- Pixel unit is a popular exception
- Types of relative units:
- px (pixel): Relative in CSS2, absolute in CSS3 at 1/96 of an inch
- em: Computed value of font-size; used in font sizes, it is in relation to the font size of the parent
- %: Measure relative to another value
- ex: Rarely used relative measure that is with x-height
- ch: Seldom used relative element related to the width of zero
- rem: Stands for root em, the font size of the root element,Unlike em, may be different for each element, rem is constant
- vw, vh: Stands for viewport width and viewport height; percentage values between 0 and 100 of browser that allows item to resize
- Absolute units of measure
- in (inches)
- cm (centimeters)
- mm (millimeters)
- pt (points which equals 1/72 of an inch)
- pc (pica equals 1/6 of an inch)
- It is helpful to add comments to style sheets which takes the form: "/* comment goes here */"
- To indicate that related style rules are together, and ways to hide a of rules, to with debugging
Location of Styles
- There are 3 types: author-created , user style sheet (custom), and browser style sheet (default)
- Author CSS style rules can be located in three different locations: Inline, Embedded and External
- Style rules can be combined and put in all 3 locations!
- Inline styles increase bandwidth and maintainability by placing them within the style attribute of HTML elements
- Embedded style sheets by and large discouraged and are style rules placed within the "" element inside the "" element
- External styles are located most commonly, as it provides the best maintainability, with style rules in a CSS extension. This format can update used documents with automated updates and performance through browser level caching of style sheets
Selectors
- The selector tells the browser which elements will have their style changed
- Allow the element to select individuals, HTML groups, elements that belong, or positioned
- Universal elements use HTML name
-
- is the universal element selector for selecting all elements.
- Select a group by separating element names with commas. This sensible way to decrease complexity by identical CSS rules into a single rule.
- Reset quickly remove browser defaults that often reduce browser level margin inconsistencies, line heights and font sizes, with rulesets that can be placed in their own CSS file
- Class selectors simultaneously aim different HTML elements through a series of labelled HTML attributes
- The targeting is by using class selector, a period (.) followed by name
- An ID selector targets by attribute to style using pound/hash (#) by the name
- Only use an ID once per page
- ID selectors should reference a single document and element in the same HTML element
- Class selectors are when referencing related elements
- An attribute selector is the presence of a value for either the element, attribute or its value
- Attribute selector are helpful in the use of in styling of hyperlinks and images
- A pseudo-element selects where there is existing HTML but that still needs identifiable structure
- A pseudo element applies either to HTML element state or to their relation
- The most common use is for targeting link states
- Contextual selectors CSS3 known as combinators, select the elements based on their relation tree
- Descendant selector matches element contained in another. The space character idicates this selection.
The Cascade, how styles interact
- Because there are three different types of style sheets (author-created, user-defined, and the default browser style sheet), author-created style sheets can define multiple rules for the same HTML element and can lead to conflicting style applications
- The Cascade refers to how the browser deals with conflict determination
- the cascade metaphor: of water moving down a mountain downstream as its the given property of a parents affects its children elements
- Cascade Principles help the browser with defaults and conflicts: inheritance specificity and location
- Inheritance is the ability for CSS to modify descendants with font colour list and text properties with sizes, border background and spacing property changes
- To control what can be inherited, there is the ability also an inherit keyword to force the inheritances of a tag
Specificity the 2cd Casacade principle
- How browser determines which style rule to precedence
- The more 'specific' the selecter the more the takes precedence
- Specificity assigns weight to rule
- Class selectors are are specific then and override an element selector in the HTML
- ID selecter are more specific and take precedence than class selector
- Algorithm that counts
- 1 if the declaration is from a style attribute in HTML 0 otherwise
- The count to the number of ID attributes
- And then, count the number of attributes of pseudo class selector
- Count the number of elements. Or pseudo elements
- Finally then concatenate the four numbers and calculate the difference
- Start the value at zero ad 100 for ID value at 10 for each class value at one selector for psedo attribute
- Principle of location says, latest will get more weight
The Box Model
- The box model describes all HTML elements within element boxes
- Background colour or images and border of elements will be in the code
- Commonly use CSS to display presentation images than elements
- Background property allows setting many of different style property options the shorthand
- Background attachment specifies image will scroll
- Repeating repeats an image
- Background size allows changing the size of image
- Borders creates visual element separation, with multiple ways to style
- There is the combine short hand
TRBL border usage notation
- Border, margin, padding properties, have both long and short form usage notation
- This allows for top, right, bottom and left properties assignment
- Margins and padding are model, the style rules affect spacing between element and other elements within the document
- If the spacing between paragraphs from, one to two is, in the fact that adjoining the vertical margins also have code impacts
Margin impact
- Vertical elements collapse into a single margin
- If they do not collapse margin of first and of would be 180
- Collapsing is due to vertical margins often largest taking the value
- The height and The width properties specfic size of elements content area
- only can be specified Block level elements such as images
Potential sizing
- The text has font size and font face impacts are of actual
- Text size is determined via the pixel measurements of dimension
Sizing considerations
- Default is total size that includes padding borders
- box-sizing: content-box, uses style dimensions
- box-sizing: border-box the opposite
- The properties allows what to di with overflow of dimensions if you need to change visibility, have it hidden, add scroll
- Sizing is the percentage of sizing
- Ems also
- Percentages are relative to parent elements and its size
- Ems or relative for the text or with its sizing of that text
Text Styling
- There are two forms that the text displays font's and paragraphs
- Fonts change different web fonts often in a web stack
- Selector allows you to use on fonts, though it may not come to your web
- Percents are relative scaling
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.