CSS Selectors Merged
CSS Selectors Merged
1. Separation of Content and Presentation: CSS allows web developers to separate the content of
a web page (HTML) from its presentation (styling). This separation makes it easier to maintain
and update websites.
2. Styling HTML Elements: With CSS, you can apply styles to HTML elements, such as setting colors,
fonts, margins, padding, and layout properties like positioning and sizing.
3. Selectors: CSS uses selectors to target specific HTML elements and apply styles to them.
Selectors can be based on element names, classes, IDs, attributes, or their relationships within
the document structure.
4. Cascading: The "C" in CSS stands for cascading, which refers to the process of combining
multiple style sheets and resolving conflicts between different styles. CSS rules can be applied
from various sources, including external style sheets, internal style blocks, and inline styles, and
they cascade in a specific order of precedence.
5. Responsive Design: CSS plays a crucial role in creating responsive web designs that adapt to
different screen sizes and devices. Media queries in CSS allow developers to apply different
styles based on factors such as screen width, height, and orientation.
6. Animation and Effects: CSS enables the creation of animations and transitions without the need
for JavaScript. Developers can use CSS properties like transition, animation, and transform to
add movement and interactivity to web elements.
Overall, CSS is essential for creating visually appealing and user-friendly websites by controlling the
layout, typography, colors, and other visual aspects of web pages.
CSS (Cascading Style Sheets) properties define how HTML elements are displayed on a web page. These
properties control various aspects of an element's appearance, such as its size, color, font, positioning,
and more. Here are some common CSS properties categorized by their functionalities:
3. padding: Specifies the space between the content and the border.
Layout Properties:
Typography Properties:
Miscellaneous Properties:
These are just a few examples of CSS properties. There are many more properties available, each serving
a specific purpose and allowing for fine-tuning of the appearance and behavior of web pages.
CSS Selectors
In CSS, selectors are patterns used to select the element(s) you want to style.
.class1.class2 .name1.name2 Selects all elements with both name1 and name2 set within its class attribute
.class1 .class2 .name1 .name2 Selects all elements with name2 that is a descendant of an element with name1
element,element div, p Selects all <div> elements and all <p> elements
element element div p Selects all <p> elements inside <div> elements
element>element div > p Selects all <p> elements where the parent is a <div> element
element+element div + p Selects the first <p> element that is placed immediately after <div> elements
[attribute~=value] [title~="flower"] Selects all elements with a title attribute containing the word "flower"
[attribute|=value] [lang|="en"] Selects all elements with a lang attribute value equal to "en" or starting with "en-"
[attribute^=value] a[href^="https"] Selects every <a> element whose href attribute value begins with "https"
[attribute$=value] a[href$=".pdf"] Selects every <a> element whose href attribute value ends with ".pdf"
[attribute*=value] a[href*="w3schools"] Selects every <a> element whose href attribute value contains the substring
"w3schools"
::after p::after Insert something after the content of each <p> element
::before p::before Insert something before the content of each <p> element
:empty p:empty Selects every <p> element that has no children (including text nodes)
:first-child p:first-child Selects every <p> element that is the first child of its parent
:first-of-type p:first-of-type Selects every <p> element that is the first <p> element of its parent
:in-range input:in-range Selects input elements with a value within a specified range
:last-child p:last-child Selects every <p> element that is the last child of its parent
:last-of-type p:last-of-type Selects every <p> element that is the last <p> element of its parent
:nth-child(n) p:nth-child(2) Selects every <p> element that is the second child of its parent
:nth-last-child(n) p:nth-last-child(2) Selects every <p> element that is the second child of its parent, counting from the
last child
:nth-last-of-type(n) p:nth-last-of-type(2) Selects every <p> element that is the second <p> element of its parent, counting
from the last child
:nth-of-type(n) p:nth-of-type(2) Selects every <p> element that is the second <p> element of its parent
:only-of-type p:only-of-type Selects every <p> element that is the only <p> element of its parent
:only-child p:only-child Selects every <p> element that is the only child of its parent
:out-of-range input:out-of-range Selects input elements with a value outside a specified range
::placeholder input::placeholder Selects input elements with the "placeholder" attribute specified
:read-only input:read-only Selects input elements with the "readonly" attribute specified
:read-write input:read-write Selects input elements with the "readonly" attribute NOT specified
:required input:required Selects input elements with the "required" attribute specified
:target #news:target Selects the current active #news element (clicked on a URL containing that anchor
name)