SlideShare a Scribd company logo
1 of 16
Download to read offline
CSS Selectors
It’s So Simple
Selector {
     propertyName : value;
     propertyName : value
}
Basic Selectors
* (Universal selector)
/* Select every element and apply the following properties */
*{
       padding : 0;
       margin : 0
}
Tag Selector (Just random tag)
                         <!--
span {
                         Select all elements with tag span/ p
     background : red;   -->

}                        <!-- Many span elements -->
p{                       <span>Some span</span>
                         <span>Some span</span>
     width : 250px;
     font-size : 18px;   <!-- Many p elements -->
                         <p> Some paragraf</p>
}                        <p> Some paragraf</p>
#IdName (id selector)
#mainDiv {              <!-- Main div with ID -->
                        <div id=“mainDiv”></div>
    background : red;
    width : 500px;      <!-- Some divs -->
    height : 500px      <div> Just a Div</div>
                        <div> Just a Div</div>
}                       <div class=“classDiv”>
                                Just a Class Div
                        </div>
.ClassName (Class Selector)
.justDiv{                 <!– First Div -->
                          <div class=“justDiv”></div>
      background : red;
      width : 50px;       <!– Second Div -->
      height : 50px       <div class=“justDiv”></div>
}                         ….
                          <!– Nth Div -->
                          <div class=“justDiv”></div>
Attribute Selector
Selector[attributeName = “value”]
img[alt= “someAlt”] {       <img src=“#” alt=“someAlt”/>
       width : 500px;       <img src=“#” alt=“onlyAlt”/>

       height : 50px
}                           <form>
.allForms[type = “text”]{         <input type=“text”/>
       width : 150px;             <input type=“text”/>
       padding : 10px             <input type=“submit”/>
}                           </form>
Attribute Selector Magic
Selector[attr.Name ^= “value”]{
/*select attribute with value at the beginning */
}
Selector[attr.Name *= “value”]{
/* select attribute with value somewhere*/
}
Selector[attr.Name $= “value”]{
/*select attribute with value at the end*/
}
p[id ^=“beginning”] {   <p id=“beginning-id”>
       width : 500px;          Beginning Text
                        </p>
       height : 50px
}                       <p id=“this-is-somewere-id”>
p[id *= “somewere”] {          Somewere Text
       width : 500px;   </p>
       height : 50px
}                       <p id=“id-at-end”>
                               End Text
p[id $= “end”] {
                        </p>
       width : 500px;
       height : 50px
}
Combinators
Child and Sibling Selectors
Parent Child
<!-- Just a list -->
<ul>                                     ul li{
          <li>Item 1</li>
          <li>Item 2</li>
                                                  background : red;
          <ol>
                 <li>Nested Item</li>
                                         }
          </ol>
</ul>

<!-- List with class -->
                                         ul .Item {
<ul>                                            background : red;
          <li class=“item”>Item 1</li>
          <li>Item 2</li>                }
</ul>
Parent>Child (Direct Children Selector)
<!-- Just a list -->
                                           ul > li{
<ul>
          <!– direct children -->                 background : red;
          <li>Item 1</li>
          <li>Item 2</li>
                                           }
          <ol>
                     <li> Nested 1 </li>
                     <li> Nested 2 </li>
                     <li> Nested 3 </li>
          </ol>
</ul>
Sibling + Sibling (Direct Sibling selector)
<p> Sample text 1 </p>         p + p{
<p> Sample text 2 </p>                  background : red;
                                        font-size:18px;
<div> Just a Box</div>
<p>Sample text 3</p>
                               }
                               div + p{
<!– This won’t work -->               background : red;
<div>Just a Box 2</div>               font-size:18px;
<span>This won’t work</span>   }
<p>Sample text 3</p>
Sibling ~ Sibling (Any Sibling Selector)
<p> Sample text 1 </p>
                              p ~ p{
<p> Sample text 2 </p>
                                    background : red;
<div> Just a Box</div>
<p>Sample text 3</p>
                                    font-size:18px;
                              }
<!– This will work -->
<div>Just a Box 2</div>       div ~ p{
<span>This will work</span>         background : red;
<p>Sample text 3</p>
                                    font-size:18px;
                              }

More Related Content

What's hot (20)

XML Technologies
XML TechnologiesXML Technologies
XML Technologies
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
fundamentals of XML
fundamentals of XMLfundamentals of XML
fundamentals of XML
 
XML Fundamentals
XML FundamentalsXML Fundamentals
XML Fundamentals
 
jQuery Beginner
jQuery BeginnerjQuery Beginner
jQuery Beginner
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
 
Xml
Xml Xml
Xml
 
Intro to java script
Intro to java scriptIntro to java script
Intro to java script
 
Introduction to MySQL in PHP
Introduction to MySQL in PHPIntroduction to MySQL in PHP
Introduction to MySQL in PHP
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
PHP - Introduction to PHP Forms
PHP - Introduction to PHP FormsPHP - Introduction to PHP Forms
PHP - Introduction to PHP Forms
 
Xslt tutorial
Xslt tutorialXslt tutorial
Xslt tutorial
 
XML XSLT
XML XSLTXML XSLT
XML XSLT
 
Xml
Xml Xml
Xml
 
Database design and error handling
Database design and error handlingDatabase design and error handling
Database design and error handling
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
Simplifying CSS Selectors
Simplifying CSS SelectorsSimplifying CSS Selectors
Simplifying CSS Selectors
 

Viewers also liked (10)

JDBC
JDBCJDBC
JDBC
 
CSS Pseudo Classes
CSS Pseudo ClassesCSS Pseudo Classes
CSS Pseudo Classes
 
Css pseudo-classes
Css pseudo-classesCss pseudo-classes
Css pseudo-classes
 
Casc Style Sheets Ii
Casc Style Sheets IiCasc Style Sheets Ii
Casc Style Sheets Ii
 
Week 12 CSS - Review from last week
Week 12 CSS - Review from last weekWeek 12 CSS - Review from last week
Week 12 CSS - Review from last week
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Agile Development | Agile Process Models
Agile Development | Agile Process ModelsAgile Development | Agile Process Models
Agile Development | Agile Process Models
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 

Similar to Css selectors

CSS Selector
CSS SelectorCSS Selector
CSS SelectorCalos Kao
 
CSS for Developers
CSS for DevelopersCSS for Developers
CSS for DevelopersNascenia IT
 
SharePointfest Denver - A jQuery Primer for SharePoint
SharePointfest Denver -  A jQuery Primer for SharePointSharePointfest Denver -  A jQuery Primer for SharePoint
SharePointfest Denver - A jQuery Primer for SharePointMarc D Anderson
 
Exam 70 480 CSS3 at Jinal Desai .NET
Exam 70 480 CSS3 at Jinal Desai .NETExam 70 480 CSS3 at Jinal Desai .NET
Exam 70 480 CSS3 at Jinal Desai .NETjinaldesailive
 
Oocss & progressive css3 selectors
Oocss & progressive css3 selectorsOocss & progressive css3 selectors
Oocss & progressive css3 selectorsdaniel_sternlicht
 
Vue.js - zastosowanie i budowa komponentów
Vue.js - zastosowanie i budowa komponentówVue.js - zastosowanie i budowa komponentów
Vue.js - zastosowanie i budowa komponentówLaravel Poland MeetUp
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTMLAmit Tyagi
 
The road to &lt;> styled-components: CSS in component-based systems by Max S...
The road to &lt;> styled-components: CSS in component-based systems by Max S...The road to &lt;> styled-components: CSS in component-based systems by Max S...
The road to &lt;> styled-components: CSS in component-based systems by Max S...React London 2017
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)Ardee Aram
 
Html5 & CSS overview
Html5 & CSS overviewHtml5 & CSS overview
Html5 & CSS overviewIvan Frantar
 

Similar to Css selectors (20)

CSS3 and Selectors
CSS3 and SelectorsCSS3 and Selectors
CSS3 and Selectors
 
CSS Selector
CSS SelectorCSS Selector
CSS Selector
 
CSS for Developers
CSS for DevelopersCSS for Developers
CSS for Developers
 
SharePointfest Denver - A jQuery Primer for SharePoint
SharePointfest Denver -  A jQuery Primer for SharePointSharePointfest Denver -  A jQuery Primer for SharePoint
SharePointfest Denver - A jQuery Primer for SharePoint
 
Exam 70 480 CSS3 at Jinal Desai .NET
Exam 70 480 CSS3 at Jinal Desai .NETExam 70 480 CSS3 at Jinal Desai .NET
Exam 70 480 CSS3 at Jinal Desai .NET
 
Oocss & progressive css3 selectors
Oocss & progressive css3 selectorsOocss & progressive css3 selectors
Oocss & progressive css3 selectors
 
jquery
jqueryjquery
jquery
 
jquery
jqueryjquery
jquery
 
Vue.js - zastosowanie i budowa komponentów
Vue.js - zastosowanie i budowa komponentówVue.js - zastosowanie i budowa komponentów
Vue.js - zastosowanie i budowa komponentów
 
Soa lab 3
Soa lab 3Soa lab 3
Soa lab 3
 
Jina Bolton
Jina BoltonJina Bolton
Jina Bolton
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 
The road to &lt;> styled-components: CSS in component-based systems by Max S...
The road to &lt;> styled-components: CSS in component-based systems by Max S...The road to &lt;> styled-components: CSS in component-based systems by Max S...
The road to &lt;> styled-components: CSS in component-based systems by Max S...
 
CSS for developers
CSS for developersCSS for developers
CSS for developers
 
An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)An Introduction to Cascading Style Sheets (CSS3)
An Introduction to Cascading Style Sheets (CSS3)
 
