Css Syntax

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CSS SYNTAX

SYNTAX:
/* This is a CSS comment */
/* Selectors and Declarations */
selector {
property: value;
}

/* Example: Styling a Heading */


h1 {
color: blue;
font-size: 24px;
}

/* Example: Styling a Paragraph */


p{
color: #333;
font-family: 'Arial', sans-serif;
}

/* Example: Styling a Class */


.my-class {
background-color: #f0f0f0;
padding: 10px;
}

/* Example: Styling an ID */
#my-id {
border: 1px solid #ccc;
margin: 20px;
}

/* Example: Styling a Specific Element within a Class */


.my-class li {
list-style-type: square;
}

/* Grouping Selectors */
h2, h3 {
font-weight: bold;
}

/* Pseudo-classes and Pseudo-elements */


a:hover {
text-decoration: underline;
}
/* Media Queries */
@media (max-width: 768px) {
body {
background-color: #f9f9f9;
}
}

Let's break down the components:

 /* This is a CSS comment */: Comments in CSS are enclosed in /* */ and are used
for adding notes or explanations within the stylesheet.
 selector: Selects HTML elements to apply styles to.
 { }: The curly braces enclose a block of CSS declarations.
 property: value;: Each declaration consists of a property and its corresponding value.

Examples:

 color: blue;: Sets the text color to blue.


 font-size: 24px;: Sets the font size to 24 pixels.
 background-color: #f0f0f0;: Sets the background color using a hexadecimal color
code.
 padding: 10px;: Adds padding around an element.
 border: 1px solid #ccc;: Adds a border with a 1-pixel width and a solid style.

Selectors:

 h1: Selects all <h1> elements.


 .my-class: Selects all elements with the class my-class.
 #my-id: Selects the element with the ID my-id.
 .my-class li: Selects all <li> elements within an element with the class my-class.

Pseudo-classes and Pseudo-elements:

 a:hover: Selects an <a> (link) element when the user hovers over it.

Media Queries:

 @media (max-width: 768px): Applies styles only when the viewport width is 768 pixels
or less.
This is a basic overview of CSS syntax. CSS is a powerful styling language, and its syntax
allows for a wide range of styling options to create visually appealing and responsive
designs.

You might also like