35,99 €
In this book "CSS Selectors and Specificity" we will learn about the different types of selectors, from simple element selectors to advanced attribute selectors and pseudo-classes. We will understand how specificity and cascading work and how to write CSS rules that deliver predictable and desired results.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 27
Veröffentlichungsjahr: 2024
CSS Selectors and Specificity
Abdelfattah Ragab
Welcome to the book "CSS Selectors and Specificity". In this book, I explain the different types of selectors, from simple element selectors to advanced attribute selectors and pseudo-classes. You will understand how specificity and cascading work and how to write CSS rules that deliver predictable and desired results.
By the end of this book, you will be confident in using CSS selectors and have mastered all possible scenarios.
Let’s go!
There are 3 different ways to add CSS styles to HTML. Let me explain them to you:
With inline styles, you can directly add CSS styles to individual HTML elements using the "style" attribute. For example:
<p style="color: blue; font-size: 16px;">This is some text.</p>
The styles are defined within the style attribute itself.
You can also include CSS styles within the <style> tags in the <head> section of the HTML document. This is called an internal stylesheet. Here's an example:
<head>
<style>
p {
color: blue;
font-size: 16px;
}
</style>
</head>
<body>
<p>This is some text.</p>
<!-- more HTML content -->
</body>
The styles defined within the <style> tags will apply to all relevant HTML elements on the page.
Another popular way is to link an external CSS file to your HTML document. You create a separate CSS file with a .css extension and link it to your HTML using the <link> tag. Here's an example:
index.html
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<p>This is some text.</p>
<!-- more HTML content -->
</body>
styles.css
p {
color: blue;
font-size: 16px;
}
In this case, all the CSS styles are defined within the styles.css file, which is referenced by the href attribute in the <link> tag.