π Lecture 06 β Basics of HTML
π Overview: This lecture covers the foundational concepts of HTML, focusing on hyperlinks, page styling with colors and backgrounds, meta information for search engine optimization, table creation and formatting for layout, and form design for user input. Understanding these elements is crucial for building functional and well-structured web pages.
ποΈ Topics Covered
The lecture begins with hypertext links using the anchor tag and mailto links, then moves to changing page colors using bgcolor, text, and link attributes, and meta information in the head section. It then covers tables including basic tags, spanning cells with colspan and rowspan, and table and cell attributes, followed by using tables for page layout. Finally, it introduces forms with submit/reset buttons, text boxes, text areas, checkboxes, radio buttons, and lists.
π Lecture Summary
Hypertext links
Hypertext links connect HTML documents. Text or images can be links, and links can be used for email as well. The href attribute is used in the anchor tag <A>, and its value is set as the URL of a web page or a file name. Content enclosed between <A> and </A> becomes clickable.
π Definition β Anchor Tag: <A HREF="URL">clickable content</A> creates a hyperlink to a specified URL.
π Example:
<HTML>
<BODY>
<H1>Computer Science</H1>
Welcome to <A HREF=http://www.vu.edu>Virtual University</A> in Pakistan
</BODY>
</HTML>
This creates a clickable link labeled "Virtual University" that opens http://www.vu.edu.
To create a mailto link: <A HREF=mailto:vtv@hotmail.com> email address</A>
Changing colors in a page
To provide a specific background color to a web page, the bgcolor attribute is used in the body tag. The text attribute assigns font color to text, and the link attribute assigns color to hyperlinks. Color values can be color names (e.g., "Green") or six-digit RGB hexadecimal codes (e.g., #00FF00 for pure green). The RGB rule is: Red Green Blue. The background attribute provides an image as the page background.
π Formula β RGB Color Code: #RRGGBB where RR, GG, BB are two-digit hexadecimal numbers representing Red, Green, and Blue intensities.
π Example:
<HTML>
<BODY bgcolor=yellow text=red link=blue>
<H1>Computer Science</H1>
Welcome to <A HREF=http://www.vu.edu>Virtual University</A> in Pakistan
</BODY></HTML>
This creates a page with yellow background, red text, and blue hyperlinks.
π‘ Why this matters: Controlling page colors and backgrounds is essential for branding, readability, and user experience.
Meta information
Meta information is information about the web page content, located in the <HEAD> section of HTML documents. It helps search engines locate documents. The Meta tag is used within the head tag for this purpose.
π Definition β Meta Tag: <Meta name="description" content="..."> and <Meta name="keyword" content="..."> provide metadata about the page.
π Example:
<html>
<head>
<title>Introduction to e-commerce</title>
<Meta name="description" content="E-commerce is a newly emerging field that uses internet as a medium of communication">
<Meta name="keyword" content="e-commerce, internet, medium, communication">
</head>
<body>Page goes here</body></html>
This provides search engines with a description and keywords for the page.
Tables
Tables are used for page layout and displaying information systematically. Any content that can go in the body can go inside a table. Tables are built row-by-row from top to bottom.
Basic tags: The <Table> tag encloses the entire table. <TR> (table row) creates a row. <TD> (table data) divides a row into cells. <TH> (table header) labels columns as headings. <caption> provides a table caption.
π Example (2 row, 2 column table):
<Table Border=1>
<TR><TD>Cell1</TD><TD>Cell2</TD></TR>
<TR><TD>Cell3</TD><TD>Cell4</TD></TR>
</Table>
This produces a table with cells: Cell1, Cell2, Cell3, Cell4.
Spanning text across multiple rows or columns: The colspan attribute extends a cell across multiple columns. The rowspan attribute extends a cell across multiple rows.
π Example (Colspan):
<TABLE BORDER="1" align=center>
<CAPTION>Spanning the text</CAPTION>
<TR><TD COLSPAN="2">This line is extended to two columns</TD><TD>This does not</TD></TR>
<TR><TD>First Column</TD><TD>Second Column</TD><TD>Third Column</TD></TR>
</TABLE>
The first cell in the first row spans two columns.
π Example (Rowspan):
<TABLE BORDER="1">
<CAPTION>Example - ROWSPAN</CAPTION>
<TR><TD ROWSPAN="2">This line is stretched to two rows</TD><TD>First Row</TD></TR>
<TR><TD>Second Row</TD></TR>
<TR><TD>This does not</TD><TD>Third Row</TD></TR>
</TABLE>
The first cell in the first row spans two rows.
Table tag attributes:
- Border:
<table border="5">displays cell boundaries accordingly. - Width:
<table width="75%">sets table width. - Height:
<table height="100%">sets table height. - Cellpadding:
<table cellpadding="10">refers to distance between cell boundaries and content (pixels). - Cellspacing:
<table cellspacing="5">refers to distance between cells (pixels). - Color:
<table bgcolor="#cccccc">provides background color; can also use color name orbackgroundattribute for an image.
Attributes for <TD> tag:
- Width:
<td width="50%">specifies cell width relative to table width. - Align:
<td align="center">horizontally aligns text (left/right also valid). - Valign:
<td valign="top">vertically aligns text (bottom/middle also valid).
Using a table to set up a page with a margin
Set the table's height to 100% using the <table> tag's height attribute. The first column acts as the margin using bgcolor or background. The second column contains regular text and graphics.
π Example:
<HTML>
<HEAD><TITLE>A Page with a Left-Hand Margin</TITLE></HEAD>
<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<TABLE HEIGHT="100%">
<TR>
<TD BACKGROUND="image2.gif" WIDTH="100"> </TD>
<TD VALIGN="TOP">This section contains the contents of your web page.</TD>
</TR>
</TABLE>
</BODY></HTML>
is the HTML code for a blank space.
Forms
A form is a web page with text boxes, drop-down lists, and command buttons to get user information. Its basic tag is <form> and </form>. Two attributes are used: action (URL or file to send data to) and method (how data is sent, e.g., "post").
π Definition β Form: <Form action="URL" method="post">...</Form> creates an interactive form for user input.
Types: Submit/Reset buttons, Text boxes, Text area, Check boxes, Radio buttons, Lists.
Submit and reset button: <Input type="submit" value="label"> and <Input type="Reset" value="label">. When the submit button is clicked, form data is sent to the URL specified in the <form> tag's action attribute. "Label" is the text on the button; the value attribute is optional.
Text boxes and text area: A text box uses <Input type="text">. A text area uses <Textarea> and </Textarea> with attributes cols and rows to set size. The name attribute in input and textarea tags provides a unique name for the field, used by the server side to respond.
π Example:
<FORM ACTION="http://www.gov.pk/scritps/test.asp" METHOD="POST">
First Name: <INPUT TYPE="TEXT" NAME="First"><P>
Last Name: <INPUT TYPE="TEXT" NAME="Last"><P>
Today's <I>Burning Question</I>: <B>How to make Pakistan a developed country?</B><P>
Please enter your answer in the text area below: <BR>
<TEXTAREA NAME="Answer" ROWS="10" COLS="60"></TEXTAREA><P>
<INPUT TYPE="SUBMIT" VALUE="I Know!"> <INPUT TYPE="RESET">
</FORM>
This creates a form with two text boxes, a text area for an answer, a submit button labeled "I Know!", and a reset button.
π‘ Why this matters: Forms are essential for collecting user data, enabling interactive web applications like search, sign-ups, and feedback.
β Key Takeaways
The key points to remember from this lecture include: hyperlinks are created using the <A> tag with the href attribute, and mailto links enable email communication. Page colors and backgrounds can be set using bgcolor (with names or RGB hex codes), text, link, and background attributes in the <BODY> tag. Tables are built row-by-row using <TABLE>, <TR>, and <TD> tags, with colspan and rowspan for spanning cells, and attributes like border, width, cellpadding, and cellspacing for formatting. Forms use the <FORM> tag with action and method attributes to send user data to a server, and include input types like text, submit, reset, and textarea. The code is used for blank spaces, and the name attribute in form fields is crucial for server-side processing.
π§ Quick Revision Questions
- What is the purpose of the
hrefattribute in an anchor tag, and how is it used to create a mailto link? - How can you set a background color in HTML, and what are the two ways to specify the color value?
- What is the difference between
colspanandrowspanattributes in a<TD>tag? - What are the
actionandmethodattributes in a<form>tag, and what do they control? - Explain the purpose of the
nameattribute in form input fields, and provide an example of its use.
π Lecture 07 β TEXT BOXES, CHECK BOXES, RADIO BUTTONS
π Overview: This lecture covers essential HTML form input elements for collecting user data. It explains how to create text boxes, checkboxes, radio buttons, and selection lists, detailing their attributes and behaviors to enable interactive web forms.
ποΈ Topics Covered
The lecture covers four main types of HTML form input controls: text boxes with attributes like value, size, and maxlength; checkboxes for multiple selections using the checked attribute; radio buttons for single-choice options with shared Name attributes; and selection lists created with <select> and <option> tags, including drop-down and scrolling lists with Multiple and Selected attributes.
π Lecture Summary
Text Boxes
Text boxes are created using <input type=text>. The value attribute pre-fills the text box with default information (e.g., value=http://). The size attribute controls the width of the text box (e.g., size="40" creates a wider box). The maxlength attribute limits the maximum number of characters a user can type (e.g., maxlength="3" allows only three characters).
π Definition β Text box: An HTML input element that allows users to enter a single line of text.
π Formula: <input type=text Name="fieldname" [Value="default"] [Size="width"] [Maxlength="maxchars"]> β Creates a single-line text input field.
π Example: <Input type=text Name="address" size="40"> creates a text box approximately 40 characters wide. <input type=text Name="age" maxlength="3"> creates a box where users can type a maximum of 3 characters (e.g., for age input).
Check Boxes
Check boxes are used for yes/no or true/false responses, allowing multiple selections. They are created with <input type=checkbox>. The checked attribute displays certain options as pre-selected. Each checkbox must have a unique Name attribute for identification when the form is submitted.
π Definition β Check box: An HTML form element that allows users to select one or more independent options from a set.
π Formula: <input type="CHECKBOX" Name="fieldname" [Checked]> β Creates a selectable checkbox, optionally pre-checked.
π Example: In the phobia survey form, <INPUT TYPE="CHECKBOX" NAME="Flying" Checked> creates a pre-checked "Fear of flying" option, while other fears like "Water" and "Lock" remain unchecked by default.
Radio Buttons
Radio buttons allow users to select exactly one option from a group. All radio buttons in the same group share the same Name attribute value. Each option has a unique value attribute that specifies the data sent when that option is selected.
π Definition β Radio button: An HTML form element that lets users choose a single option from a predefined set of mutually exclusive choices.
π Formula: <input type="radio" Name="groupname" Value="uniquevalue" [Checked]> β Creates a radio button in a group where only one can be selected.
π Example: In the income survey, three radio buttons share Name="Income" with Value="Poverty", Value="Middle" (pre-selected with Checked), and Value="Upper". Similarly, the political inclination group uses Name="Politics" with four options: Nationalist (pre-checked), Socialist, Republican, and None.
π‘ Why this matters: Radio buttons enforce mutually exclusive choices, making them ideal for single-answer survey questions where the user must pick exactly one option.
Selection Lists
Selection lists are created with the <select> tag and contain <option> tags for each list item. The size attribute determines the number of visible items; omitting size creates a drop-down list, while size="2" or more creates a scrolling list with scroll bars. The Selected attribute marks a default choice, and the Multiple attribute allows users to select several items at once.
π Definition β Selection list: An HTML form element that displays a list of options in a compact drop-down or scrollable box.
π Formula: <select name="fieldname" size="n" [Multiple]> <option [Selected]>item1</option> ... </select> β Creates a selection list.
π Example: The nationality list uses <SELECT NAME="Nationality" SIZE="4"> to show four items at a time with scroll bars; "Pakistani" is pre-selected using <OPTION SELECTED>Pakistani</OPTION>. The favorite city list omits size, creating a drop-down with "Lahore" pre-selected. The countries visited list uses <SELECT NAME="Countries" SIZE="5" MULTIPLE> to allow selecting multiple countries (e.g., Canada, Russia, England) by holding the Ctrl key (or Command on Mac).
β Key Takeaways
The most critical concepts from this lecture are understanding the four core input types for HTML forms. Text boxes use name, value, size, and maxlength attributes to control input. Checkboxes allow multiple selections and use checked for defaults, with each needing a unique name. Radio buttons enforce a single choice within a group by sharing the same name but having distinct value attributes. Selection lists offer either a drop-down (no size attribute) or a scrolling list (with size β₯ 2), and optionally support multiple selections with the multiple attribute. Remember that for radio buttons, the value attribute is mandatory because it defines the data submitted when that option is selected.
π§ Quick Revision Questions
- What attribute would you add to a text box to limit user input to exactly 5 characters?
- How do you make a checkbox appear pre-selected when the page loads?
- In a group of radio buttons, what attribute must be identical for all buttons to ensure only one can be selected?
- How do you create a drop-down list instead of a scrolling list using the
<select>tag? - Which attribute allows a user to select multiple items from a single selection list?
π Lecture 08 β FRAMES AND IMAGES IN HTML
π Overview: This lecture explains how to use frames in HTML to display multiple pages simultaneously within a single browser window. It also covers how to make images clickable as links and how to create image maps with multiple clickable regions defined by coordinates. Understanding these concepts is essential for creating more interactive and navigable web layouts.
ποΈ Topics Covered
The lecture covers the concept of frames using <FRAMESET> and <FRAME> tags, including dividing the screen horizontally and vertically, and nesting frames. It also covers making images clickable as links, and provides a detailed three-step process for creating image maps using <Map>, <Area>, and <IMG> tags, including determining coordinates using the ISMAP attribute.
π Lecture Summary
Frames in HTML
The concept of frames is used to set up a site so that one page remains in view in part of the browser screen while the visitors can use the rest of the screen to view other pages using hyperlinks. This concept uses two different types of pages: a frameset page and content pages. The frameset page divides the browser window into a set of frames and defines the size of each frame; it has no body section (no <body> tag). Content pages are just regular HTML pages.
Dividing the screen horizontally
The <FRAMESET> tag uses the ROWS attribute to divide the screen horizontally. The example <FRAMESET ROWS="25%,75%"> creates two frames stacked vertically.
π Definition β Frameset Page: A page that divides the browser window into frames and specifies which content pages are displayed in each frame. It uses <FRAMESET> and <FRAME> tags and has no <BODY> tag.
π Formula: <FRAMESET ROWS="value1, value2, ..."> β Defines the height of each horizontal frame, either as a percentage of the total window height or in pixels.
π Example: The code <FRAMESET ROWS="25%,75%"> with two <FRAME> tags creates a layout where the top frame takes up 25% of the screen height and the bottom frame takes up 75%.
Dividing the screen vertically
The <FRAMESET> tag uses the COLS attribute to divide the screen vertically.
π Formula: <FRAMESET COLS="value1, value2, ..."> β Defines the width of each vertical frame, either as a percentage of the total window width or in pixels.
π Example: The code <FRAMESET COLS="20%,60%,20%"> creates three vertical columns, with the middle column being the widest.
Frames with content
The <FRAME> tag uses the SRC attribute to specify which HTML file is displayed in that frame. The NAME attribute is used to give the frame a unique identifier, which can be used with the TARGET attribute of a hyperlink to control where the linked page opens.
π Definition β SRC attribute: Specifies the URL of the content page to be displayed in a frame.
π Definition β TARGET attribute: An attribute of the <A> tag that specifies the frame in which the linked document should open. Its value must match the NAME attribute of a <FRAME> tag.
π Example: <FRAMESET ROWS="25%,75%"> <FRAME SRC="1.htm" NAME="upper"> <FRAME SRC="2.htm" NAME="lower"> </FRAMESET>. Then, a link in 2.htm with TARGET="lower" will load the new page into the frame named "lower".
Ready-made names for frames
There are four pre-defined target names that do not require a corresponding frame to exist.
Target="_self"β loads the new page into the same frame that contains the link.Target="_top"β loads the new page into the entire window, breaking out of any frame structure.Target="_blank"β loads the new page into a new browser window.
Some frame attributes
Several attributes can be added to the <FRAME> tag to control its appearance and behavior.
π Definition β NORESIZE: An attribute used in the <FRAME> tag that prevents users from resizing the frame by dragging its border.
π Definition β SCROLLING: An attribute that determines whether a scroll bar appears with a frame (e.g., SCROLLING="yes" makes it appear).
π Definition β BORDER or FRAMEBORDER: Setting this attribute to 0 in the <FRAMESET> tag hides the border between frames.
Nesting frames
A frame can be further divided into different frames. This concept is called nesting of frames. A <FRAMESET> tag can be used inside another <FRAMESET> tag to create more complex layouts.
π Example:
<FRAMESET ROWS="25%,75%">
<FRAME SRC="1.htm" NAME="upper">
<FRAMESET COLS="50%,50%">
<FRAME SRC="2.htm" NAME="lower">
<FRAME SRC="3.htm" NAME="right">
</FRAMESET>
</FRAMESET>
This code creates a horizontal split where the bottom frame is further split into two vertical frames.
Images can be links, too
Images can be made clickable by placing an <IMG> tag inside an <A> tag. The entire image then becomes a hyperlink.
π Example: <A HREF="main.htm"><IMG SRC="home.gif"></A> β Clicking the "home.gif" image will load the file "main.htm".
Images can be maps, too
An image map is a web page graphic with several defined 'clickable' areas. Creating one involves three steps.
π Definition β Image Map: A single image on a web page that contains multiple clickable regions, each linked to a different destination.
Step 1: Determine the map coordinates
A pixel is a point on a computer screen, identified by its column number followed by its row number. To find the coordinates of a region, you can load the image in a browser with the <ISMAP> attribute. The image coordinates of the current mouse position appear in the status bar.
π Example: For a 600 pixel wide, 100 pixel tall image divided into three equal areas:
- Area A: upper-left
0,0to lower-right199,99 - Area B: upper-left
199,0to lower-right399,99 - Area C: upper-left
399,0to lower-right599,99
Step 2: Use <Map> to define the image map
The <Map> tag is used to define a set of clickable areas. Inside it, the <Area> tag defines each region with its shape, coordinates, and target link.
π Example:
<Map Name="Testmap">
<Area shape="Rect" coords="0,0,199,99" href="a.htm">
<Area shape="Rect" coords="199,0,399,99" href="b.htm">
<Area shape="Rect" coords="399,0,599,99" href="c.htm">
</Map>
Step 3: Add the image map to the web page
The <IMG> tag uses the usemap attribute to link the image to the map defined in step 2. The value must be the name of the map preceded by a #.
π Example: <Img src="coords.gif" usemap="#Testmap"> β This assigns the image "coords.gif" to the image map named "Testmap".
<Area> tagβs SHAPE attribute
The shape attribute can have values like "rect", "circle", and "poly". For a circle, the coords attribute takes three values: the x-coordinate of the center, the y-coordinate of the center, and the radius. For a polygon, it takes three or more sets of x,y coordinates.
π‘ Why this matters: The shape attribute allows you to define non-rectangular clickable areas, such as circular buttons or irregularly shaped regions in a map, making the image map more versatile.
β Key Takeaways
The most critical concepts from this lecture are that frames divide the browser window using <FRAMESET> with ROWS or COLS, and each frame loads a separate HTML file using the <FRAME> tag's SRC attribute. The TARGET attribute in hyperlinks controls which frame a link opens in, and you can nest framesets for complex layouts. For images, you can make them links by wrapping them in an <A> tag, or create image maps using <Map> and <Area> tags with defined coords and shape values. Finally, images become active image maps when you add the usemap attribute to the <IMG> tag, referencing the map by name.
π§ Quick Revision Questions
- What is the difference between a frameset page and a content page, and which tag is used to define each?
- If you have a link in a frame named "content" with the code
<A HREF="newpage.htm" TARGET="top">, where will "newpage.htm" open? - Write the HTML code to create a horizontal frame layout where the top frame is 150 pixels high and the bottom frame takes the remaining space.
- In an image map, what does the coordinate set "30,40,80,100" represent for a rectangular shape?
- What is the purpose of the
ISMAPattribute in the<IMG>tag when creating an image map?
π Lecture 9 β TAG ATTRIBUTES, SOUND FILES, ANIMATIONS
π Overview: This lecture covers specialized HTML elements and attributes, including
<area>tag attributes for image maps, embedding sound files, creating animated GIFs, using the<marquee>tag for scrolling text, and introduces Cascading Style Sheets (CSS) with four different implementation methods. These concepts enable developers to create more interactive and visually appealing web pages.
ποΈ Topics Covered
The lecture covers <area> tag attributes like alt, target, and nohref; sound file formats (AU, WAV, MP3, MIDI) and embedding methods using <embed> and <bgsound> tags; creation and use of animated GIF images; the <marquee> tag and its various attributes for controlling text scrolling; and an introduction to Cascading Style Sheets (CSS) including embedded, linked, and inline styling methods.
π Lecture Summary
<Area> tag attributes
The alt attribute is used to label the clickable region of an image map. The target attribute can be used to display the result in a given frame. The nohref attribute can be used to make a region non-clickable.
π Definition β nohref: An attribute that makes a region in an image map non-clickable, meaning it does not link to any destination.
π Example: <Area shape="circle" coords="70,45,25" href="a.htm" alt="a.htm" target="upper" nohref>
Sound Files
Sound file formats covered are: AU, WAV, MP3, MIDI. Sound files can be used in an anchor tag as follows: <A href="song.wav">Click here for some greeting!</A>. We can also embed such files using the <embed> tag.
π Example - Embedding:
<HTML>
<HEAD><TITLE>Example - Embedding</TITLE></HEAD>
<BODY>
Click the Play button for some nice music:<BR>
<EMBED SRC="Skylar.MP3">
</BODY>
</HTML>
The <EMBED> tag also supports these attributes: Autostart="False" β browser does not play the sound file automatically when the user surfs the web page; Loop="value" β tells the browser how many times to play the file (you can set the value as a number or infinite); Hidden="True" β browser hides the control panel. There is another tag for embedding sound files: the <BGSOUND> tag, but it is supported by Internet Explorer only.
Animated GIF images
Use Paint, Paint Shop Pro, or some other drawing program to create individual image files that will comprise the animation. Then use a special program such as GIF Animator to specify that these images be displayed sequentially, creating an animation. Add it to your web page by setting up an <IMG> tag where the Src attribute indicates the GIF file you created. You can also use ready-made animated images.
<Marquee> Tag
Text placed between <Marquee> and </Marquee> tags scrolls across the screen. Attributes and their values include: Align="top" or "bottom"; Direction="left" or "right"; Behavior="Scroll" or "Slide" or "Alternate"; Loop="times" β can set "times" equal to infinite; Scrollamount="pixels" β higher the pixel value, the faster the text scrolls; Width="value" β specifies the marquee width; Height="value" β specifies the marquee height; Bgcolor="color" β specifies the marquee background color.
π Example - Marquee:
<HTML>
<HEAD>
<TITLE>Marquee</TITLE>
</HEAD>
<BODY>
Discover this amazing compatibility between
<MARQUEE ALIGN="BOTTOM" BGCOLOR="SILVER" WIDTH="200" SCROLLAMOUNT="4">
Islam and Modern Science
</MARQUEE>!
</BODY>
</HTML>
Style sheets
Style sheet instructions can be embedded in the HTML document. One advantage is that the style's formatting definition is created once, and the browser applies that formatting each time the tag is used. Secondly, pages are easier to modifyβedit the style definition and all places where the style is used within the page get updated automatically. The most popular type is Cascading Style Sheets (CSS). There are four main methods of using CSS.
Method #1: Embedded method
Give a <style> tag and a </style> end tag in your document. Put the style tags before the <body> tag. Insert all your style definitions between the style tags.
π Example:
<HTML>
<head>
<style>
<!--
H1{font-size:72pt}
-->
</style>
</head>
<body><h1>An Example of Embedded Method</h1></body>
</html>
Here, H1{font-size:72pt} is called a style definition, font-size is called a style property, and 72pt is the value of the property. Style definitions are contained within the mark <!-- and -->, which is the HTML comment format. It is better to provide style definitions within the comment tag so that old browsers that do not support the <style> tag do not treat the style definition as text.
π‘ Why this matters: The comment tags protect style definitions from being displayed as text in older browsers that don't support CSS.
Method #2: Linking to an external style sheet
A separate file is created with the extension .css, containing your style definitions. Use the <Link> tag inside a web page's <head> section to apply these style definitions.
π Definition β External Style Sheet: A separate .css file containing style definitions that can be linked to multiple HTML pages, allowing uniform styling across an entire website.
π Example:
mystyles.css file content:
h1{color:red}
p{font-size:34pt}
HTML file:
<HTML>
<head>
<Link Rel="stylesheet" Type="text/css" href="mystyles.css">
</head>
<body>
<h1>This heading will appear red</h1>
<p>This line has a 34pt font</p>
</body>
</html>
Method #3: Inline styles
Used when a particular tag is to be given a different style. We use style as an attribute in a tag and give properties/values in the format shown below.
π Example:
<HTML>
<body>
<h1 style="font-size:40pt">This heading has font-size 40-point</h1>
</body>
</HTML>
β Key Takeaways
The <area> tag supports alt, target, and nohref attributes for controlling image map regions. Sound files can be embedded using the <embed> tag with autostart, loop, and hidden attributes, while <bgsound> is IE-only. Animated GIFs are created by combining sequential images using special software and inserted via the <img> tag. The <marquee> tag scrolls text and can be customized with align, direction, behavior, loop, scrollamount, width, height, and bgcolor attributes. Finally, CSS can be applied through three methods: embedded (within <style> tags in the document head), linked (via an external .css file using <Link>), and inline (using the style attribute directly within HTML tags), with the embedded method using HTML comments to protect style definitions from older browsers.
π§ Quick Revision Questions
- What are the five attributes supported by the
<area>tag for image maps? - Which sound file formats were mentioned in this lecture?
- What is the purpose of commenting out style definitions with
<!--and-->? - Name the three different methods of using Cascading Style Sheets discussed in this lecture.
- How does the
scrollamountattribute affect the behavior of a<marquee>element?
π Lecture 10 β Style Sheets
π Overview: This lecture explores Cascading Style Sheets (CSS) in web development, explaining how to apply formatting to HTML elements. It covers various methods of implementing styles, from inline to class-based, and demonstrates how to control fonts, text alignment, colors, and backgrounds for creating visually appealing web pages.
ποΈ Topics Covered
This lecture covers multiple methods of applying style sheets in HTML, including inline styles, styles applied to sections using DIV tags, styles applied to words or phrases using SPAN tags, and style classes. It then demonstrates font control through font-size, font-family, font-weight, and text properties like text-indent, text-align, text-decoration, and text-transform. Finally, it covers color styles for backgrounds and text using CSS properties.
π Lecture Summary
Applying a style to a section
The <DIV> tag is used to divide a page into separate sections. The browser inserts a line break before the <DIV> tag and after the </DIV> end tag. By including the "style" attribute inside the <DIV> tag, one can apply an inline style to everything inside <DIV> and </DIV> tags.
π‘ Why this matters: The DIV tag allows grouping multiple HTML elements and applying the same style to all of them at once, saving code and ensuring consistency.
π Example: <DIV style="font-size:30pt"> <h1>This heading uses a 30-point font</h1> This sentence will have 30-point font <h2>This heading, too</h2> </DIV> β This applies a 30-point font size to all content within the DIV tags.
Applying a style to a word or phrase
Use <SPAN> and </SPAN> and insert the style attribute inside the <SPAN> tag. The <SPAN> tag does not provide any line break, making it useful for styling specific words or phrases within a line without disrupting the flow.
π Example: <h1> This <Span style="font-size:40pt">heading </Span> has font-size 40-point </h1> β Only the word "heading" appears in 40-point font while the rest of the line remains unchanged.
Method # 4: style classes
Style classes are used when you want to apply a specific style to a number of different tags and sections throughout the document. Set up a style class within the <style> tag or within an external style sheet file, e.g., .Classname {style definitions go here}. Add a "class" attribute to the tags you want the styles applied to and put it equal to classname (without the dot).
π Example:
<STYLE>
.Text1{font-size: 20pt;color:red;text-align:center}
.Text2{font-size: 16pt;color:green;text-align:center}
</STYLE>
<DIV CLASS="Text1"><h1>This text is in red</h1></DIV>
<DIV CLASS="Text2"><h2>This text is in green</h2></DIV>
Using styles to control fonts
Font sizes can be specified using keyword values including: xx-small, x-small, small, medium, large, x-large, xx-large, smaller, and larger. Font sizes can also be specified in points (e.g., 24pt).
π Example:
<SPAN STYLE="font-size: xx-small">Physics</SPAN>,
<SPAN STYLE="font-size: x-small">Math</SPAN>,
<SPAN STYLE="font-size: small">Computer Science</SPAN>,
<SPAN STYLE="font-size: medium">Literature</SPAN>,
<SPAN STYLE="font-size: large">E-commerce</SPAN>,
<SPAN STYLE="font-size: x-large">History</SPAN>,
<SPAN STYLE="font-size: xx-large">Islam</SPAN>
Font family styles
The font-family property specifies the typeface to be used. Multiple font names can be listed as a fallback system, with the browser using the first available font. Common font families include "Times New Roman", Arial, "Courier New", and Tahoma.
π Example:
<STYLE>
.fonttype1 {font-size: 20pt; font-family: "Times New Roman"}
.fonttype2 {font-size: 20pt; font-family: Arial}
.fonttype3 {font-size: 18pt; font-family: "Courier New"}
</STYLE>
Font weight styles
The font-weight property controls the thickness of text. Predefined weight values are: normal, bold, bolder, lighter. Specific weight values are in the range 100 β 900, where 400 is typically normal and 700 is typically bold.
π Example:
<SPAN STYLE="font-weight: 100">Physics</SPAN>,
<SPAN STYLE="font-weight: 400">Fiction</SPAN>,
<SPAN STYLE="font-weight: 700">Computer Science</SPAN>,
<SPAN STYLE="font-weight: 800;font-style:italic;color:red">Sociology</SPAN>
Indenting the first line of a paragraph
Use the text-indent property with a value specified in inches or centimeters (e.g., 0.5in) to indent the first line of a paragraph. This is typically applied using a style rule for the <P> tag.
π Example:
P {text-indent: 0.5in}
Aligning the text
Use the text-align property with values: left, right, center, or justify. This property controls the horizontal alignment of text within its container.
π Example:
<TD WIDTH="25%" STYLE="text-align: left">...text...</TD>
<TD WIDTH="25%" STYLE="text-align: center">...text...</TD>
<TD WIDTH="25%" STYLE="text-align: right">...text...</TD>
<TD WIDTH="25%" STYLE="text-align: justify">...text...</TD>
Text decoration styles
Use the text-decoration property with values: none, line-through, overline, or underline. These add visual effects to text such as strikethrough, a line above, or underlining.
π Example:
<H2 STYLE="text-decoration: none">Introduction to E-commerce</H2>
<H2 STYLE="text-decoration: line-through">Introduction to E-commerce</H2>
<H2 STYLE="text-decoration: overline">Introduction to E-commerce</H2>
<H2 STYLE="text-decoration: underline">Introduction to E-commerce</H2>
Working with the upper case and lowercase letters
The text-transform property has four values: capitalize, lowercase, none, and uppercase. "capitalize" capitalizes the first letter of each word, "lowercase" makes all letters lowercase, "uppercase" makes all letters uppercase, and "none" leaves the text as originally typed.
π Example:
<H2 STYLE="text-transform: capitalize"> We love Pakistan</H2>
<H2 STYLE="text-transform: lowercase"> We love Pakistan</H2>
<H2 STYLE="text-transform: none"> We love Pakistan</H2>
<H2 STYLE="text-transform: uppercase"> We love Pakistan</H2>
Coloring the web page with color styles
Using Cascading Style Sheets, one can apply a background color or background image to sections of one's page or even to individual words.
π Definition β background-color: Specifies the background color of an element, using a color name (e.g., blue) or hex code (e.g., #0000FF).
π Definition β background-image: Specifies an image to be used as the background of an element using the syntax URL(filename).
π Example:
<DIV STYLE="background-color: yellow; color: blue">...text...</DIV>
<DIV STYLE="background-color: green; color: white">...text...</DIV>
<SPAN STYLE="background-color: red">highlight individual words</SPAN>
<DIV STYLE="background-image: URL(image2.gif); font-size: 16pt;color:white">...text...</DIV>
β Key Takeaways
Students must understand the four methods of applying styles: inline styles directly in tags, DIV tags for styling entire sections, SPAN tags for styling words or phrases without line breaks, and style classes for reusable styles across the document. Font control requires knowledge of font-size (with keywords like xx-small and values in pt), font-family for typefaces, and font-weight ranging from 100-900. Text formatting properties including text-indent, text-align (left, center, right, justify), text-decoration (none, line-through, overline, underline), and text-transform (capitalize, lowercase, uppercase) are each used with specific syntax. Background styling uses background-color with color names or hex codes and background-image with URL(). The key distinction between DIV (block-level with line breaks) and SPAN (inline without line breaks) is essential for proper layout control.
π§ Quick Revision Questions
- What is the difference between using
<DIV>and<SPAN>tags when applying styles? - How do you create and apply a style class named "Text1" that makes text 20pt, red, and centered?
- What are the predefined keyword values for font-size, and which keyword represents the smallest size?
- What are the four possible values for the text-decoration property and what visual effect does each create?
- How do you apply a background image to a section of a web page using CSS, and what is the correct syntax?
π Lecture 11 β Style Sheets
π Overview: This lecture explores advanced CSS concepts for web design, focusing on the style sheet box model that governs how block elements are rendered on a page. It covers attachment of background images, dimensioning, padding, borders, margins, and position styles, providing the foundational tools for precise layout control in e-commerce websites.
ποΈ Topics Covered
The lecture covers the attachment of background images using the background-attachment property, then introduces the style sheet box model for block elements. It details dimension properties, padding (with individual and shorthand properties), border properties (including width, style, and color), margins, and finally position styles (absolute, relative, and static) with comprehensive examples and visual results.
π Lecture Summary
Attachment of the background image
Using background-attachment: fixed, the background image would remain in place when the user scrolls up and down the page. This creates a parallax-like effect where content moves over a stationary background.
Style sheet box model
Each block element (<P>, <h1>...) is considered to have an invisible box around it. Stuff inside <P>, <h1> to <h6>, <DIV> and <Table> tags etc. is present in the form of blocks. Using the style sheet box model, we can make use of certain properties (dimensions, padding, border, margin and position) to introduce useful styles.
Dimension - Example
The example demonstrates setting height and width properties directly on paragraph elements using inline styles, with a thin solid border applied via a style sheet rule.
π Formula: height: value β Sets the vertical dimension of the box
π Formula: width: value β Sets the horizontal dimension of the box
π Example: <P STYLE="height: 100px">This paragraph is contained in a box 100 pixels high. and <P STYLE="width: 100px">This paragraph is contained in a box 100 pixels wide.
Padding
Padding is the space between the content and its border.
padding-topβ adds space on top of the contentpadding-rightβ adds space to the right of the contentpadding-bottomβ adds space below the contentpadding-leftβ adds space to the left of the contentpaddingβ general property that applies to all four padding properties in this order: 'padding top, padding-right, padding-bottom, padding-left'
π Formula: padding: top right bottom left β Shorthand for all four padding values
π Example: <DIV STYLE="padding: 10px 15px 10px 15px"> applies 10px top, 15px right, 10px bottom, 15px left padding
Border
The border property group controls the appearance of the box outline, with three sub-properties: width, style, and color.
Border Width
border-top-width: specifies width of the top borderborder-right-width: specifies width of the right borderborder-bottom-width: specifies width of the bottom borderborder-left-width: specifies width of the left borderborder-width: specifies the width of all borders in the order 'border-top-width, border-right-width, border-bottom-width, border-left-width'
Border style
border-top-style: specifies style of the top borderborder-right-style: specifies style of the right borderborder-bottom-style: specifies style of the bottom borderborder-left-style: specifies style of the left borderborder-style: specifies the style of all borders in the order 'border-top-style, border-right-style, border-bottom-style, border-left-style'- Values for border styles are double, inset, outset, groove, solid, ridge.
Border color
border-top-color: specifies color of the top borderborder-right-color: specifies color of the right borderborder-bottom-color: specifies color of the bottom borderborder-left-color: specifies color of the left borderborder-color: specifies the color of all borders in the order 'border-top-color, border-right-color, border-bottom-color, border-left-color'
π Formula: border-width: 1cm; border-style: inset β Creates a 1cm thick inset border
π Formula: border-width: 10px; border-color: red green yellow blue; border-style: ridge β Creates a 10px ridge border with different colors on each side
π Example: <DIV STYLE="border-width: 1cm; border-style: inset"> This line is written in a box having inset style border and a border width of 1 centimeter.
π‘ Why this matters: The border properties allow you to create visually distinct boxes for products, navigation, and content sections in e-commerce interfaces, with the ability to customize each side independently.
Margins
Margins are the space outside the border of an element.
margin-top: specifies the size of the top marginmargin-right: specifies the size of the right marginmargin-bottom: specifies the size of the bottom marginmargin-left: specifies the size of the left marginmargin: specifies the size of all the margins in the order: margin-top, margin-right, margin-bottom, margin-left
π Formula: margin: top right bottom left β Shorthand for all four margin values
π Example: P {margin-top:100px; margin-bottom:100px; margin-left:200px; margin-right:200px} creates 100px top/bottom margins and 200px left/right margins for all paragraphs
Position styles
The position property allows you to control exactly where an element appears on the page.
position: absoluteβ you can place the element box anywhere on the pageposition: relativeβ position is relative to the normal position of the elementposition: staticβ position remains unchanged
Positioning coordinates:
topβ element's position is fixed from the top of browser window (in case ofposition: absolute) or below the element's natural position (in case ofposition: relative)rightβ element's position from the right side of browser's windowbottomβ element's position from the bottom of browser's windowleftβ from the left side of the window (in case ofposition: absolute) or to the left of the element's natural position (in case ofposition: relative)
π Formula: position: absolute; left: 700px; top: 200px β Places the element exactly 700px from the left and 200px from the top of the browser window
π Example: <DIV STYLE="position: absolute; left: 700px; top: 200px">Books Section</DIV> positions the "Books Section" text at a specific location on the page, independent of normal document flow
π‘ Why this matters: Absolute positioning is crucial for creating fixed navigation bars, floating shopping carts, and overlay elements in e-commerce websites.
β Key Takeaways
The style sheet box model treats every block element as having an invisible box with content, padding, border, and margin layers that can be independently controlled. Padding adds space inside the border around content, while margins add space outside the border between elements. Border properties allow control over width, style (solid, ridge, inset, etc.), and color, with each side customizable. The position property with absolute, relative, and static values enables precise layout control, where absolute positioning removes an element from normal flow and places it at exact coordinates. Understanding the box model is fundamental to creating properly spaced, visually appealing web layouts for e-commerce interfaces.
π§ Quick Revision Questions
- What is the difference between padding and margin in the CSS box model?
- In what order do the shorthand
paddingandmarginproperties apply their values? - What are the five possible values for the
border-styleproperty mentioned in the lecture? - How does
position: absolutediffer fromposition: relativein terms of element placement? - What effect does
background-attachment: fixedhave on a background image when a user scrolls?