CSS
CSS
CSS
Here's a quick overview of the **basics of CSS** (Cascading Style Sheets), which is
used to style HTML documents.
---
CSS controls the appearance of HTML elements on a webpage. It allows you to apply styles
like colors, fonts, layouts, and spacing to create visually appealing web pages. You can link
a CSS file to an HTML file or include CSS directly in the HTML file.
---
CSS is written in rulesets, where each ruleset consists of a **selector** and **declaration
block**.
```css
selector {
property: value;
```
```html
```
- **Internal CSS**: Styles placed inside the `<style>` tag in the `<head>` of an HTML
document.
```html
<style>
p{
color: red;
</style>
```
- **External CSS**: Styles written in a separate `.css` file linked to the HTML file.
```html
---
```css
p{
color: blue;
background-color: yellow;
```
- **Fonts**
```css
h1 {
font-size: 24px;
font-weight: bold;
```
- **Text Styling**
```css
p{
text-align: center;
text-decoration: underline;
```
- **Spacing**
```css
div {
margin: 10px;
padding: 20px;
```
---
```css
p{
color: red;
```
- **Class Selector**: Targets elements with a specific class (use `.` before the class
name).
```css
.highlight {
background-color: yellow;
```
- **ID Selector**: Targets a specific element with a unique ID (use `#` before the ID name).
```css
#header {
font-size: 20px;
}
```
```css
*{
font-family: Arial;
```
- **Descendant Selector**: Targets elements that are nested inside other elements.
```css
div p {
color: blue;
```
---
The **box model** is fundamental to how elements are styled and laid out. It consists of:
- **Margin**: Space outside the border, separating the element from others.
```css
div {
margin: 10px;
padding: 20px;
```
---
- **Fixed**: Positions element relative to the viewport (stays in place while scrolling).
```css
div {
position: relative;
top: 20px;
left: 30px;
```
---
Flexbox is a layout model that allows for easy alignment and distribution of elements.
```css
.container {
display: flex;
```
---
CSS Grid Layout allows for two-dimensional layouts (rows and columns).
```css
.container {
display: grid;
```
---
You can make your web pages responsive (adapt to different screen sizes) using media
queries.
```css
.container {
```
---
### **Conclusion**
CSS is a powerful tool for styling HTML elements, and mastering its properties allows you
to create visually appealing, responsive, and well-structured web pages. Once you're
comfortable with these basic concepts, you can explore more advanced features like
animations, transitions, and advanced layout techniques (Flexbox/Grid).