CC Assignement
CC Assignement
Below is a fully detailed explanation of each part of your CSS assignment — covering
definitions, types, uses, importance, and examples — suitable for turning into a document or
presentation.
A CSS rule is the fundamental unit in a CSS file that applies styles to HTML elements. It tells
the browser what to style and how to style it.
Selector: Determines which HTML element the rule will apply to (e.g.,
p, h1, .class, #id).
Property: A style attribute such as color, font-size, background, etc.
Value: The setting applied to that property (e.g., blue, 16px, red).
Importance:
2. CSS Elements
CSS elements are HTML elements that are targeted and styled using CSS rules.
Examples of HTML Elements Styled Using CSS:
Why it matters:
3. CSS Syntax
CSS syntax refers to the way CSS rules are written, which the browser interprets to apply
styles.
General Syntax:
selector {
property: value;
}
Example with Explanation:
h1 {
color: red;
text-align: center;
}
h1 is the selector
color: red; is a property-value pair
text-align: center; centers the heading text
Importance:
Syntax:
* {
margin: 0;
padding: 0;
}
Uses:
Importance:
Helps create a consistent starting point for styling across all browsers.
2. Type Selector
Definition:
Syntax:
p {
font-size: 16px;
}
Uses:
Importance:
3. Class Selector
Definition:
Importance:
4. ID Selector
Definition:
Syntax:
#header {
background-color: gray;
}
Uses:
Importance:
5. Grouping Selector
Definition:
Syntax:
h1, h2, h3 {
font-family: Arial;
}
Uses:
Importance:
6. Descendant Selector
Definition:
Syntax:
div p {
color: green;
}
Uses:
Importance:
7. Child Selector
Definition:
Syntax:
ul > li {
list-style: none;
}
Uses:
Syntax:
h1 + p {
color: red;
}
Uses:
Syntax:
h1 ~ p {
font-style: italic;
}
Uses:
Applies style to any siblings of the same parent that follow the selected element.
CSS applied directly within an HTML element using the style attribute.
Example:
<p style="color:blue;">This is blue text</p>
Uses:
Poor maintainability.
Violates separation of concerns.
2. Internal CSS
Definition:
CSS written inside a <style> tag in the HTML document’s <head> section.
Example:
<head>
<style>
p { color: red; }
</style>
</head>
Uses:
Drawbacks:
3. External CSS
Definition:
CSS stored in a separate file (e.g., styles.css) and linked via <link> tag.
Example:
<link rel="stylesheet" href="styles.css">
Uses:
Benefits:
Centralized styling.
Cleaner HTML code.
d) Describe CSS Comments, CSS Pseudo-classes, CSS Pseudo-
elements, and CSS Concepts
1. CSS Comments
Definition:
Syntax:
/* This is a comment */
Importance:
2. CSS Pseudo-classes
Definition:
Examples:
a:hover {
color: red;
}
Common Pseudo-classes:
Uses:
Syntax:
p::first-line {
font-weight: bold;
}
Common Pseudo-elements:
Uses:
4. CSS Concepts
Importance:
b) Display Property
Uses:
d) CSS Units
Importance:
f) CSS Variables
:root {
--main-color: #ff0000;
}
p {
color: var(--main-color);
}
Benefits: