SlideShare a Scribd company logo
An Introduction to CSS
 Selectors and Drupal
Understanding CSS selectors and
 how Drupal allows you to use
  them to style pages is a key
         Drupal skill
Audience Knowledge Quiz
How many…
 …know what CSS stands for

 …have “cut & pasted” CSS into sites

 …have written their own CSS rules from
  scratch

 …know what a CSS Selector is

 …are experts, just here to heckle
Why Should You Know This

Turn this:
Into this…
 with CSS
CSS Rule Syntax
Example:                         CSS Syntax:
CSS:                              <Selector> {
   A.menu:hover {
     color: #002b70;               <property>: <value>;
     text-decoration:   underline; <property>: <value>;
   }
                                   …
HTML:                             }
<UL>
  <LI>
     <A class=“menu” href=“foobar.html”>FooBar</A>
  </LI>
</UL>
What are Selectors
Patterns used to select the parts of a
document to apply the styles to.
The CSS3 spec define these patterns as:
  A chain of one or more sequence of simple
  selectors separated by combinators

Lets break this down…
Sequence of Simple Selectors
The most common simple selector types are:
 .<class>            select all elements with class=“<class>”
 <element>           match a specific HTML <element> (A, H2)
 #<id> match element with id=<id> attribute
 :<pseudo>           “pseudo class” selectors like :hover, :visited

These can be combined into sequences to target
specific document element like:
                               A.menu:hover
                               H1
                               #header
Note: There are a lot of other simple selectors, especially with CSS3. See:
                     http://www.w3.org/TR/css3-selectors/#selectors
What are Combinators
Combinators let you combine sequences of
simple selectors (S3) and target very specific
areas of a document.
Combinators are the most important CSS item
to understand with Drupal!
They let you target almost anything on a Drupal
page
Combinators
escendant – S3 S3…
Elements that are contained inside another
element. For example, the selector:


               IV.menu A:hover


ould define the hover style for any anchor tag
inside a div with class menu, even if there are
other tags between.
Combinators
hild – S3 > S3…
Describes elements that have a direct parent
and child relationship:

               L.menu > LI.leaf

ould target ONLY <LI class=“leaf”> elements
that were directly under a <UL class=“menu”>
element.

ibling – S3 + S3… or S3 ~ S3
Specificity (The Great Gotcha)
Complex CSS selectors will overlap with more
than one rule applying to an element.
Specificity defines how browsers should
calculate the “weight” of rules. The heavier ones
win.
Drupal tends to have LOTS of rules so chances
are your carefully crafted selector may not work.
Here’s how specificity is calculated:
       http://www.w3.org/TR/css3-selectors/#specificity
Something !Important
One trick to remember if your selector is not
specific enough is the !important property
declaration.
E.g., if these rules point to the same DIV, the text
color will be red (#id is highly specific).
Div#more_specific { color: red; }
Div.less_specific { color: green; }

If you add, !important to the properties, the color
will be green.
Div#more_specific { color: red; }
Div.less_specific { color: green !important; }
Drupal Areas
Drupal pages have a wide variety of CSS addressable
“areas” that are created by the system and themes.

•Page info
•Theme regions
•Nodes (Content type/Specific)
•Blocks (General / Specific )
•Menus (General / Specific )
•Views (General / Specific )
•Fields - Views & CCK (General / Specific )
•Form elements (General / Specific )
Page Info

 The body tag on Drupal pages will have
 several useful classes.

Front/Not-Front:           Front page or not
Logged-in/not-logged in:   User or Anonymous
Node-Type-<node-type>:     Class based on Node Type
Theme Regions
Theme Regions
Page Top:     <div id=“page-top” class=“region-page-top….
Header:       <div id=“header-group” class=“header-group…
Sidebar First: <div id=“sidebar-first” class=“region-sidebar-first…
Footer:       <div id=“footer” class=“region-footer…
Content:      <div id=“content” class=“region-content…

Example CSS
               #sidebar-first DIV.block {
                    padding-top: 15px;
               }
Nodes, Blocks, & Menus
Nodes, Blocks, & Menus
Node: <div id=“node-2” class=“node node-page full-node…
Block: <div id=“block-block-2” class=“block…
Menu: <div id=“block-system-main-menu”
             class=“block block-system block-menu…

