Basic Concepts CSS
Basic Concepts:
Cascading Style Sheets (CSS): It's a declarative language that controls the visual presentation of web pages in a browser. It allows defining the style and layout of HTML elements on a page.
Style Declarations: A style declaration in CSS contains properties and their values. These properties determine the visual appearance of elements on the page.
CSS Rule: A CSS rule is a set of properties associated with a selector. The selector is used to identify the elements to which the rule applies.
Example CSS Rule:
CSS Comment: Starts with /* and ends with */. Comments in CSS are for providing explanations or documentation but do not affect the styles.
Selector (highlight): The selector specifies the HTML elements that the rule will apply to. In this case, the .highlight selector targets all elements with the class "highlight".
Style Declarations: Style declarations are enclosed in curly braces { }. Each declaration consists of a property, a colon (:), and a value. In this example:
- color: red;: Sets the text color to red.
- border: 2px solid blue;: Adds a border around the element. It's a 2-pixel wide border that is solid and colored blue.
Cascading:
The term "cascading" refers to the idea that multiple rules can affect the same element, and the browser needs to decide which rule should take precedence. The cascade is controlled by factors such as selector specificity, importance, and rule definition order.
Conclusion:
The given example styles all paragraphs in an HTML document, making the text yellow on a black background. Understanding how CSS rules are applied and how the cascade works is crucial for efficiently controlling the appearance of a web page.
Comments
Post a Comment