Docsity

CSS Selectors and Pseudo-Classes: A Comprehensive Guide, Slides of Web Design and Development

Partial preview of the text

Download CSS Selectors and Pseudo-Classes: A Comprehensive Guide and more Slides Web Design and Development in PDF only on Docsity!

Introduction to CSS

Selecting Elements to Apply a Style

Table of Contents

Primary Selectors: Select by Tag

Here's a span with some text.

Here's a p with some text.

Here's a span with more text.

span {

background: DodgerBlue;

color: #ffffff;

Select all elements

Primary Selectors: Select by ID

Here's a span with some text. Here's another.

span#top {

background: DodgerBlue;

Select

with id="top"

NESTED SELECTORS

Nested Selectors: Descendant

Item1 Item2 Item3

Item4 Item5 Item6

div.items a { color: green; font-weight: bold; } inside

Nested Selectors: Direct Child

Span #1, in the div. Span #2, in the span that's…

Span #3, not in the div at all.

div > span {

background: DodgerBlue;

span { background: #fff; }

**Direct child of directly contained in a **

Nested Selectors: Multiple Classes

Apple + Orange

Apple

Orange

.apple { color: red }

.orange { color: orange }

.small { font-size: 16px }

.apple.orange {

font-style: italic;

Elements with both classes Element with multiple classes

Multiple Selectors (Element, Element)

h1, h2, p {

background: yellow;

Welcome…

My name is…

I live in Duckburg.

My best friend is…

h1#header.intro { text-decoration: underline; color: #C00; } HTML and CSS

Combining Multiple Selectors

Solution: Photo Shoot Effect – CSS

@import "https://fonts.googleapis.com/css?family=Lato:300,400,900";

  • { margin: 0; padding: 0; } body { font-family: Arial, sans-serif; color: #fcfcfc; background-color: #355664; width: 960px; margin: 0 auto; }

Solution: Photo Shoot Effect – CSS (2)

text-transform: uppercase; border-bottom: 3px solid #416371; padding-bottom: 20px;} h3 { text-align: right; font-size: 30px; font-weight: normal; margin: 0 0 10px;} p { line-height: 20px; padding-bottom: 5px;} h1, h2, h3 { font-family: forte,Arial,sans-serif;} h1 { font-size: 50px; padding: 10px 0 0; text-align: center; text-transform: uppercase} h2 { font-size: 40px; letter-spacing: 15px; text-align: center;

Solution: Photo Shoot Effect – CSS (4)

nav ul li a { color: #ffffff; display: inline-block; font-size: 30px; margin: 5px 2px; padding: 7px 10px 4px; text-transform: uppercase;} nav ul li:first-of-type > a { color: #7CB3E9; font-size: 30px; text-transform: lowercase; } nav ul a[title="sweet tabs"] { color: #8EC45B; font-size: 30px; text-transform: none; } nav,article, nav ul li a,figure { border-radius: 10px; }

Solution: Photo Shoot Effect – CSS (5)

article { background-color: #213E4A; margin: 0 0 10px; padding: 20px; height: 390px;} figure { border: 3px solid #142830; float: right; height: 300px; width: 500px; margin-left: 15px; } footer { border-top: 3px solid #142830; padding-top: 15px; margin-bottom: 30px; text-align: center; font-size: 20px; }