Example CSS
   #block-block2 .content {
     background-image: url("../images/SkylarkingDef2.gif");
     background-repeat: no-repeat;
     width: 151px;
     height: 308px;;
   }
Views & View Fields
Views & View Fields

View: <div class=“view view-photo-galleries…

Field: <div class=“views-field views-field-title…


Example CSS
    .view-photo-galleries .views-field-title {
      padding-bottom: 6px;
    }
    .view-photo-galleries .views-field-title A {
      font-size: 18px;
    }
CCK Fields
CCK Fields
Field:        <div class=“field field-name-field-quest…
Field Label: <div class=“field-label…
Field Items: <div class=“field-items…
Field Item:   <div class=“field-item…

 Example CSS
     .node-field-example .field DIV.field-label {
       padding: 1em 0;
     }
     .node-field-example .field DIV.items {
       padding: 1em 0 2em 1em;
     }
Form Fields

No examples prepared, but
forms are similar to CCK /
Node fields.
Helpful Tools

FireFox with FireBug

Chrome with built in Explore Element
Questions?

This has covered a lot of complex
       concepts quickly….

More Related Content

What's hot (20)

PPTX
Html
Lakshmy TM
 
PDF
Angular Pipes Workshop
Nir Kaufman
 
PPTX
SASS - CSS with Superpower
Kanchha kaji Prajapati
 
PDF
CSS Dasar #6 : Background
Sandhika Galih
 
PDF
AEM Sightly Deep Dive
Gabriel Walt
 
PDF
AEM Sightly Template Language
Gabriel Walt
 
PPT
Html project
arsh7511
 
PDF
CSS Dasar #3 : Penempatan CSS
Sandhika Galih
 
PPTX
New Elements & Features in CSS3
Jamshid Hashimi
 
PPTX
Complete Lecture on Css presentation
Salman Memon
 
PPT
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
 
PPTX
1 03 - CSS Introduction
apnwebdev
 
PDF
05 Introduccion a HTML
Víctor Manuel García Luna
 
PPTX
Curso css
Jesus Luque Medina
 
PDF
CSS For Backend Developers
10Clouds
 
PPT
Basic perl programming
Thang Nguyen
 
PDF
Introduction to CSS3
Doris Chen
 
PPTX
css.ppt
bhasula
 
PDF
CSS Dasar #10 : Specificity
Sandhika Galih
 
PPTX
Cascading style sheets (CSS)
Harshita Yadav
 
Angular Pipes Workshop
Nir Kaufman
 
SASS - CSS with Superpower
Kanchha kaji Prajapati
 
CSS Dasar #6 : Background
Sandhika Galih
 
AEM Sightly Deep Dive
Gabriel Walt
 
AEM Sightly Template Language
Gabriel Walt
 
Html project
arsh7511
 
CSS Dasar #3 : Penempatan CSS
Sandhika Galih
 
New Elements & Features in CSS3
Jamshid Hashimi
 
Complete Lecture on Css presentation
Salman Memon
 
Introduction to Cascading Style Sheets (CSS)
Chris Poteet
 
1 03 - CSS Introduction
apnwebdev
 
05 Introduccion a HTML
Víctor Manuel García Luna
 
CSS For Backend Developers
10Clouds
 
Basic perl programming
Thang Nguyen
 
Introduction to CSS3
Doris Chen
 
css.ppt
bhasula
 
CSS Dasar #10 : Specificity
Sandhika Galih
 
Cascading style sheets (CSS)
Harshita Yadav
 

Viewers also liked (20)

ODP
Using Content Delivery Networks with Drupal
cgmonroe
 
PPT
Congress powerpoint (final)
shaw swafford
 
PDF
European Venture Market
Continua Unternehmensentwicklung GmbH
 
PPT
Powers of 10
Earl Cote
 
PPTX
Eval 4 construction
hamsterlife
 
PPTX
2009 Retail Development Seminar
Stephanie Lindley
 
PPT
Savior Skin Template
MarcMooney
 
PPTX
οι 3 φάκελοι
atanatsis
 
PPT
Getting to the Heart of the Matter: Communities and Health Systems Strengthening
jehill3
 
