CSS Syntax, Selector, Comments, Colors and Background
CSS Syntax, Selector, Comments, Colors and Background
CSS Syntax:
- Syntax consists of selectors and declaration blocks. Selectors are simply used to select the HTML
element to be styled. Declaration consists of a set of instructions which tell the browser how to style the
HTML elements. Selectors tell "where to do" and declarations tell the browser "what to do"
Example:
1. choosing a paper-selection
Declarations are properties and values followed by semicolons and enclosed with curly brackets.
2. Selectors:
- Declaration Blocks: Consist of one or more declarations enclosed in curly braces `{}`. Each declaration
includes a property and its corresponding value.
3. Comments:
- Purpose: Used for documenting code, adding notes, or temporarily disabling styles.
4. Colors:
Colors are integral part of any web application. Colors in CSS can be specified in the following ways:
- CSS supports various color formats like hexadecimal (Hex) valus, RGB, RGBA, HSL and named colors.
-Named Colors: CSS supports predefined color names such as `red`, `blue`, `green`, etc. The total number
of color names supported in CSS is 140.
Hexadecimal (hex) values: Represent colors using a combination of six hexadecimal digits. Each pair
represents the intensity of red, green, and blue, respectively. It is written in the following format:
#RRGGBB. Where RR, GG and BB are values between 00 and FF.
RR-amount of red
GG-amount of green
BB-amount of blue
How far is a number between 0.0 (fully transparent) and 1.0 (fully opaque)
For red green and blue 0 depicts the lowest intensity and 255 the highest.
- HSL (Hue, Saturation, Lightness): Specify colors based on their hue, saturation, and lightness. Hue is
represented as an angle (0 to 360), saturation and lightness are percentages.
5. Background:
- Used to set background properties of elements.
- Background Repeat: Defines how the background image should be repeated, options include `repeat`,
`repeat-x`, `repeat-y`, and `no-repeat`.
- Background Attachment: Specifies whether the background image scrolls with the content or remains
fixed.