SlideShare a Scribd company logo
1 of 9
Download to read offline
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!

More Related Content

What's hot (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
 

Similar to CSS_tutorial_2

Similar to CSS_tutorial_2 (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
 

More from 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
 
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
 
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
 

More from 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" />
 
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>
 
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
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

CSS_tutorial_2

  • 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!