Here we have 3 input fields with their respective label tags. Note that, the input fields id must match with the label tags for attribute value. Also notice the css file attached to the html file, for aligning the input fields and the labels.
Note: These placeholder attributes are not a substitute for label tags. And it’s neither a form validator. It’s used to provide hint to the user for form entry.
In the previous tutorial there was no facility to display the labels using CSS. To over come that problem, we step into CSS Level 2, wherein we include the label information to the presentation layer using CSS level 2 coding.
Last 3 lines of coding is the only thing changed from previous day tutorial. Those 3 lines are CSS Level 2 coding!
using :beforepseudo class selector we tell the parser to include email: as content before displaying the actual email id.
similarly, using :after we include the label after the actual content.
attr(type) this selects the value assigned to the attribute type from companyNames.xml file and displays it. phone[primary]:after There are multiple phone numbers, one of which is made primary. So phone[primary] points to the phone number which has the attribute primary.
Video Tutorial: Business Card Design: XML & CSS Level 2
I’ve shown CSS Level 2 working on all 3 browsers: Internet Explorer, Mozilla Firefox and Google Chrome. But some older versions of Internet Explorer doesn’t support CSS Level 2 coding. To solve this issue( cross browser compatibility issue ), we can make use of XSLT [ eXtensible Stylesheet Language Transformations ]. We’ll see it in coming video tutorials.
Output on the browser Satish B home: (91) 9844552841(call me) work: (91) 9844119841 email: [email protected] Technotip IT Solutions
In this example we apply styling to business cards of two people. The primary information i.e., the content is in XML and the presentation is taken care by CSS.
Base tag or the root tag name is companyNames and the elements inside root tag is companyName Other tags present inside companyName tag are Name, phone, email, company.
Example: Two people are Satish B and Shwetha, they are working in Technotip IT Solutions and Microsoft respectively.
Video tutorial illustrating: attaching css stylesheet to XML document to give better appearance to it on the browser. In short: for presentation purpose.
To achieve this, we need to first create a stylesheet file, and attach it or associate our XML file with this stylesheet. We do it with the help of a processing instruction.
This way we have separated the content and styling information and made it into two separate files. Helps keep the XML and Design/CSS coding separate and we could hire separate teams to work on these things.
Video Tutorial: Attach CSS StyleSheet To XML Document
Develop and demonstrate, using Javascript, a xHTML document that contains three short paragraphs of text, stacked on top of each other, with only enough of each showing so that the mouse cursor can be placed over some part of them. When the cursor is placed over the exposed part of any paragraph, it should rise to the top to become completely visible.
In HTML code we have used unique ids for the div tags: one, two, three. The same ids have been used in CSS(to assign style information) as well as in the Javascript(for functionality) file.
<html>
<head>
<title>Text Stacked On Top Of EachOther: CSS & JavaScript</title>
<link rel="stylesheet" href="style.css" type="text/css">
<script type="text/javascript" src="stacked.js"></script>
</head>
<body>
<div id="one" onmouseover="moveIt('one')">
Microsoft Dominates!<br />
Windows 7 is getting popular!
</div>
<div id="two" onmouseover="moveIt('two')">
Apple may Dominate!<br />
iTV may takeoff in the market!
</div>
<div id="three" onmouseover="moveIt('three')">
Google Rocks!!<br />
We all know that!!!! :-)
</div>
</body>
</html>
<html> <head> <title>Text Stacked On Top Of EachOther: CSS & JavaScript</title> <link rel="stylesheet" href="style.css" type="text/css"> <script type="text/javascript" src="stacked.js"></script> </head> <body>
<div id="one" onmouseover="moveIt('one')">
Microsoft Dominates!<br />
Windows 7 is getting popular!
</div>
<div id="two" onmouseover="moveIt('two')">
Apple may Dominate!<br />
iTV may takeoff in the market!
</div>
<div id="three" onmouseover="moveIt('three')">
Google Rocks!!<br />
We all know that!!!! :-)
</div> </body>
</html>
Cascading StyleSheet(CSS) coding: In CSS, we assign Verdana as the font for the entire body, with font size as 24 points(pt). Next, using the id(present in the HTML code below) we assign styling information to each div tags. Positioning is absolute. We have varied 20 pixels from top and 20 pixels from left for each div, so that the text overlaps on each other leaving 20 pixels(from top as well as from left) of space for mouse over. We have also changed the background-color and foreground-color of the text inside div tags, so that each div stands out from the other.
JavaScript coding: In Javascript, we declare a variable called topLayer and assign it the value three(which is a id name). Next inside the function moveIt we declare another variable called oldTop, in which we store the style information of topLayer variable(which contains id “three”). Similarly, in variable newTop we store the style information of the toTop(which we receive as parameter to moveIt function).
We can also combine those two lines of code as shown below:
1
2
3
var oldTop = document.getElementById(topLayer).style.zIndex = "0";
var newTop = document.getElementById(toTop).style.zIndex = "10";
var oldTop = document.getElementById(topLayer).style.zIndex = "0"; var newTop = document.getElementById(toTop).style.zIndex = "10";
Note: Higher the value of z-index(in CSS) or zIndex(in javascript), nearer it looks to the user viewing it.
In javascript, while writing style property name, make use of capital latter immediately after the hyphen and eleminate the actual hyphen.
Example: In CSS: background-color In JS : backgroundColor
In CSS: z-index In JS : zIndex
In CSS: font-weight In JS : fontWeight
In CSS: border-style In JS : borderStyle
etc, etc.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var topLayer = "three";
function moveIt(toTop) {
var oldTop = document.getElementById(topLayer).style;
var newTop = document.getElementById(toTop).style;
oldTop.zIndex = "0";
newTop.zIndex = "10";
topLayer = document.getElementById(toTop).id;
}
var topLayer = "three";
function moveIt(toTop) { var oldTop = document.getElementById(topLayer).style; var newTop = document.getElementById(toTop).style; oldTop.zIndex = "0"; newTop.zIndex = "10"; topLayer = document.getElementById(toTop).id;
}
At the end of the function we reset the value of topLayer variable with the id name which invoked the function. Note: Make sure to save all these (.html, .css and .js : HTML, CSS and Javascript) files in the same folder or else change the path in the header as appropriate.