Introduction to CSS
Introduction to CSS
(cascading style
sheet)
CSS stands for Cascading Style Sheets
CSS describes how HTML elements are to be displayed on screen,
paper, or in other media
CSS saves a lot of work. It can control the layout of multiple web
pages all at once
External stylesheets are stored in CSS files
.center {
text-align: center;
color: red;
}
You can also specify that only specific HTML elements should be
affected by a class.
p.center {
text-align: center;
color: red;
}
* {
text-align: center;
color: blue;
}
The CSS Grouping Selector
selects all the HTML elements with the same style definitions
Better to group the selectors, to minimize the code.
Separate each selector with a comma.
Ungrouped Grouped
h1 { h1, h2, p {
text-align: center; text-
color: red; align: center;
} color: red;
}
h2 {
text-align: center;
color: red;
}
p{
text-align: center;
color: red;
}
Inline CSS
Add CSS directly to the tag within your HTML file. This method is generally
not recommended for large projects since it makes the code harder to
maintain.
Add CSS directly to the <nav style="background-color: #333; color: white;
padding: 10px;">
<!-- Navbar content here -->
</nav>
Internal CSS
Place the CSS code in the <style> tag within the <head> section of your HTML
file. This method is useful if you only need the CSS on a single page.
<style>
nav { background-color: #333; color: white; padding: 10px; }
nav a { color: white; margin: 0 10px; text-decoration: none; }
nav a:hover { color: #ddd; }
</style>
External CSS
Create an external CSS file (e.g., styles.css).
Link the CSS file in your HTML file within the <head> section.
nav {
background-color: #333;
color: white;
padding: 10px;
}
nav a {
color: white;
margin: 0 10px;
text-decoration: none;
}
nav a:hover {
color: #ddd;
}
CSS example for <p> tag
p{
color: red;
text-align: center;
}