SlideShare una empresa de Scribd logo
1 de 9
Descargar para leer sin conexión
Beginner CSS Tutorial: Class and ID Selectors                                                               1




I. OVERVIEW OF CLASSES AnD IDs

Class Selectors can be used to select any html element that has been given a class attribute. For in-
stance, a class can be applied to multiple things within your html document. Think of it as a paragraph
style in InDesign.

Classes are defined in CSS with a “.” For instance:

.intro {
    font-weight: bold;
}




ID Selectors are similar to class selectors, in that they can be used to select any html element that has
an ID attribute. However, an ID can only be used OnCE within a document, whereas Classes can
be used as often as needed. IDs are used for specific instances. Think of an ID as a character style in
InDesign.

IDs are defined in CSS with a “#” For instance:

#main_nav {
    font-weight: bold;
}




When do you use ID or Class? Classes can be used as many times as needed within a document. IDs
can be applied only once within a document. If you need to use the same selector more than once,
classes are a better choice.

However, IDs have more weight than classes. If a class selector and an ID selector apply the same
property to one element, the ID selector’s value would be chosen. For example the following #ID
selector:

h2#intro {
    color: red;
}

will override the following .Class selector:

h2.intro {
    color: blue;
}

This is the real concept behind “cascading”... that there is hierarchy built into the language of CSS so
that certain rules “override” others.
II. WORkIng WITH CLASSES AnD IDS                                                                      2


1. Make a folder on your desktop. Call it “CSS_tutorial_2”

2. Create a new file in Dreamweaver. Select:

    - blank page
    - Page type: html
    - Layout: <none>
    - In lower right, for “DocType” select “strict”
    - click “create”




Again, we do not want to use a template for this because we are building the CSS from scratch.

3. go to “File” > “Save as” and name your Dreamweaver document “class_id_selectors_2.html”. Save it
   in your “CSS_tutorial_2” folder on your desktop.

4. Look at the upper left-hand corner of your screen. There are three buttons:

“Code”, “Split”, and “Design”. Click on “Split”.
5. Look at line 5 of the code:                                                                               3


         <title>Untitled Document</title>
Type in a name for your page. Again, you can do this in the top window:




6. In the “design” section of your workspace, type in the following content:

This is my paragraph tag.

This is my class selector.

This ID selector overrides my class and paragraph selectors.


III. REVIEW FOR HOW TO SAVE A CSS FILE AnD DEFInIng RULES

1. Look at your screen. In the upper right-hand corner, there should be a panel called “CSS Styles”. It
   looks like this:

                                                   In the upper right-most corner of that panel, click and
                                                   hold on this icon.

                                                   And drag down to “new”. now, you should get a win-
                                                   dow that looks like this:
2. You are adding a new CSS rule to your document. Do the following:                                        4


         - Selector Type: select “Tag” (we’ll making Classes and IDs after).

         - Tag: click and hold the two arrows to the right of the field. Drag down to select “p”.
           You are defining the “p” (paragraph) tag.

         - Define in: select “(new Style Sheet File)”

         - click “Ok”




3. Save your styles before defining any rules. name your CSS file: “class_id_selectors_2.css” and save it
in your “CSS_tutorial_2” folder. You will only have to do this once. The next time we add a rule, it will
be much easier.

4. Once your “class_id_selectors_2.css” is saved, a window will automatically pop up. Save it with the
following definitions (Only set the following rules for the type category. Don’t worry about the other
categories yet).
5. now you should have a <p> defined in your style sheets window. now, highlight the text you wrote    5

in the design window. At the bottom, in the properties window, select the “format” pulldown menu at
the far upper left and select “paragraph”. This makes all your text formatted with the <p> tag.




Look in the code view—your html should look like this:

<body>
          <p>This is my paragraph tag.</p>
          <p>This is my class selector.</p>
          <p>The ID selector overrides my class and paragraph selectors.</p>
</body>
</html>




And the design view should look like this:




now let’s start applying classes and IDs to this content.



IV. CREATIng RULES FOR CLASSES

1. In the CSS window, underneath properties, click on the page + icon. (new CSS rule) Select “class”
radial button (at the top) and name the new rule “p_class”. Make sure that the bottom radial button
reads as “define in: class_id_selectors_2.css”.
2. In the CSS rules definition window, select OnLY the following: (right now we are only going to             6

change the weight and the color of the font.) Click ok.




3. In the design view, highlight the text that reads “This is my class selector.” In the properties window,
look to the far left to the pulldown menu that reads “Format: Paragraph”. To the right of that menu is
another pulldown menu that reads “Style.” In the “style” pulldown menu you should now see an op-
tion to select “p_class”. Once you have selected it, see your text change to bold and a dark purple color.




notice how your class selector changed the color and weight of the text, but nOT the font! This is
because we didn’t change the font... it automatically picks up on the specifications of the original <p>
tag you defined, unless you define it otherwise. This is the beauty of cascading style sheets! (You can
always go back and change the font, border, color, etc. etc...)
4. Let’s take a look at what your html is doing here:                                                       7


<body>
<p>This is my paragraph tag.</p>

<p class=”p_class”>
This is my class selector.
</p class>

<p>The ID selector overrides my class and paragraph selectors.</p>

</body>
</html>

Here’s what the html mark-up is saying: this class belongs to the <p> tag, and it’s called “p_class”. All
the text in between belongs to the <p> tag, but apply the class properties to it.



5. Here’s what your CSS file should look like:

@charset “UTF-8”;

p {
          font-family: Arial, Helvetica, sans-serif;
          font-size: 12px;
          font-weight: normal;
          color: #993300;
}

.p_class {
          font-weight: bold;
          color: #663366;
}



It makes sense, correct? notice the class definition begins with a “.” now let’s move on to IDs.



V. CREATIng RULES FOR IDs

1. In the CSS window, underneath properties, click on the page + icon. (new CSS rule) Select “Ad-
vanced: IDs, pseudo-class selectors” radial button (at the top) and name the new rule “#p_id”. Make
sure that the bottom radial button reads as “define in: class_id_selectors_2.css”.
2. In the CSS rules definition window, select OnLY the following: (right now we are going to change        8

the font, case, and color.) Click ok.




3. In the design view, highlight the text that reads “This is my class selector.” Look in the properties
window, to the pulldown menu “Style.” notice there is no option to select “#p_id”... This is because
you can only use an ID once! Let’s write the mark-up for this, as it’s not easy to apply this change in
the Dreamweaver interface.

In your html mark-up, key in the following (in pink):

<body>

<p>This is my paragraph tag.</p>

<p class=”p_class”>
This is my class selector.</p class>

<p id=”p_id”>
The ID selector overrides my class and paragraph selectors.</p id>

</body>
</html>

You are telling the <p> tag that this ID belongs to it, and it’s called “p_id”. All the text in between
belongs to the <p> tag, but applies the ID properties to it. You can only use this once in your
document. Here’s what your text looks like now:
4. Here’s what your CSS file should look like:                                                           9


@charset “UTF-8”;

p {
          font-family: Arial, Helvetica, sans-serif;
          font-size: 12px;
          font-weight: normal;
          color: #993300;
}

.p_class {
          font-weight: bold;
          color: #663366;
}

#p_id {
          font-family: Georgia, “Times New Roman”, Times, serif;
          text-transform: uppercase;
          color: #006633;
}

notice the following:

- the ID definition begins with a “#”

- the ID it doesn’t define the type size. This information from the original <p> tag.

- the semi-colon (;) after each rule.



next, we will move onto divs. Divs are containers. This is where things really get exciting as you are
able to define “chunks” for your layout!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (17)

Web Typography
Web TypographyWeb Typography
Web Typography
 
CSS Foundations, pt 2
CSS Foundations, pt 2CSS Foundations, pt 2
CSS Foundations, pt 2
 
HTML Foundations, pt 3: Forms
HTML Foundations, pt 3: FormsHTML Foundations, pt 3: Forms
HTML Foundations, pt 3: Forms
 
Web Layout
Web LayoutWeb Layout
Web Layout
 
Advanced Cascading Style Sheets
Advanced Cascading Style SheetsAdvanced Cascading Style Sheets
Advanced Cascading Style Sheets
 
Unit 3 (it workshop).pptx
Unit 3 (it workshop).pptxUnit 3 (it workshop).pptx
Unit 3 (it workshop).pptx
 
Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
Make Css easy(part:2) : easy tips for css(part:2)
Make Css easy(part:2) : easy tips for css(part:2)Make Css easy(part:2) : easy tips for css(part:2)
Make Css easy(part:2) : easy tips for css(part:2)
 
Web Design Assignment 1
Web Design Assignment 1 Web Design Assignment 1
Web Design Assignment 1
 
Css
CssCss
Css
 
Css
CssCss
Css
 
Tags
TagsTags
Tags
 
3 css essentials
3 css essentials3 css essentials
3 css essentials
 
Web development (html)
Web development (html)Web development (html)
Web development (html)
 
Introduction to whats new in css3
Introduction to whats new in css3Introduction to whats new in css3
Introduction to whats new in css3
 
Ms word 2013
Ms word 2013Ms word 2013
Ms word 2013
 
Css tutorial
Css tutorialCss tutorial
Css tutorial
 

Destacado

Aconcagua 2010
Aconcagua 2010Aconcagua 2010
Aconcagua 2010NFS
 
Informanten Efterår 06
Informanten Efterår 06Informanten Efterår 06
Informanten Efterår 06Jonas Sindal
 
Iisec dt-2011-10
Iisec dt-2011-10Iisec dt-2011-10
Iisec dt-2011-10PaolaReyesR
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 

Destacado (7)

Aconcagua 2010
Aconcagua 2010Aconcagua 2010
Aconcagua 2010
 
Informanten Efterår 06
Informanten Efterår 06Informanten Efterår 06
Informanten Efterår 06
 
HTML Resources
HTML ResourcesHTML Resources
HTML Resources
 
tut0000021-hevery
tut0000021-heverytut0000021-hevery
tut0000021-hevery
 
Iisec dt-2011-10
Iisec dt-2011-10Iisec dt-2011-10
Iisec dt-2011-10
 
newsletter53
newsletter53newsletter53
newsletter53
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 

Similar a Beginner CSS Tutorial: Class and ID Selectors Guide

Similar a Beginner CSS Tutorial: Class and ID Selectors Guide (20)

CSS_tutorial_1
CSS_tutorial_1CSS_tutorial_1
CSS_tutorial_1
 
Web topic 15 1 basic css layout
Web topic 15 1  basic css layoutWeb topic 15 1  basic css layout
Web topic 15 1 basic css layout
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS Guide
 
Css notes
Css notesCss notes
Css notes
 
Customizing the look and-feel of DSpace
Customizing the look and-feel of DSpaceCustomizing the look and-feel of DSpace
Customizing the look and-feel of DSpace
 
BasicCSSFlowTutorial
BasicCSSFlowTutorialBasicCSSFlowTutorial
BasicCSSFlowTutorial
 
BasicCSSFlowTutorial
BasicCSSFlowTutorialBasicCSSFlowTutorial
BasicCSSFlowTutorial
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Tutorial5
Tutorial5Tutorial5
Tutorial5
 
Tutorial5
Tutorial5Tutorial5
Tutorial5
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Lecture2
Lecture2Lecture2
Lecture2
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
Learn CSS From Scratch
Learn CSS From ScratchLearn CSS From Scratch
Learn CSS From Scratch
 
CSS Foundations, pt 1
CSS Foundations, pt 1CSS Foundations, pt 1
CSS Foundations, pt 1
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
 
SMACSS Workshop
SMACSS WorkshopSMACSS Workshop
SMACSS Workshop
 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
 

Más de tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 

Más de tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
eng2u3less38
eng2u3less38eng2u3less38
eng2u3less38
 

Último

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Último (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

Beginner CSS Tutorial: Class and ID Selectors Guide

  • 1. Beginner CSS Tutorial: Class and ID Selectors 1 I. OVERVIEW OF CLASSES AnD IDs Class Selectors can be used to select any html element that has been given a class attribute. For in- stance, a class can be applied to multiple things within your html document. Think of it as a paragraph style in InDesign. Classes are defined in CSS with a “.” For instance: .intro { font-weight: bold; } ID Selectors are similar to class selectors, in that they can be used to select any html element that has an ID attribute. However, an ID can only be used OnCE within a document, whereas Classes can be used as often as needed. IDs are used for specific instances. Think of an ID as a character style in InDesign. IDs are defined in CSS with a “#” For instance: #main_nav { font-weight: bold; } When do you use ID or Class? Classes can be used as many times as needed within a document. IDs can be applied only once within a document. If you need to use the same selector more than once, classes are a better choice. However, IDs have more weight than classes. If a class selector and an ID selector apply the same property to one element, the ID selector’s value would be chosen. For example the following #ID selector: h2#intro { color: red; } will override the following .Class selector: h2.intro { color: blue; } This is the real concept behind “cascading”... that there is hierarchy built into the language of CSS so that certain rules “override” others.
  • 2. II. WORkIng WITH CLASSES AnD IDS 2 1. Make a folder on your desktop. Call it “CSS_tutorial_2” 2. Create a new file in Dreamweaver. Select: - blank page - Page type: html - Layout: <none> - In lower right, for “DocType” select “strict” - click “create” Again, we do not want to use a template for this because we are building the CSS from scratch. 3. go to “File” > “Save as” and name your Dreamweaver document “class_id_selectors_2.html”. Save it in your “CSS_tutorial_2” folder on your desktop. 4. Look at the upper left-hand corner of your screen. There are three buttons: “Code”, “Split”, and “Design”. Click on “Split”.
  • 3. 5. Look at line 5 of the code: 3 <title>Untitled Document</title> Type in a name for your page. Again, you can do this in the top window: 6. In the “design” section of your workspace, type in the following content: This is my paragraph tag. This is my class selector. This ID selector overrides my class and paragraph selectors. III. REVIEW FOR HOW TO SAVE A CSS FILE AnD DEFInIng RULES 1. Look at your screen. In the upper right-hand corner, there should be a panel called “CSS Styles”. It looks like this: In the upper right-most corner of that panel, click and hold on this icon. And drag down to “new”. now, you should get a win- dow that looks like this:
  • 4. 2. You are adding a new CSS rule to your document. Do the following: 4 - Selector Type: select “Tag” (we’ll making Classes and IDs after). - Tag: click and hold the two arrows to the right of the field. Drag down to select “p”. You are defining the “p” (paragraph) tag. - Define in: select “(new Style Sheet File)” - click “Ok” 3. Save your styles before defining any rules. name your CSS file: “class_id_selectors_2.css” and save it in your “CSS_tutorial_2” folder. You will only have to do this once. The next time we add a rule, it will be much easier. 4. Once your “class_id_selectors_2.css” is saved, a window will automatically pop up. Save it with the following definitions (Only set the following rules for the type category. Don’t worry about the other categories yet).
  • 5. 5. now you should have a <p> defined in your style sheets window. now, highlight the text you wrote 5 in the design window. At the bottom, in the properties window, select the “format” pulldown menu at the far upper left and select “paragraph”. This makes all your text formatted with the <p> tag. Look in the code view—your html should look like this: <body> <p>This is my paragraph tag.</p> <p>This is my class selector.</p> <p>The ID selector overrides my class and paragraph selectors.</p> </body> </html> And the design view should look like this: now let’s start applying classes and IDs to this content. IV. CREATIng RULES FOR CLASSES 1. In the CSS window, underneath properties, click on the page + icon. (new CSS rule) Select “class” radial button (at the top) and name the new rule “p_class”. Make sure that the bottom radial button reads as “define in: class_id_selectors_2.css”.
  • 6. 2. In the CSS rules definition window, select OnLY the following: (right now we are only going to 6 change the weight and the color of the font.) Click ok. 3. In the design view, highlight the text that reads “This is my class selector.” In the properties window, look to the far left to the pulldown menu that reads “Format: Paragraph”. To the right of that menu is another pulldown menu that reads “Style.” In the “style” pulldown menu you should now see an op- tion to select “p_class”. Once you have selected it, see your text change to bold and a dark purple color. notice how your class selector changed the color and weight of the text, but nOT the font! This is because we didn’t change the font... it automatically picks up on the specifications of the original <p> tag you defined, unless you define it otherwise. This is the beauty of cascading style sheets! (You can always go back and change the font, border, color, etc. etc...)
  • 7. 4. Let’s take a look at what your html is doing here: 7 <body> <p>This is my paragraph tag.</p> <p class=”p_class”> This is my class selector. </p class> <p>The ID selector overrides my class and paragraph selectors.</p> </body> </html> Here’s what the html mark-up is saying: this class belongs to the <p> tag, and it’s called “p_class”. All the text in between belongs to the <p> tag, but apply the class properties to it. 5. Here’s what your CSS file should look like: @charset “UTF-8”; p { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #993300; } .p_class { font-weight: bold; color: #663366; } It makes sense, correct? notice the class definition begins with a “.” now let’s move on to IDs. V. CREATIng RULES FOR IDs 1. In the CSS window, underneath properties, click on the page + icon. (new CSS rule) Select “Ad- vanced: IDs, pseudo-class selectors” radial button (at the top) and name the new rule “#p_id”. Make sure that the bottom radial button reads as “define in: class_id_selectors_2.css”.
  • 8. 2. In the CSS rules definition window, select OnLY the following: (right now we are going to change 8 the font, case, and color.) Click ok. 3. In the design view, highlight the text that reads “This is my class selector.” Look in the properties window, to the pulldown menu “Style.” notice there is no option to select “#p_id”... This is because you can only use an ID once! Let’s write the mark-up for this, as it’s not easy to apply this change in the Dreamweaver interface. In your html mark-up, key in the following (in pink): <body> <p>This is my paragraph tag.</p> <p class=”p_class”> This is my class selector.</p class> <p id=”p_id”> The ID selector overrides my class and paragraph selectors.</p id> </body> </html> You are telling the <p> tag that this ID belongs to it, and it’s called “p_id”. All the text in between belongs to the <p> tag, but applies the ID properties to it. You can only use this once in your document. Here’s what your text looks like now:
  • 9. 4. Here’s what your CSS file should look like: 9 @charset “UTF-8”; p { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #993300; } .p_class { font-weight: bold; color: #663366; } #p_id { font-family: Georgia, “Times New Roman”, Times, serif; text-transform: uppercase; color: #006633; } notice the following: - the ID definition begins with a “#” - the ID it doesn’t define the type size. This information from the original <p> tag. - the semi-colon (;) after each rule. next, we will move onto divs. Divs are containers. This is where things really get exciting as you are able to define “chunks” for your layout!