PPT
Incidence of posterior capsular opacification in rigid pmma
Dr. Anand Sudhalkar
 
PPTX
Dinnershow of Dreams
Philomeen Bazen
 
PPT
Changing trends in ophthalmic practice 2
Dr. Anand Sudhalkar
 
PPT
Partnership Defined Quality: Acting it Out!
jehill3
 
PPT
Laerdal: Helping Save Lives
jehill3
 
PPT
Community Mobilization: Indonesia MITRA TB Project
jehill3
 
PPT
Space Camp Barcelona 2010 - English
Xavier Alabart
 
PPT
Lives Saved Analyses for Child Survival Projects: Basic How-To Use LiST - Deb...
jehill3
 
PPT
Polynomials
nina
 
PDF
European Financial News Distribution Bmb 2010
Brazil Means Business
 
Using Content Delivery Networks with Drupal
cgmonroe
 
Congress powerpoint (final)
shaw swafford
 
European Venture Market
Continua Unternehmensentwicklung GmbH
 
Powers of 10
Earl Cote
 
Eval 4 construction
hamsterlife
 
2009 Retail Development Seminar
Stephanie Lindley
 
Savior Skin Template
MarcMooney
 
οι 3 φάκελοι
atanatsis
 
Getting to the Heart of the Matter: Communities and Health Systems Strengthening
jehill3
 
Incidence of posterior capsular opacification in rigid pmma
Dr. Anand Sudhalkar
 
Dinnershow of Dreams
Philomeen Bazen
 
Changing trends in ophthalmic practice 2
Dr. Anand Sudhalkar
 
Partnership Defined Quality: Acting it Out!
jehill3
 
Laerdal: Helping Save Lives
jehill3
 
Community Mobilization: Indonesia MITRA TB Project
jehill3
 
Space Camp Barcelona 2010 - English
Xavier Alabart
 
Lives Saved Analyses for Child Survival Projects: Basic How-To Use LiST - Deb...
jehill3
 
Polynomials
nina
 
European Financial News Distribution Bmb 2010
Brazil Means Business
 
Ad

Similar to Intro to CSS Selectors in Drupal (20)

PDF
Html / CSS Presentation
Shawn Calvert
 
PDF
Pfnp slides
William Myers
 
PPT
CSS Methodology
Zohar Arad
 
PDF
SMACSS Workshop
Tim Hettler
 
PDF
SMACSS Your Sass Up
Mina Markham
 
PPTX
Css for Development
tsengsite
 
PPT
3 css essentials
Anchu S
 
PDF
Web Programming& Scripting Lab
Swapnali Pawar
 
PPT
3-CSS_essentials_developers_begineers.ppt
mohamed abd elrazek
 
PPT
3-CSS_essentials.ppt
datapro2
 
PPT
3-CSS_essentials introduction slides.ppt
Aasma13
 
PPT
3-CSS_essentials.ppt
scet315
 
PPT
CSS Essentials for Website Development.ppt
unknownman23570
 
PPTX
Howcssworks 100207024009-phpapp01
Likitha47
 
PPTX
SharePointfest Denver - A jQuery Primer for SharePoint
Marc D Anderson
 
KEY
Sass Essentials at Mobile Camp LA
Jake Johnson
 
PDF
Fewd week2 slides
William Myers
 
KEY
Lecture2
Lee Lundrigan
 
PPTX
CSS101 - Concept Fundamentals for non UI Developers
Darren Gideon
 
PPTX
Lecture 3CSS part 1.pptx
GmachImen
 
Html / CSS Presentation
Shawn Calvert
 
Pfnp slides
William Myers
 
CSS Methodology
Zohar Arad
 
SMACSS Workshop
Tim Hettler
 
SMACSS Your Sass Up
Mina Markham
 
Css for Development
tsengsite
 
3 css essentials
Anchu S
 
Web Programming& Scripting Lab
Swapnali Pawar
 
3-CSS_essentials_developers_begineers.ppt
mohamed abd elrazek
 
3-CSS_essentials.ppt
datapro2
 
3-CSS_essentials introduction slides.ppt
Aasma13
 
3-CSS_essentials.ppt
scet315
 
CSS Essentials for Website Development.ppt
unknownman23570
 
Howcssworks 100207024009-phpapp01
Likitha47
 
SharePointfest Denver - A jQuery Primer for SharePoint
Marc D Anderson
 
Sass Essentials at Mobile Camp LA
Jake Johnson
 
Fewd week2 slides
William Myers
 
Lecture2
Lee Lundrigan
 
CSS101 - Concept Fundamentals for non UI Developers
Darren Gideon
 
Lecture 3CSS part 1.pptx
GmachImen
 
Ad

More from cgmonroe (12)

PDF
Structured SEO Data Overview and How To
cgmonroe
 
PDF
Structured SEO Data: An overview and how to for Drupal
cgmonroe
 
PDF
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
cgmonroe
 
PDF
Tips on Securing Drupal Sites
cgmonroe
 
PDF
Becoming "Facet"-nated with Search API
cgmonroe
 
ODP
Intro to drupal module internals asheville
cgmonroe
 
ODP
Solr facets and custom indices
cgmonroe
 
PPTX
HTML Purifier, WYSIWYG, and TinyMCE
cgmonroe
 
PPTX
Using the Features API
cgmonroe
 
PPTX
The Drupal Strongarm Module - Tips and Tricks.
cgmonroe
 
PPT
Drupal Workflow Concepts
cgmonroe
 
PPTX
TriDUG WebFM Presentation
cgmonroe
 
Structured SEO Data Overview and How To
cgmonroe
 
Structured SEO Data: An overview and how to for Drupal
cgmonroe
 
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
cgmonroe
 
Tips on Securing Drupal Sites
cgmonroe
 
Becoming "Facet"-nated with Search API
cgmonroe
 
Intro to drupal module internals asheville
cgmonroe
 
Solr facets and custom indices
cgmonroe
 
HTML Purifier, WYSIWYG, and TinyMCE
cgmonroe
 
Using the Features API
cgmonroe
 
The Drupal Strongarm Module - Tips and Tricks.
cgmonroe
 
Drupal Workflow Concepts
cgmonroe
 
TriDUG WebFM Presentation
cgmonroe
 

Recently uploaded (20)

PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
2025-07-15 EMEA Volledig Inzicht Dutch Webinar
ThousandEyes
 
PPTX
Lecture 5 - Agentic AI and model context protocol.pptx
Dr. LAM Yat-fai (林日辉)
 
PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PDF
CIFDAQ'S Token Spotlight for 16th July 2025 - ALGORAND
CIFDAQ
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PPTX
Machine Learning Benefits Across Industries
SynapseIndia
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PPTX
python advanced data structure dictionary with examples python advanced data ...
sprasanna11
 
PDF
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
PDF
Integrating IIoT with SCADA in Oil & Gas A Technical Perspective.pdf
Rejig Digital
 
PDF
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PPTX
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
2025-07-15 EMEA Volledig Inzicht Dutch Webinar
ThousandEyes
 
Lecture 5 - Agentic AI and model context protocol.pptx
Dr. LAM Yat-fai (林日辉)
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
CIFDAQ'S Token Spotlight for 16th July 2025 - ALGORAND
CIFDAQ
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
Machine Learning Benefits Across Industries
SynapseIndia
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
python advanced data structure dictionary with examples python advanced data ...
sprasanna11
 
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
Integrating IIoT with SCADA in Oil & Gas A Technical Perspective.pdf
Rejig Digital
 
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Top Managed Service Providers in Los Angeles
Captain IT
 

Intro to CSS Selectors in Drupal

  • 1. An Introduction to CSS Selectors and Drupal Understanding CSS selectors and how Drupal allows you to use them to style pages is a key Drupal skill
  • 2. Audience Knowledge Quiz How many… …know what CSS stands for …have “cut & pasted” CSS into sites …have written their own CSS rules from scratch …know what a CSS Selector is …are experts, just here to heckle
  • 3. Why Should You Know This Turn this: Into this… with CSS
  • 4. CSS Rule Syntax Example: CSS Syntax: CSS: <Selector> { A.menu:hover { color: #002b70; <property>: <value>; text-decoration: underline; <property>: <value>; } … HTML: } <UL> <LI> <A class=“menu” href=“foobar.html”>FooBar</A> </LI> </UL>
  • 5. What are Selectors Patterns used to select the parts of a document to apply the styles to. The CSS3 spec define these patterns as: A chain of one or more sequence of simple selectors separated by combinators Lets break this down…
  • 6. Sequence of Simple Selectors The most common simple selector types are: .<class> select all elements with class=“<class>” <element> match a specific HTML <element> (A, H2) #<id> match element with id=<id> attribute :<pseudo> “pseudo class” selectors like :hover, :visited These can be combined into sequences to target specific document element like: A.menu:hover H1 #header Note: There are a lot of other simple selectors, especially with CSS3. See: http://www.w3.org/TR/css3-selectors/#selectors
  • 7. What are Combinators Combinators let you combine sequences of simple selectors (S3) and target very specific areas of a document. Combinators are the most important CSS item to understand with Drupal! They let you target almost anything on a Drupal page
  • 8. Combinators escendant – S3 S3… Elements that are contained inside another element. For example, the selector: IV.menu A:hover ould define the hover style for any anchor tag inside a div with class menu, even if there are other tags between.
  • 9. Combinators hild – S3 > S3… Describes elements that have a direct parent and child relationship: L.menu > LI.leaf ould target ONLY <LI class=“leaf”> elements that were directly under a <UL class=“menu”> element. ibling – S3 + S3… or S3 ~ S3
  • 10. Specificity (The Great Gotcha) Complex CSS selectors will overlap with more than one rule applying to an element. Specificity defines how browsers should calculate the “weight” of rules. The heavier ones win. Drupal tends to have LOTS of rules so chances are your carefully crafted selector may not work. Here’s how specificity is calculated: http://www.w3.org/TR/css3-selectors/#specificity
  • 11. Something !Important One trick to remember if your selector is not specific enough is the !important property declaration. E.g., if these rules point to the same DIV, the text color will be red (#id is highly specific). Div#more_specific { color: red; } Div.less_specific { color: green; } If you add, !important to the properties, the color will be green. Div#more_specific { color: red; } Div.less_specific { color: green !important; }
  • 12. Drupal Areas Drupal pages have a wide variety of CSS addressable “areas” that are created by the system and themes. •Page info •Theme regions •Nodes (Content type/Specific) •Blocks (General / Specific ) •Menus (General / Specific ) •Views (General / Specific ) •Fields - Views & CCK (General / Specific ) •Form elements (General / Specific )
  • 13. Page Info The body tag on Drupal pages will have several useful classes. Front/Not-Front: Front page or not Logged-in/not-logged in: User or Anonymous Node-Type-<node-type>: Class based on Node Type
  • 15. Theme Regions Page Top: <div id=“page-top” class=“region-page-top…. Header: <div id=“header-group” class=“header-group… Sidebar First: <div id=“sidebar-first” class=“region-sidebar-first… Footer: <div id=“footer” class=“region-footer… Content: <div id=“content” class=“region-content… Example CSS #sidebar-first DIV.block { padding-top: 15px; }
  • 17. Nodes, Blocks, & Menus Node: <div id=“node-2” class=“node node-page full-node… Block: <div id=“block-block-2” class=“block… Menu: <div id=“block-system-main-menu” class=“block block-system block-menu… Example CSS #block-block2 .content { background-image: url("../images/SkylarkingDef2.gif"); background-repeat: no-repeat; width: 151px; height: 308px;; }
  • 18. Views & View Fields
  • 19. Views & View Fields View: <div class=“view view-photo-galleries… Field: <div class=“views-field views-field-title… Example CSS .view-photo-galleries .views-field-title { padding-bottom: 6px; } .view-photo-galleries .views-field-title A { font-size: 18px; }
  • 21. CCK Fields Field: <div class=“field field-name-field-quest… Field Label: <div class=“field-label… Field Items: <div class=“field-items… Field Item: <div class=“field-item… Example CSS .node-field-example .field DIV.field-label { padding: 1em 0; } .node-field-example .field DIV.items { padding: 1em 0 2em 1em; }
  • 22. Form Fields No examples prepared, but forms are similar to CCK / Node fields.
  • 23. Helpful Tools FireFox with FireBug Chrome with built in Explore Element
  • 24. Questions? This has covered a lot of complex concepts quickly….