Emmet(zen coding)
Emmet(zen coding)Emmet(zen coding)
Emmet(zen coding)
 
CSS selectors
CSS selectorsCSS selectors
CSS selectors
 
Css Selectors
Css SelectorsCss Selectors
Css Selectors
 
Html5 & CSS overview
Html5 & CSS overviewHtml5 & CSS overview
Html5 & CSS overview
 
Polymer
PolymerPolymer
Polymer
 

More from Михаил Петров (9)

JS Event Model
JS Event ModelJS Event Model
JS Event Model
 
DOM API Java Script
DOM API Java ScriptDOM API Java Script
DOM API Java Script
 
Object - Oriented Java Script
Object - Oriented Java ScriptObject - Oriented Java Script
Object - Oriented Java Script
 
strings and objects in JavaScript
strings and  objects in JavaScriptstrings and  objects in JavaScript
strings and objects in JavaScript
 
Arrays and Functions in JavaScript
Arrays and Functions in JavaScriptArrays and Functions in JavaScript
Arrays and Functions in JavaScript
 
JavaScript intro
JavaScript introJavaScript intro
JavaScript intro
 
Html 5 Semantics overview
Html 5 Semantics overviewHtml 5 Semantics overview
Html 5 Semantics overview
 
Less & Sass
Less & SassLess & Sass
Less & Sass
 
Науката през погледа на младите
Науката през погледа на младитеНауката през погледа на младите
Науката през погледа на младите
 

Css selectors

  • 2. It’s So Simple Selector { propertyName : value; propertyName : value }
  • 4. * (Universal selector) /* Select every element and apply the following properties */ *{ padding : 0; margin : 0 }
  • 5. Tag Selector (Just random tag) <!-- span { Select all elements with tag span/ p background : red; --> } <!-- Many span elements --> p{ <span>Some span</span> <span>Some span</span> width : 250px; font-size : 18px; <!-- Many p elements --> <p> Some paragraf</p> } <p> Some paragraf</p>
  • 6. #IdName (id selector) #mainDiv { <!-- Main div with ID --> <div id=“mainDiv”></div> background : red; width : 500px; <!-- Some divs --> height : 500px <div> Just a Div</div> <div> Just a Div</div> } <div class=“classDiv”> Just a Class Div </div>
  • 7. .ClassName (Class Selector) .justDiv{ <!– First Div --> <div class=“justDiv”></div> background : red; width : 50px; <!– Second Div --> height : 50px <div class=“justDiv”></div> } …. <!– Nth Div --> <div class=“justDiv”></div>
  • 9. Selector[attributeName = “value”] img[alt= “someAlt”] { <img src=“#” alt=“someAlt”/> width : 500px; <img src=“#” alt=“onlyAlt”/> height : 50px } <form> .allForms[type = “text”]{ <input type=“text”/> width : 150px; <input type=“text”/> padding : 10px <input type=“submit”/> } </form>
  • 10. Attribute Selector Magic Selector[attr.Name ^= “value”]{ /*select attribute with value at the beginning */ } Selector[attr.Name *= “value”]{ /* select attribute with value somewhere*/ } Selector[attr.Name $= “value”]{ /*select attribute with value at the end*/ }
  • 11. p[id ^=“beginning”] { <p id=“beginning-id”> width : 500px; Beginning Text </p> height : 50px } <p id=“this-is-somewere-id”> p[id *= “somewere”] { Somewere Text width : 500px; </p> height : 50px } <p id=“id-at-end”> End Text p[id $= “end”] { </p> width : 500px; height : 50px }
  • 13. Parent Child <!-- Just a list --> <ul> ul li{ <li>Item 1</li> <li>Item 2</li> background : red; <ol> <li>Nested Item</li> } </ol> </ul> <!-- List with class --> ul .Item { <ul> background : red; <li class=“item”>Item 1</li> <li>Item 2</li> } </ul>
  • 14. Parent>Child (Direct Children Selector) <!-- Just a list --> ul > li{ <ul> <!– direct children --> background : red; <li>Item 1</li> <li>Item 2</li> } <ol> <li> Nested 1 </li> <li> Nested 2 </li> <li> Nested 3 </li> </ol> </ul>
  • 15. Sibling + Sibling (Direct Sibling selector) <p> Sample text 1 </p> p + p{ <p> Sample text 2 </p> background : red; font-size:18px; <div> Just a Box</div> <p>Sample text 3</p> } div + p{ <!– This won’t work --> background : red; <div>Just a Box 2</div> font-size:18px; <span>This won’t work</span> } <p>Sample text 3</p>
  • 16. Sibling ~ Sibling (Any Sibling Selector) <p> Sample text 1 </p> p ~ p{ <p> Sample text 2 </p> background : red; <div> Just a Box</div> <p>Sample text 3</p> font-size:18px; } <!– This will work --> <div>Just a Box 2</div> div ~ p{ <span>This will work</span> background : red; <p>Sample text 3</p> font-size:18px; }