<div> <span>

Slides:



Advertisements
Similar presentations
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Advertisements

Cascading Style Sheets
Modifying existing content Adding/Removing content on a page using jQuery.
New Semantic Elements (Part 1). Semantics Explained The textbook definition of "semantics" is the study of the relationship between words and their meanings.
4.01 Cascading Style Sheets
Random Stuff Colors Sizes CSS Shortcuts. Learning Objectives By the end of this lecture, you should be able to: – Identify the 3 most common ways in which.
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
HTML. Goals How to use the Komodo editor HTML coding and testing – List and Images – Tables and Links – At least 2 pages and navigation –
HTML & CSS A brief introduction. OUTLINE 1.What is HTML? 2.What is CSS? 3.How are they used together? 4.Troubleshooting/Common problems 5.More resources.
Internet Skills An Introduction to HTML Alan Noble Room 504 Tel: (44562 internal)
ITP 104.  While you can do things like this:  Better to use styles instead:
Eat Your Words! Creating webpage Layout. CONTENT The Layout of a Webpage HEADER FOOTER Each of these sections represents a ‘div’ (or divider). By linking.
Basic Responsive Design Techniques. Let’s take a look at this basic layout. It has a header and two columns of text, in a box that is centered on the.
IDs versus Classes Naming Your Tags for Maximum Functionality.
XP Dreamweaver 8.0 Tutorial 3 1 Adding Text and Formatting Text with CSS Styles.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
CIS67 Foundations for Creating Web Pages Professor Al Fichera Rev. September 14, 2010—All HTML code brought to XHTML standards. Reference for CIS127 and.
WRT235: Writing in Electronic Environments CSS Classes, IDs, divs.
INTRODUCTION TO CSS. OBJECTIVES: D EFINE WHAT CSS IS. K NOW THE HISTORY OF CSS. K NOW THE REASON WHY CSS IS USED. CSS SYNTAX. CSS ID AND CLASS.
Essentials of HTML Class 4 Instructor: Jeanne Hart
INTRODUCTION TO HTML5 Semantic Layout in HTML5.  The new semantic layout in HTML5 refers to a new class of elements that is designed to help you understand.
Definition CSS “Short for Cascading Style Sheets, a new feature being added to HTML that gives both Web site developers and users more control over how.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Course created by Sarah Phillips BBCD Melbourne BAPDCOM Version 1 – April 2013.
Modifying HTML attributes and CSS values. Learning Objectives By the end of this lecture, you should be able to: – Select based on a class (as opposed.
Are You Smarter Than a 5 th Grader? 1,000,000 5th Grade HTML 5th Grade Syntax 4th Grade HTML 4th Grade Syntax 3rd Grade HTML 3rd Grade Syntax 2nd Grade.
Microsoft Expression Web 3 – Illustrated Unit D: Structuring and Styling Text.
Understanding ID and Class in CSS Web Design – Sec 4-9 Part or all of this lesson was adapted from the University of Washington’s “Web Design & Development.
Review of HTML and CSS A (very) brief review of some key fundamentals to be aware of in IT-238.
- WE’LL LOOK AT THE POSITION PROPERTY AND HOW CSS RESOLVES CONFLICTS BETWEEN STYLING INSTRUCTIONS The position property; CSS specificity hierarchy.
NASRULLAHIBA.  It is time to take your web designing skills to the next level with Cascading Style Sheets (CSS). They are a way to control the look and.
Chapter 4 and 5. Objectives Introduce markup: elements and attributes How browsers interpret HTML documents Basic structure of HTML document What do style.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
HTML Extra Markup CS 1150 Spring 2017.
Cascading Style Sheets for layout
Getting Started With HTML
Cascading Style Sheets (CSS)
Internal Style Sheets External Style Sheets
CS 0134 (term 2181) Jarrett Billingsley
4.01 Cascading Style Sheets
CSS Layouts: Grouping Elements
>> Introduction to CSS
Cascading Style Sheets Part 1
Cascading Style Sheets contd: Embedded Styles
Cascading Style Sheets for layout
Retrieving information from forms
Arrays and files BIS1523 – Lecture 15.
Creating a Baseline Grid
HTML Forms and User Input
Styles and the Box Model
Controlling Layout with Style Sheets
Functions BIS1523 – Lecture 17.
“Semantic” Tags Semantic markup describes what the content contains as opposed to what it looks like! Examples include: div, nav, article, header, footer.
HTML Formatting Text.
Training & Development
CSS: Classes and Contextual Selectors
New Semantic Elements (Part 1)
HyperText Markup Language
4.01 Cascading Style Sheets
Introduction to Styling
CSS: Classes and Contextual Selectors
Events Part III The event object.
Modifying HTML attributes and CSS values
Random Stuff Colors Sizes CSS Shortcuts.
Using the API.
JavaScript Part 2 Organizing JavaScript Code into Functions
HTML Document Structure
Internal Style Sheets External Style Sheets
Retrieving information from forms
CSS Classes.
Presentation transcript:

<div> <span> Who knew "generic" could be so useful!

Learning Objectives By the end of this lecture, you should be able to: Understand when you might want to use a <div> tag Understand when you might want to use a <span> tag Recognize that these tags are primarily intended for use with CSS styling, and sometimes with scripting Appreciate the importance of the id attribute

<div> tag In our semantic tags discussion, we have learned about how we should organize our page into logical sections. Recall that semantic tags don’t actually do anything. That is, the tags themselves do not change the appearance of the content they hold, nor do they hyperlink things (e.g. an a tag), or create a list, etc. etc. The tags are simply containers that enable us to break our page into logical sections. However, they are still very important for many reasons as described previously. Among the many important reasons for using them, semantic containers allow us to style the content they contain. For example, we could use CSS to style all <footer> tags in a consistent way throughout our web site. But what if you want to apply some styles to a batch of content on your page that is not enclosed by a semantic tag – or any other tag? For example, suppose you had a few paragraphs of content that you wished to style using CSS, but those particular paragraphs do not "fit" into any known semantic section? One solution is to use a generic container tag called a <div>. Unlike semantic tags, the <div> tag in no way describes the content it contains. In summary: Enclosing content in a <div> tag is perfectly acceptable. You should try to use semantic tags first – but only where they make sense! (For example, don't shoehorn a few random paragraphs of text into an <article> tag or <section> tag). However, if you need to enclose content in a tag, and no semantic tag fits, then use a <div>.

Example - Styling with <div> tags - Let's return to our turtle page. Suppose that for whatever reason, we wanted to apply some styles to the second and third <section> tags on the page (i.e. the 'Anatomy' section, and the 'Diet' section). For example, let's say that the boss decides that they want you to add a border around that particular block of content, as well as to change its foreground and background color - while leaving the 'Introduction' section alone. Because the boss hasn’t given us any particular reason why these two sections should be grouped, it’s not easy to come up with a good semantic tag for them. One solution, then, is to wrap that entire block of HTML code inside a <div> tag. We can then apply the class to that tag.

Working Example - div and class Added - <head> <title>All About Turtles</title> <meta charset="utf-8"> <style> .border-color-emphasize { border: 5px solid brown; padding:10px; color:chocolate; background-color:antiquewhite; } </style> </head> <body> <header> <h1>The World of Turtles</h1> <h2>A Highly Abbreviated Primer</h2> <img src="box_turtle_wikipedia.jpg" alt="Picture of a box turtle"> </header> <main> <section> <h2>Introduction</h2> <p>Turtles are diapsids of the order Testudines</p> <p>Turtles are ectotherms—animals commonly called...</p> </section> <div class="border-color-emphasize"> <h2>Anatomy</h2> <p>The largest living chelonian is the leatherback sea turtle. </p> <h3>Neck Retraction</h3> <p>Turtles are divided into two groups, according to </p> <h3>Shell</h3> <p>The upper shell of the turtle is called the carapace. </p> <h2>Diet</h2> <p>A turtle's diet varies greatly depending on the environment in which it lives. </p> </div> <!-- end of anatomy_diet div --> </main> <footer> <p>The text for this page taken from Wikipedia.</p> </footer> File: turtles_semantics_with_div.html Working Example - div and class Added - Note: I have again removed much of the text inside the paragraphs to enable us to fit the relevant HTML code onto the screen. I have also left out irrelevant segments of the HTML code. You can, of course download and view the complete HTML document from the course page. We have added: A CSS class. A <div> tag to enclose the second and third section tags. We have added our CSS class to this <div> tag. Also note how after the closing </div> tag I added an HTML comment indicating which <div> tag was being closed. This can be a very helpful thing to do in terms of making your code as clear as possible.

It is often a good idea to provide an ‘id’ attribute to tags As we progress, you will increasingly come to see how useful the 'id' attribute is when it comes to scripting (e.g. to retrieve a value from a form). id attributes are also very useful for styling. KEY POINT: If you anticipate even the possibility of doing any scripting and/or styling to a tag, you should provide an id for that tag. Recall that we assign an identifier using an attribute called “id”. Important: The value of the id attribute must be unique to every tag on your page. That is, no two tags in a single web document can have the same id values. Choose your id values carefully. Be sure they describe the purpose of that section. Again, however, be sure to understand you only need to provide an id for a specific tag if you anticipate styling or scripting with that specific tag. If, for example, you anticipate styling all of your <section> tags exactly the same way, you do not need to provide an id to the individual tags. If, however, you anticipate that one particular <section> tag is going to be styled or scripted differently, you should provide it with its own id value. We will go into more detail in subsequent lectures.

File: turtles_semantics_with_span.html <span> tag File: turtles_semantics_with_span.html There is another tag, closely related to <div>, that is called <span>. This tag is very similar to <div> except that it is meant to enclose very small snippets of content. For example, if you wanted to apply a style (or do something involving scripting) to a single sentence, or word, or letter(!), you would probably enclose that content inside a <span> tag. As an example, suppose you wanted to do some elaborate styling to the very first letter of a particular paragraph. That would be an ideal place for a <span> tag to be used. As with the <div> tag, the <span> tag is a generic container. It is not a semantic tag, so it really doesn't tell the web browser (or web crawlers, or speech readers, etc) anything about the content contained inside. It is simply a small, generic container used to style (or script) some content. As with the <div> tag, it is sometimes useful to provide an id to that tag. But the decision as to whether an id attribute is necessary really depends on the context. Note: There is one significant distinction between <span> and <div> tags, namely, that <div> tags are "block level" elements whereas <span> tags are "inline" elements. You can find out more about this in the CSS positioning and layout lecture. Here is an example in which we have decided to style a very small segment of content – in fact, just a single letter! We wrap this letter 'T' inside a <span> tag. Now that we have wrapped this single letter inside a container tag, we can apply a (admittedly rather unattractive!) class to it. <span class="florid-letter"> T </span> urtles are diapsids of the order Testudines. The earliest known members….

<span> tag Note: The example on the previous slide was overdoing the whitespace a little bit. Most programmers would probably put this on a single line: <span class="florid-letter">T</span>urtles are diapsids of the order Testudines. The earliest known members….

Summary of <div> and <span> tags These are known as "generic" tags since, unlike semantic tags, they do not give any indication of the content that they contain. They are almost exclusively used to surround a block of content that the designer wishes to style using CSS. However, because they are wrapped inside a tag, scripting can also be applied if desired. Generic tags should be used when you need to enclose some content, and there is no semantic tag that seems appropriate. At the same time, don't try to "force" a semantic tag around content if that semantic tag doesn't seem right. They are almost always used in conjunction with CSS classes. Sometimes, though not always, it is helpful to provide them with an id attribute. Whether or not you choose to do so, depends on your future plans. The <div> tag is a "block level" element, whereas the <span> tag is an "inline" element. This is relevant to CSS styling, usually related to positioning. Summary of <div> and <span> tags