CSS Selectors and Specificity - Abdelfattah Ragab - E-Book

CSS Selectors and Specificity E-Book

Abdelfattah Ragab

0,0
35,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

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:

EPUB
MOBI

Seitenzahl: 27

Veröffentlichungsjahr: 2024

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



CSS Selectors and Specificity

Abdelfattah Ragab

Introduction

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!

Chapter 1: How to add CSS styles to HTML

There are 3 different ways to add CSS styles to HTML. Let me explain them to you:

Inline Styles

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.

● Advantages: Inline styles are useful for applying unique styles to individual elements. They have the highest specificity, meaning they override other styles. They are also quick and easy to implement, as the styles are defined directly within the HTML element.
● Use Cases: Inline styles are handy when you want to apply specific styles to a single element without affecting other elements on the page. They are commonly used for quick styling adjustments or for adding temporary styles.

Internal Stylesheet

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.

● Advantages: Internal stylesheets provide a convenient way to define styles that apply to multiple elements on a single HTML page. They keep the styles separate from the HTML markup, which promotes better organization and maintainability. Additionally, they have a higher specificity than external stylesheets.
● Use Cases: Internal stylesheets are often used for small to medium-sized projects where style rules are specific to that particular page. They are suitable when you want to keep the HTML and CSS code together for easier management and readability.

External Stylesheet

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.

● Advantages: External stylesheets offer several advantages. They allow for the separation of concerns, where HTML focuses on structure and content, while CSS handles presentation. This promotes code reusability, consistency, and easier maintenance across multiple HTML pages. External stylesheets can also be cached by the browser, resulting in faster page loading times after the initial load.
● Use Cases: