CSS block
Created By: chatGPT
A CSS block is a collection of rules that apply to a specific set of HTML elements. Blocks are defined using curly braces
{}
, and each rule consists of a property and a value, separated by a colon. To define a CSS block, you typically start with a selector, which indicates the HTML element or elements to which the styles will apply.selector {
property: value;
property: value;
}
For example, if you want to style all
<h1>
elements on a page, you would create a CSS block like this:h1 {
color: blue;
font-size: 24px;
margin-bottom: 20px;
}
This block tells the browser that every
<h1>
element should have a blue text color, a font size of 24 pixels, and a bottom margin of 20 pixels. CSS allows you to create even more complex styles by combining multiple selectors and using various properties..class-name, #id-name {
background-color: #f0f0f0;
border: 1px solid #ccc;
}
In this case, the CSS block targets both a class and an ID selector, applying a light gray background color and a border. Remember that keeping your CSS organized and readable is crucial for maintaining, updating, and debugging styles.
// Example of organized CSS
body {
font-family: Arial, sans-serif;
}
h1 {
color: blue;
}
p {
line-height: 1.5;
}