navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

CSS: Styling Forms
Mark Todd

CSS: Styling Forms

with Ray Villalobos

 


This course covers CSS best practices and techniques for styling and structuring forms. Author Ray Villalobos explains how forms work, best practices for structuring HTML, new additions to forms in HTML5, and how to style individual elements. The course discusses how to use CSS to style traditional and custom elements and reviews browser discrepancies, custom elements, and custom fonts and how to style for different types of user feedback. Advanced CSS layouts and design patterns and issues specific to styling for handhelds are also covered.
Topics include:
  • Creating forms with the <form> element
  • Adding labels and basic usability features
  • Navigating elements between browsers
  • Styling the background
  • Creating input and button fields
  • Working with select fields
  • Floating and positioning grouped elements
  • Using HTML5 input types
  • Resizing elements and adjusting the view for mobile devices
  • Adding jQuery navigation
  • Designing validation feedback

show more

author
Ray Villalobos
subject
Web, Forms, Web Design
software
CSS
level
Beginner
duration
4h 1m
released
Jan 20, 2012

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:04Hello! I'm Ray Villalobos and welcome to CSS: Styling Forms.
00:08In this course I'm going to show you how to use CSS to style forms and form elements.
00:13I'll start by showing you basic form inputs and how to code forms to improve usability.
00:18Then I'll show you how to create special styles for individual form elements,
00:22like custom check box and radio buttons.
00:25We'll see how to lay out forms by grouping them and positioning them with
00:29pixel-level precision.
00:30Finally, I'll show you how to combine jQuery with CSS to validate and style
00:35feedback to users on required fields.
00:38So let's get started with CSS: Styling Forms.
Collapse this transcript
What you should know before watching this course
00:00Before taking this course, you should be familiar with basic web page
00:04development with HTML.
00:06You should also know how to style HTML elements with CSS.
00:10You should be familiar with uploading content to web servers using FTP programs
00:14and using text editors to work with HTML documents.
00:17If you want to learn more about HTML, make sure you check out Bill Weinman's
00:21course on XHTML and HTML Essential Training.
00:25To learn more about CSS, check out James Williamson's CSS Fundamentals and his
00:31CSS Core Concept course.
Collapse this transcript
Using the exercise files
00:00If you are a Premium member of the lynda.com Online Training Library or if you
00:04are watching this tutorial on a DVD-ROM, you have access to the exercise files
00:08used throughout this title.
00:10Inside the exercise files, you will find a folder for assets used throughout
00:14this course, a code snippets file with text elements you'll be using for each
00:20movie, as well as a Starting Points folder with folders for each video in the series.
00:26At the beginning of each movie, I'll show you how to copy the Working Folder
00:30onto your Desktop and how to start working with the project by dragging it onto
00:35your text editor and working with the project files.
00:38If you are a Monthly member or an Annual member of lynda.com, you don't have
00:42access to the exercise files, but you can follow along from scratch with your own assets.
00:47So let's get started.
Collapse this transcript
Setting up the working environment
00:00To work on any web development project, you'll need a combination of a text
00:04editor to work on your files and an FTP program to upload files to a server so
00:09that people can see them on the web.
00:11On a Mac, a great text editor you can get for free is TextWrangler, which is
00:15available from the App Store.
00:17Also available for free on a Mac or a PC is Aptana Studio.
00:21You can go to this web site to download a copy.
00:24Although it's not free, I like to use Macrabbit's Espresso for working with web projects.
00:28It has an excellent HTML and CSS editor, as well as a great live preview for
00:34seeing changes in files while you work on them.
00:36Using a text editor is a very personal choice, so use whatever you
00:39are comfortable with.
00:40While we are working on these files, I'll be using Espresso, and what I usually
00:45do is open up the exercise files, open up Starting Points, and then find the
00:50starting point for the particular movie I am working with, and I make a copy onto the Desktop.
00:57That way I leave the original untouched.
00:59You'll see me dragging this folder into a copy of Espresso, which will open it up as a project.
01:06Anything I add or delete to this Project File section gets added and deleted to this folder.
01:12So this Project File section is equivalent to the Finder folder.
01:15You'll also see me drag things into the Workspace.
01:18The Workspace is a temporary area where you can place things that you are going
01:21to be working on more often.
01:23So you'll see me sometimes drag the codesnippets file which is in a separate
01:26folder, in the Working Folder, onto the Workspace, and you might see me
01:30double-click on some of these other files, like the index files, to bring it
01:34into the Workspace.
01:35You'll also see me open up a live preview.
01:39A live preview is a preview that updates as you edit the HTML.
01:42So if I just click on the Preview icon, you'll see that the Live preview will
01:45come up right here as a document in the Workspace.
01:48I can click and drag that document and put it on a separate window so that I can
01:52see what I am doing while I am typing.
01:54So here let me go ahead and change the title to just Sample, and you can see that
01:59up here that title has been modified. And as I type it in, you'll see that the
02:05live preview updates automatically.
02:07If I change anything else on the file, you'll see the changes happen
02:12onscreen as I do them.
02:14So this is really convenient, and that's one of the reasons I like to use this
02:17program when I am showing how to do things in HTML.
02:20I don't need to save the file and then click over here and reload the document
02:24in order to see my changes.
02:26You can do the same thing by opening up a Working Folder onto something like
02:30TextWrangler, which will open up all the files as a project.
02:34But you may have to open up a separate window in a browser. Move the files that
02:41you want to preview onto the browser window itself.
02:48On some editors the changes don't happen immediately, so you would have to make
02:53a change on your file, save the document, click on the browser, and then do a
02:59refresh to see any changes onto the document.
03:05So I would save, come over here, refresh the page, and I would see the change.
03:09So I just find Espresso just a little bit convenient, especially when I am
03:14showing you how to do things in one of these videos.
03:17Once you are done with the document, you'll need to upload the documents to a
03:20live server so that they will be visible to people on the Internet.
03:25Once you are ready to send the files to your server, you'll need a way to upload
03:28the files so that people can see them online.
03:30You can use an FTP program like Cyberduck which is available for free on a Mac or a PC.
03:35You can download a copy on this web site or on the Mac App Store.
03:39Once you download and install Cyberduck, you can open it up, and you'll need to
03:44create a shortcut for your server.
03:46I've already created one right here.
03:48If you need to create a shortcut, just hit this plus sign and type in the login
03:52information for our server.
03:58You'll need access information for your server.
04:08Then you can save the login information and double-click on your shortcut
04:12to access your server.
04:13Once you access your server, you can copy files to the server to place them on the Internet.
04:18I am going to select all these files, drag them over here.
04:22It will upload the files to the server, and once it's finished, you can go to
04:30a browser and access your project online.
04:33You can also give this URL to somebody else on the web and let them access
04:37your project on the web.
04:38Now that we have our workspace set up, let's get started.
Collapse this transcript
1. Understanding Form Structure
Creating a form with the form element
00:01Forms help the users communicate with your site.
00:03Before we take a look at styling them with CSS, let's check out the most basic
00:07type of form element, the input field.
00:09Some I'm going to open up the exercise files and open up the Starting Points
00:13folder, and inside the Starting Points folder I am going open up the folder for
00:16this chapter, and I am going to copy the Working Folder onto our Desktop. And I am
00:21going to drag this onto the Espresso icon, and it will open it up as a project.
00:26I am also going to need the codesnippets.txt document.
00:29I am going to click on that and drag it into our Workspace.
00:31Finally, I am going to double-click on the index.html file. That will also bring it
00:36into the Workspace. And then I am going to move this over here, and I am going to
00:40hit the Preview button.
00:41If I hold down the Option key, it's going to open it up automatically on a
00:44separate window. And I am going to position that on this side and arrange my
00:48windows a little bit better, so I can see what's going on here.
00:51So the first thing we are going to do is we are going to go into the
00:53codesnippets.txt file and move it all the way to the top.
00:57We are going to take a look at this very first piece of HTML code.
01:00It's just a basic HTML5 page structure, and I am going to copy this and put it in
01:06our index.html file.
01:07You'll notice that our live preview right now is showing at least the title
01:11of the document in this area, because it's the only thing that we have on this page.
01:16So I am going to also go into the codesnippets and grab this piece of code right
01:20here and paste it into our body section. And as soon as we do that we see it's
01:24created an input field where users can type text.
01:27And so an input field is designed to allow the users to type in text.
01:31Right now, the only way to submit this text is with the Enter key, so this form
01:34is not very useable.
01:35There is no buttons to submit anything, and so the form also doesn't really go
01:41anywhere when we type in some text. If we hit Enter, it doesn't really take us anywhere.
01:45So the first thing we need to do now is create an action for this form so that
01:48it sends the information somewhere.
01:50We are going to have Google search process this form so our form will
01:53eventually return search results.
01:56So in order to do that, I am going to go to the codesnippets and grab the next
01:59piece of code, which will modify our form field, so we'll click back on the
02:04index.html. And I am just going to replace this form piece of code right here,
02:09and this action parameter on the form element tells this form to submit to the
02:15Google Search Results page.
02:16So if I come over here and if I type in a search and I hit the Enter key, you'll
02:21see that it actually takes us to the Google Search Results page, but it doesn't
02:25actually return any search results because we haven't really filled out any
02:28additional information on this form to tell Google what we want to search for.
02:32So we are going go back into the codesnippets file.
02:35We are going to grab this next piece of code here and paste it to replace this
02:39input field. And I am going to hit the Back button here, go back to our form. And
02:44by adding this input field here with the name attribute of Q, we are passing
02:48along some information to the Google Search Results page to return the search
02:52results for what we type in into this input field.
02:54So now when we type in a search in our search field you'll see that it actually
02:58returns some information in the Google Search Results page.
03:02So what the user types into the field becomes the value of the variable that is
03:06passed on to a Google search page, so that it knows what returns to give you.
03:11So forms pass information to the processor via a set of name and value pairs, and
03:16the value that we gave this name is what we typed into the form.
03:20You can see that Google wants this variable called q to be passed so that it
03:25knows how to process the form properly.
03:27So there is many other types of input fields. Most forms will have at least one
03:30other type of input field called the submit or submit input type.
03:34So let's go grab the input variable here from our codesnippets.txt file, and
03:38we'll switch back here and we'll add it after our input field here. And we'll
03:43have to come back here, hit the Back button, hit the Refresh.
03:47It's not activating its Live view because it actually took us to another page.
03:51So if we refresh this page, you can see that now we have a Submit button
03:54and instead of hitting the Enter key, we just type in a keyword there and hit
03:59the Submit button and it will actually let us do things with a button
04:03instead of just the Enter key.
04:05Forms can also have values that get passed along automatically.
04:08We can add a value to the submit type that controls the text that shows up in the
04:13little button right here.
04:14So if we add a value to our Submit input type, it will actually change the text
04:19from submit to go, so whatever you type in here becomes the value for this
04:23button right here. And value fields are important in forms because they allow
04:28you to control the value of certain variables.
04:30We can also pass along some hidden information with a different kind of input
04:34field that is hidden.
04:35So I am going to go back into codesnippets.txt, and I am going to copy this piece
04:40of code, go back into our form, and we could really paste this anywhere.
04:44I am going to refresh this page.
04:46We'll actually tell Google to return results, but not using its Normal search
04:51results, but using its Images search results.
04:54We can pass information along to our processor via the value field, and we
05:00can even have different types of input fields that pass different kinds of information in.
05:05You've already seen a text field, a lot of other different kinds of fields. The
05:08hidden input field allows you to send hidden information and with the hidden
05:12input field we usually send a variable name and also a value.
05:16So, we've taken a look at the basics of building a very simple form and the most
05:21common type of form element, the input field.
05:23Input field is super diverse and sends most of the information that goes
05:27along with the form.
Collapse this transcript
Adding labels and basic usability to your forms
00:01Most input fields should have some kind of label that tells users what they need
00:04to type to fill out the form.
00:06Although we can just simply type some text next to the fields, there is a
00:09special tag we can use called the label tag, and using it has a few benefits.
00:14With the label tag, the information in the form becomes more meaningful and
00:18easier to style with CSS.
00:19We are going to open up the exercise files folder and open up the Starting
00:23Points folder, find the folder for this chapter, and copy the Working Folder on
00:28to our desktop. And then we are going to drag that onto Espresso, which will open
00:33it up as a project. And I am also going to drag the codesnippets.txt file into
00:38the Workspace, double-click on the index file in the Project section.
00:42That will also open it up in the Workspace.
00:44Then I am going to Option+Click on the Preview icon, and that will open up a
00:49preview of this document.
00:50Let's modify the hidden input field to allow someone to turn on or off searching
00:55for images with a check box.
00:57Go to the codesnippets file and find a section for this chapter, and I'm going to
01:01copy this input field right here, go back into our index file, and take this
01:07hidden input field out and paste our new version with it so you could see that
01:12now we have a check box that allows people to turn searching for images on and
01:16off by clicking on it, and we have a label next to the check box that let's
01:21people know what this search is for.
01:24Typing a label next to a field looks fine, but it doesn't do a good job of
01:27associating the label with the input field.
01:29It could just as well belong to this search box right here. Plus someone using
01:34an assistive device might have problems understanding which label goes with what input field.
01:39Most of the time input field labels go before the input field, but on radio or
01:43check box input types, the labels are always after the fields, so those can be
01:47especially confusing without labels.
01:50Let's go back into our codesnippets file and grab the next piece of code, and
01:54we'll go back to our index.html file, and we will replace our form of code right here.
01:59Using labels you can create a label tag and then add a for attribute to the
02:05label tag and an ID to the input field. See that we've tied these things
02:09together by adding a for attribute here on the label and adding an ID to the
02:14input field; that ties these two things together.
02:17Having an additional tag around our labels means that we can also style
02:21them easily with CSS.
02:23Adding a label and associating it with the input field has the added bonus of
02:27making the label activate the input field.
02:30If we click on the Images label, we can automatically activate the check box
02:34without having to click exactly on the check box.
02:37That could be a real benefit, especially since check boxes are sometimes a little bit tiny.
02:41This is especially useful on iOS devices.
02:44So let's open up the iOS Simulator.
02:45We'll open up Safari.
02:48When we open up Safari, we'll take our copy of our index file--
02:51I am going to make sure I save it first-- from our Projects file into Safari, and
02:56it will pull up the document in there.
02:58See that by default the document comes up really tiny on mobile Safari, but I
03:03can still click on the Images label and easily activate the form element.
03:07There are a lot of other fields that we can use to help this form perform better
03:11and provide other usability features in some browsers,
03:14so let's take a look.
03:15I am going to quit the iOS Simulator.
03:17I am going to go back to my codesnippets file and copy the next version of our
03:22form where we've added a lot of other usability features.
03:25So in our index file, we'll replace our form fields with a new version that has
03:30some additional features.
03:33On some browsers, adding a title field like this will bring up a tooltip pop-up after a second.
03:38So if we come over here and we put our cursor on top of the Search field, after
03:41a second, you will see that this "Type your search term here" will come up, which
03:46is what we typed in into our title field here.
03:48You can see we've changed the order so that tapping the Tab will activate the
03:52second field and then the first field.
03:54Some browsers allow people to tab through different fields, and this is
03:58especially useful if layout is complex.
04:00You can use the tab index attribute to change the order in which tabs
04:04activate the fields.
04:05So right here we've changed it so that tapping the Tab activates the second
04:09field as opposed to the first field.
04:11Now if I try this on this browser, you'll see that it's not actually working,
04:15and this version of Safari that Espresso is using for a preview doesn't work that way.
04:20I am going to copy the location of this file, just by triple-clicking here and
04:24selecting Copy, and I am going to pull up the Chrome browser and paste the
04:29location of the document. And you'll see that if I hit the Tab key, my second
04:33field, the Images check box, activates before my first field, which is the Search.
04:39So it doesn't work on all browsers, but it's another usability feature that can be useful.
04:43Adding the label, the title, and tab index attributes can go a long way
04:47towards providing enhanced usability in your documents, and also has some
04:51really handy benefits, like making it easier to choose items and also easier
04:56to select the items with CSS.
Collapse this transcript
Normalizing form elements between browsers
00:01There are many types of form elements, but unfortunately there is no way to make
00:04them look identical on all browsers.
00:06I want to take a look at the different types of fields and give you a few tips
00:09on how to make them look alike.
00:11So we'll open up the exercise files, then open up the Starting Points folder and
00:15the folder for this chapter.
00:17I am going to copy this Working Folder onto my Desktop.
00:20Then I'll drag this onto the Espresso application, and I also want to copy the
00:25codesnippets.txt files into the Workspace and double-click on the index file
00:30also to bring it into the Workspace. And I'll move this over here, hold down the
00:34Option key, and click on Preview.
00:35That will pull up a live view right here.
00:37So there is a variety of text fields, like the input type text and input type
00:42passwords, which allow users to type in text in text fields. Input type password
00:47just hides all the input.
00:48HTML5 introduces different versions of these elements, like URL and email input
00:54types, but they pretty much display the same way.
00:56As a matter of fact, if you do not specify a type of input, it will by default
01:01show you an input type text field.
01:03There is also the textarea, which is like the input field, but lets users type in
01:09longer pieces of text.
01:11Unfortunately, these fields display differently depending on the browser
01:15platform and version that you are using to see them.
01:17You can use a tool like Adobe BrowserLabs at browserlab.adobe.com to take a look
01:24at how they look on different platforms.
01:25You will have to get an AdobeID account if you don't already have one. I have mine here,
01:30so I am going to type in my password.
01:31Once you sign in, you will be able to type in the URL of your web site.
01:38Now I have already loaded this page onto a server so we can take a look at how
01:42this form looks on different platforms.
01:43So I'll type in the URL to the form and BrowserLab will pull up the form
01:48in multiple browsers.
01:49You can see right here that we are looking at this on Internet Explorer 7 in
01:54Windows, but I can choose a different browser from this pop-up list.
01:57I can choose Safari and any of these other browsers.
02:00BrowserLab also lets you create groups of browsers for different types of
02:04testing so that you can customize which browsers come up on this list.
02:08Now although BrowserLabs also allows you to see a 2-up view side by side so
02:13that you can compare two different browsers, I've taken the time to put this
02:16into a single page so you could see all of the different platforms and how they display this page.
02:21So you can see even different versions of Internet Explorer display
02:25things differently,
02:26so with different spacing between things and different styles or different
02:30elements. You could see also that Chrome Windows and Safari Mac have
02:34different styles for the buttons and also different spacings for different types of fields.
02:40Now there is no way of making all these look identical, but there is a lot of
02:43libraries that try to handle the work of making them look similar for you.
02:48One of those libraries is a template system called HTML5 Boilerplate.
02:52It does a lot more than just trying to make all the form elements look the same.
02:55And you should take a look at it, and it does a lot of other things like
02:59automatically loading modernizr, jQuery, and other libraries, so it's really more
03:03of a template system rather than just a reset template.
03:06We also have HTML5 Reset, which is a little bit simpler template, and it also
03:12loads jQuery and other libraries. And it does some of the resetting for you, but
03:16it's really for bigger projects where you want to start off with a set of
03:19templates with a number of different files in the template.
03:22If you want a simpler version, you can use something called Normalize.css, which
03:27is really designed to just normalize the styles between different platforms.
03:31It doesn't have a lot of the features as some of the other template systems, but
03:36it'll work really well for standardizing how form elements look.
03:39So you want to go down to the bottom and download the file in one of these formats.
03:43Once the file downloads, you want to open up the folder with the file and you
03:48want to copy the file called normalize.css into your current Working Folder.
03:53This is my exercise files, and I don't want to copy it in there.
03:56I want to copy it into the same folder as the index.html file that I will be working with.
04:01Espresso just lets you drag that file into the project files, and it will
04:05actually make a copy of it and put it in the Working Folder.
04:08If you are not using Espresso, you can just drag it onto whichever folder you
04:12have your index.html file. You can see that I copied it right there.
04:20So once you've added the file into your Working Folder, you want to include the
04:24file into your current form.
04:28And as soon as I made the call to the normalize.css file, you can see that
04:33my instant preview updated some things about the form, and you can immediately
04:37see that all the fonts are now a little bit different than the default font, and
04:40that's one of the things that normalize does. Get rid of this type because we
04:44don't need it in HTML5.
04:46You could go back to BrowserLabs and see how this all works in
04:48different browsers.
04:49But I've already put all those together in a single file for you.
04:53So you could see that the fonts look a lot closer together.
04:56There are still a few other discrepancies, but it's looking a little bit closer
05:00to what it should be.
05:02Just remember, it's never going to be perfect.
05:04There are a few more things that we could do to improve on this,
05:07mainly making the button looks a little better, and also just getting rid of some
05:11of the styling of the buttons, so that we can start from scratch.
05:13So I am going to switch back into Espresso here, and I am going to go to my
05:18codesnippets file, and I'm going to copy this code from the codesnippets file to
05:24show you a few more improvements.
05:25So I am just going to add that to the head section of my document.
05:29You can see that it collapsed some of the spaces a little bit better, and
05:32we really want that.
05:33We really want to start with clean spacing.
05:35So I am going to go through what some of these things do, and the first thing I
05:38am doing is setting every form element to have no background whatsoever.
05:44I am also using the type selectors to choose every type of input field,
05:49including the type=password, type= text, and type=submit. If you had other
05:53types of input fields, you want to add that to this list. And we've also
05:57included the textarea and the button field, and one of the first things that
06:00we did is told the browsers that support it to not show any special
06:05appearance in their buttons.
06:06So normally, these buttons would display with a little round edges on Safari,
06:12but we've told it not to do that.
06:13So let me just go ahead and take off this.
06:15So you could see how to choose, for example, this right here is looking like a
06:19pop-up list with little round edges. The button has this little border to it.
06:24So by using the webkit-appearance attribute we have taken off some of the
06:28defaults styling that WebKit and Mozilla--which are Chrome, Safari, and Firefox--
06:34would use when displaying some of these elements.
06:37So if we take those out, you could see a little bit of a change in here, so
06:40the buttons look a little different right now. And in different browsers, as you
06:44saw in the other window, the buttons would display with different styles, so
06:48that adding the -webkit-appearance lets you override how those styles look on
06:52different browsers.
06:53We've also, instead of having these different kinds of borders that you see on
06:57different buttons, for example, the kind of double border that has a little bit
07:00of an embossed look, we've taken that out by specifying a border that's more
07:04consistent, one pixel solid and whatever color we want.
07:08We have reset the background to none, and also we are setting the roudness of
07:14some of the edges to nothing.
07:16We can overwrite those if we want to by clearing all these out. It will give us more
07:20consistent form elements.
07:21So let's go back into Fireworks and we'll take a look at this version of the
07:25form with all the adjustments that we have made, and mainly here you can see that
07:29the buttons are now more consistent across all browsers.
07:33Internet Explorer 6 still does not do a perfect job with that, but all the other
07:37browsers now have more consistent buttons, which is really crucial when you are
07:41trying to style things to make them look as close as possible to each other.
07:44With just a few changes, we've managed to make these forms look alike in
07:48different browsers, but just remember that although you can come close, they
07:52will never look perfectly the same. Make sure that you are previewing your
07:55projects in a tool like Adobe BrowserLabs and or as many browsers and
07:59platforms as you can.
Collapse this transcript
2. Styling Basic Elements
Creating a background with textured gradients
00:00Learning how to style form elements is pretty much like styling anything else.
00:04So in order to learn how to deal with form elements we'll get started by working
00:07on styling backgrounds.
00:09So open up the exercise files folder and open up the Starting Points and find the
00:14folder for this video and copy the Working Folder onto your desktop. And I am
00:20going to drag the Working Folder onto Espresso.
00:23I'll also need the snippets.txt file, so I am going to copy that by dragging
00:28it into the Workspace.
00:29I am going to double-click on the index.html file to also bring it into the
00:34Workspace, and I'll move my window and hold down the Option key and click on the
00:39Preview icon to open a live preview.
00:43The most obvious thing we can do to a background is to change its color.
00:46We can do that easily by using a number of different color models.
00:49So I already have a style tag in my document, and I am just going to type in code
00:54to change the body section of my document and type in a background element, and
01:01see that Espresso gives you a lot of defaults there, but all I really need to do
01:05is just change the background color.
01:08And so you could see that it's really easy to change the background color; all
01:11you need to do is specify a color in one of several different modes.
01:15You can use hexadecimal or RGB, and those are the most common and best-
01:20supported modes out there.
01:21You can specify colors in Hexadecimal by using three sets of numbers like this.
01:26Every one of these numbers actually doubles,
01:29so this could also be written like this. And every pair of numbers stands for a
01:34number between 0 and 255, so FF would be 255 and 00 would be 00.
01:41This is the basic same numbering system, and it sometimes a little bit difficult
01:46to get your head around it, and so I usually use another tool to kind of tell me
01:50what these colors are supposed to be.
01:52So if you want to check out some cool color combinations or just want to create
01:56colors from an existing image, you should check out Adobe Kuler, which is
02:00available at kuler.adobe.com, and lets you create colors from an existing image.
02:05So you can load up an image that you want to base your web site on and it'll
02:10automatically pick colors for you based on that. You could get any of the different
02:13color modes from a list of colors underneath each color, and we can even modify
02:19them right here, or by clicking on these little icons.
02:22You can choose different color rules,
02:27so a monochromatic rule, to make sure that as you switch the colors they stay
02:31within the same family, and other kinds of rules for related colors.
02:37If you go to Themes, you can see that there is a lot of themes that people
02:41have already created.
02:42So, if you are stuck and you know you want to base a color on a specific, you
02:47know, type of color, like greens or blues, you can start with one of these
02:50predefined color modes and pick your colors from there and copy them and paste
02:55them into your HTML document.
02:57Kuler is also available as an Android app, which will soon be out on the iPad.
03:02Of course Fireworks and Photoshop will also let you pick colors and let
03:06you copy and paste the hexadecimal values or the RGB values that you'll
03:09need for your project.
03:11If you have an Android tablet, you might want to check out Adobe Kuler for your
03:14device. Having a second screen is sometimes a convenient way to brainstorm
03:18your color choices.
03:20You can take a look at color palettes from the Kuler network or build your
03:25own Kuler patterns.
03:29When building a theme you can take a look at the individual colors and quickly
03:34modify a color by dragging these little color wells.
03:42Then you can get the color codes you need by moving this slider up and copying
03:47the colors into your web layouts.
03:50Although the program is not available for iOS devices as of this video, it will
03:54be available in the future.
03:55Another tool that I love on the Mac is a small app called Hues that's available
04:01from the App Store for $2.99 and lets you specify colors in any color mode.
04:06You can see the values right here. And if you specify an opacity, it also gives
04:12you color modes that are available and some of the new color models like the
04:16rgba color model and the hsla color model.
04:19Those models will only be available to you on newer browsers.
04:24Most element tools also have color pickers that you could use to modify
04:28the colors as well.
04:30One of the most common things that you do to form elements is create a gradient.
04:33The most common and easiest type of gradient is the linear gradient,
04:37so I am going to go to my codesnippets file and select this version of our
04:43body style and go back into our index file and replace the one that we've placed there,
04:47and you'll see that we've actually added a bunch of different things with this
04:51particular gradient.
04:52We still have a basic background color. And whenever you specify gradients you
04:57should always use this notation to make sure that older browsers that don't
05:01support some of these new features can see at least a basic background color,
05:06which will just look like that.
05:09In addition to that, we can create a gradient.
05:11Right now you can see that I have different browser prefixes for
05:14different browsers.
05:15You can see that I have the gradients specified in multiple versions.
05:19So I have a version for WebKit, which would be Safari; Mozilla which will be
05:23Firefox, Opera, Microsoft; and then what should become the standard way of
05:29specifying gradients without browser prefixes, right here.
05:32And then I have a little hack for older versions or Microsoft versions that
05:39don't support any of these linear gradients.
05:41Right now, the only one that's actually affecting our document is this one
05:45right here, because this particular version of the live preview is a Safari- or
05:50WebKit-based preview.
05:52So if I just show you this line of code--so you can see that this is a very
05:57slight gradient. If I scroll down, you'll see it getting a little bit darker, just
06:00because I want a very subtle version of this gradient to be on our background.
06:06In addition to that, what I have also done here is specified a background texture
06:10to appear on top of our gradient.
06:12And one of the cool things that you could do in newer browsers is be able to
06:16specify multiple gradients to appear on top of each other.
06:19So by adding this other call to a file that we've specked right here, we can add
06:25a gradient on top of our gradient.
06:26That's really convenient because I can add this texture pattern to a gradient
06:30that has any color in it.
06:32So if I specify a different color, I can use the same background image to be a
06:37texture on top of the gradient, as opposed to trying to create, you know,
06:41different gradient patterns for different files.
06:44So this is a really cool trick.
06:46Multiple gradients will give you the ability to put gradients on top of each
06:49other, and you can use transparency to build gradients on top of other gradients.
06:55Usually when I program these kind of background elements, I start off by creating
07:00the background for the particular browser that I am working on, and then I add
07:04all these other browser-prefix versions.
07:07Making gradients work in multiple browsers means you'll have to create multiple
07:11versions of the gradients with different browser prefixes.
07:14And that can be a little bit of a pain, so you can use tools like this Ultimate
07:18CSS Gradient Generator, available at colorzilla.com/gradient-editor, that
07:25simplifies the process of creating gradients by giving you a bunch of different
07:28little swatches where you can pick different gradients, and it writes the code
07:33out for you in multiple versions with all the browser prefixes.
07:37You can choose different types of gradients, like radial or vertical or
07:41horizontal or diagonal gradients.
07:43You can even try to add multiple gradient support in IE version 9.0, which
07:48doesn't normally support multiple gradients.
07:51This is probably the best tool if you are planning on working with gradients.
07:55If you are trying to do other elements that are not gradients, you might want to
07:59check out CSS3please.com, which lets you specify gradients, and it will write the
08:04code with the multiple browser versions.
08:06And in addition to that, you could see that it provides the prefixes for other
08:11things like border radius, web shadows, and other CSS3 elements.
08:16Creating backgrounds, especially if you use multiple layers, isn't just good for
08:20the body of your document.
08:21You can use the same techniques to handle any kind of form elements, including
08:25input fields, buttons, and this is definitely something you want to take time to
08:29play around and be comfortable with.
08:31To learn about general CSS styling, don't forget to check out James Williamson's
08:36excellent CSS: Core Concepts, available from the lynda.com Library.
Collapse this transcript
Using a seamless background with radial glow
00:01In addition to using gradients, you can also put a background image on any
00:05element, and since you can also use multiple backgrounds, you can combine
00:09background images with gradients to add some subtle lighting effects.
00:12So let's just check it out.
00:13Open up the exercise files, open up the Starting Points, find the starting
00:17points for this chapter, and copy the Working Folder onto your Desktop.
00:22Then I am going to drag that on to my copy of Espresso and open up the
00:27codesnippets by dragging it into the Workspace.
00:30Double-click on my index file to drag it also into the Workspace.
00:33I will move that over there.
00:35Hold on the Option key and click on Preview.
00:37It will give me live preview, and now I can open up my codesnippets.txt file and
00:42I'll find the section for this movie, and I'll copy this piece of code.
00:46You can see that I already have a texture here, and I am going to go back
00:49into my index file.
00:50I have to create a rule for the body, and I'll paste my code right there.
00:56All right, so as you can see here, I've specified a background image just by
01:00using the background attribute and specifying a URL.
01:03So without all this, this gives you just a repeating background image that's a wooden texture.
01:08This is actually a picture of the floor in my house that I took, and by adding
01:13a background gradient, I am able to layer a slight lighting effect on top of my image.
01:18You can use this if you are not using a background that repeats evenly.
01:23You can use this to maybe fade out an image or do other kinds of lighting effects.
01:27It's just a very, very basic, simple gradient.
01:30Radial gradients are a little bit harder than linear gradients, so let's take a
01:34look what we have done here.
01:35You have got a definition for a -webkit-radial-gradient.
01:38And instead of using a hard color, we can use a color that has transparency by
01:44using an rgba color value here.
01:46So this particular color value happens to be white 255, 255, 255 is white.
01:510, 0, 0 would be black.
01:54And we are specifying it to be 20% white on the outset.
01:59Remember that radial gradients are essentially a blend between two circles, and
02:04the simple gradient is done by just specifying two different colors.
02:08By default, they blend from the center.
02:10You can also specify a position here, so let me just modify this 0.2 to be 0.5.
02:15You can see that now it's a stronger gradient.
02:17So by changing this with the number from one to show 100% opacity on the inside
02:23version of the circle to 0, so now it's completely transparent--of course it
02:26doesn't show-- we can specify the strength of the gradient, so any number that
02:31we type in here will make the gradient lighter or more opaque.
02:35So I'll bring it back 0.2.
02:36This is the other circle right here, so this circle goes to no color, and
02:41that's the outside circle.
02:42So we are talking about essentially two circles, and I am blending between them.
02:46And so if we specify a number here, you could see that the second circle is 50%
02:50strength, which actually shows up because we specified a height here, and
02:54eventually it bumps into the background.
02:57So this is how you would do a sort of a fade- in into a circle, if you wanted to do that.
03:01And the other values right next to each color specify the position of the
03:06gradient, so you can make the gradient be sort of tighter by changing this number.
03:11So this is essentially not exactly a gradient, just a circle.
03:14So I could see a very slight variation there.
03:17We will bring this back up to 60.
03:20And then if you wanted to start with a little smaller circle, just do a 20 there
03:23and you could see that it changes the color of the gradient.
03:26So first you specify a color.
03:28If you use a transparent color, you can have a gradient blend into the
03:31background, and you then specify a position for the gradient, tell it not to
03:35repeat, because I don't want to repeat, and then as a backup, I am using the
03:39comma separator here to specify that I also want the background as a secondary
03:43element behind the gradient that I have.
03:46Because this gradient is transparent, I can see the background behind it.
03:49That's our final background element.
03:51It works pretty well, even in older browsers.
03:53Your best bet is to try to find a background that is seamless or repeats nicely
03:57and it looks like it goes on forever.
03:58So this particular background is a seamless background.
04:01No matter what size I make my browser, you can see that it just repeats over and over.
04:05There are a lot of different web sites that you can find seamless patterns or
04:09just generic patterns.
04:10In my case I took a photo of my floor.
04:11You can do the same thing.
04:13It's a little tough with just regular textures, but this is a great web site,
04:15texturise.com with an s, and you could see that they have a lot of different
04:20kinds of gradients and patterns that you could use.
04:24And if you click on Seamless, you can make sure that those patterns will repeat evenly.
04:29Another tool that I really like is a tool called Repper.
04:32You can go to repperpatterns.com, and it's a tool for creating patterns.
04:38And this is especially good for when you take a picture of something and you
04:41want to combine it into a seamless pattern that doesn't repeat.
04:44It's a little bit difficult because there is usually a lot of shading variations
04:48within the patterns that make them not repeat evenly.
04:51This is a program that you buy, so this is $43, a little pricy, but you could
04:56check out the demo to see what it does.
04:59In the case of my wooden background, that's what I did was use this tool to make
05:04sure that I could take a picture of a background that didn't repeat very well
05:07and played it around with where I position this selection right here, to create
05:12a version of the background that repeated very well.
05:14And you can go into tiling here and choose different ways that the program tiles.
05:19There are different ways of combining the patterns so that they tile with
05:22different options or choose backgrounds that don't necessarily tile but combine
05:27in different ways to give you a lot of patterns for you projects.
05:30So once you choose one of these, then you can actually apply colors to it, so
05:34you could apply different faded colors or adjust the settings for contrast and
05:40then once you are done with your pattern, you can hit Export, and it will save a
05:42tile that is already optimized for the web as a JPEG or a PNG, and you could use
05:47that in your projects.
05:48Of course, the demo gives you a low-quality version.
05:50I have enjoyed using it quite a bit.
05:52Just remember, too, that if you need help creating gradients, use the Ultimate
05:56CSS Gradient Generator.
05:57That gives you a lot of options on the different types of gradients and
06:00automatically writes the code for you in different formats using different color
06:05modes, and creating all the prefixes for all the different browsers.
06:09Sometimes it's just not possible to create backgrounds that are seamless, and
06:12you want to be able to use any kind of pattern that you have from either photo
06:16or a background image, and this particular trick of fading out your background
06:21and being able to control the background with a gradient allows you to fade
06:24things out and blend them into an existing color so that when people resize
06:28their browsers they will also see a pattern in your main area and be able to get
06:32a good background element, and be able to have a good experience, even with a
06:36background that is not seamless.
Collapse this transcript
Using custom fonts
00:00It's really exciting that you can finally use custom fonts not just on forms but
00:04on any web project.
00:06There is a couple of issues that you need to be aware of when using custom
00:08fonts, so we are going to review those and see how you can be ready to use them
00:11now on your projects.
00:13So we are going to open up the exercise files, open up the Starting Points
00:16folder, find a folder for this video, and copy the Working Folder onto our
00:21Desktop, holding down the Option key and dragging that so it makes a copy.
00:24Then I'll drag that into Espresso, and I will copy the codesnippets.txt file into my Workspace,
00:32double-click on the index.html to also bring it up into our Workspace, and
00:36finally I will Option+ Click on this Preview icon.
00:39It will pull up a live preview so we could see what's going on.
00:42This is really simple page.
00:44It just has two custom classes, and right now it doesn't have any styles.
00:48The ability to use custom fonts is not a CSS3 feature.
00:51It has been around for a quite a while. And technically it's really easy to use.
00:56You simply create a special rule that defines what the font name is going to be,
01:00called the @font-face rule.
01:02So we could do that by just simply creating a style section, typing in the rule
01:06that defines what this font is supposed to be called.
01:09So @font-face and we create a font-family, and you call the font-family whatever you want.
01:15Then you specify the location of where this font is in relationship to this
01:20document, so you just use the url attribute here and you would just say my font
01:24is in a TrueType file, and then you specify that this particular font is in a
01:30format that is TrueType. And whenever you want to use this font, you theoretically
01:34can just, say, add one of the your custom classes.
01:37You can make a custom class call here and just use the font-family to specify
01:42that this particular element is going to be using somefont.
01:45We don't really have a font called somefont that's TrueType, so this is not working.
01:49This is how easy using custom fonts should be.
01:51Unfortunately, things aren't perfect, and there are number of things that you
01:54will need to address when using custom fonts.
01:56First is licensing.
01:58If you want to use a font online, even one that you've already purchased before,
02:02you have to make sure the font is licensed for online usage.
02:05The other issue is that different browsers and different platforms require that
02:09the font be in different formats.
02:10For example, versions of Mobile Safari before 4.2 require that the font be
02:16stored in a format called SVG, which is really not very common.
02:20To make sure you are compatible as possible, you need to save the font in
02:23multiple formats, which include TTF, EOT, SVG, and WOFF formats, for different
02:29browsers and different platforms.
02:31And that makes the call to your custom fonts a lot more complicated because you
02:35have to call different versions of the fonts for different machines, and you
02:38even have to specify different weights of the fonts in their own calls.
02:42So the calls to fonts are usually quite complex.
02:45Thankfully, there are a couple of tools that you can use to make life easier for
02:48you, and one of my favorites is something called Font Squirrel.
02:52So Font Squirrel has a bunch of fonts that are available for free for commercial use.
02:57You can take a look at all the fonts that they have right here.
02:59You can take a look at them by different styles.
03:01You can also use a web site called Fontspring that has a few other fonts that
03:05are available for purchase.
03:07Once you purchase or download these fonts from either of these two sites, you
03:11will receive a folder that has all the different styles that you will need for
03:15your project, as well as the fonts in all of the different formats. And you
03:18simply just add the style sheet to your project and use the font as you normally would.
03:22So we will go back into Font Squirrel.
03:24We will look for font called orbitron, and here is the font we are going to use.
03:28So let's click on it to take a look at the samples.
03:31It looks pretty good.
03:33It has different weights.
03:34Font Squirrel also provides something called @font-face kit.
03:38Instead of giving you the font in just one format, like the OTF format that
03:42you can download here, you can actually click on this and it will let you
03:46specify which formats do you want to get the font in. And by default it's
03:50clicking on all the formats I just mentioned, which are required for being as
03:53compatible as possible.
03:54We can also just choose different subsets of the fonts here, and once you have
03:59got the font that you like, you could just hit Download @font-face Kit.
04:02I am going to go into the Downloads folder. And if I open up that file, I see
04:08that it downloaded the font in multiple formats--every format that we'll need to
04:13be as compatible as possible.
04:14It also downloaded a demo, which you can open up in a browser. Check out how the font looks.
04:19That looks pretty good.
04:21And it even added a stylesheet.css file that we can call into our project to
04:26automatically create all the different rules that we will need for using this font.
04:31So what I am going to do is I am going to move all the contents of this folder
04:35into the Working Folder.
04:36We can also do that by dragging the files into the Project Files within
04:44Espresso. And I am going to rename my style sheet to something related to the name orbitron.css.
04:51You will see that Espresso picked up all the files, and it showing it into the
04:55Project Files area. And I can take a look at that CSS.
04:59If we close up the tools here, you could see that it's essentially written out
05:03all the font-face rules in all their different versions.
05:05Notice that if you were doing this manually, it would just take you a long time
05:09to type all that stuff in,
05:10so this has already done the job of creating the @font-face rules, and now all
05:14you have to do is, when you want to use one of these font-face rules, you could
05:18just use them as you normally would.
05:20So I am going to go to my codesnippets file, and I will grab this copy of this
05:25call to the style sheet, and I will place it in my document so that it loads the
05:28style sheet from that file.
05:30Then I am going to go back here and grab my style definition and replace this
05:34demo style definition that I have done.
05:36So as you can see here, I have loaded up two different style rules: one right
05:40now for this font that we've loaded from our external style sheet and then
05:43another one that we will load from another place. And as soon as I added this
05:47definition, you see that my font over here has already changed to the new Orbitron font.
05:51So once you download the @font-face kit, it's as easy as looking into the CSS,
05:55make sure the fonts are in the right place--you see all the different versions of
05:59them right here--and then just using them as you would any other font.
06:02Make sure that you do specify an alternative, just in case this font, for
06:06whatever reason, doesn't load properly on the machine.
06:09So you should always specify a comma and then something that is an
06:12alternative to this font.
06:14Font Squirrel also has a really cool tool
06:17if you already have a font that you own and you want to convert it into all the
06:21different formats, plus you want to have Font Squirrel automatically write all
06:25of these rules for you. It's called the @font-face Generator and you can find
06:29that also on their web site.
06:30You can click on this link to the @font-face Generator, and in here you can
06:34actually upload you own fonts and it will convert the fonts to all the relevant
06:38formats and automatically create the style sheet with all the different
06:42@font-face rules for you.
06:44So this is great for if you have purchased a font, you know that you have the
06:47license for it, and you want to add that to your site, but you don't want to
06:50have to write all those rules. This works really well.
06:52Now the other option is to use a font service.
06:55Using this means that you won't download the fonts on your machine; the fonts
06:59will be hosted on a separate server.
07:01The most famous of those two services are Typekit, which you can go to at
07:05typekit.com, recently purchased by Adobe, which is pretty interesting.
07:09Adobe has a super-large library of amazing fonts, and so you should be able to
07:13see those and download those.
07:14Now they are probably a little pricier, since the other ones are free, but if
07:18you are looking for specific fonts, they are probably going to have the largest library available.
07:22The other place where you can use a service is Google Web Fonts, and this is also free service.
07:27So with Google Web Fonts, you can simply just choose a font and then you will be
07:31able to generate a link to the font file, and when your web app pulls up, you can
07:36simply just specify the font-family as you normally would, without having to
07:41worry about downloading the fonts and putting them in the folder and or worrying
07:44about creating the different font-face rules.
07:46So you could hit Start choosing fonts from this site, and right now they have
07:49302 families, and they are pretty good.
07:51They have a large selection already of a lot of different types of fonts. And so
07:55we'll do the search for a font called convergence, and there it is.
07:59Take a look at different font samples.
08:01If you want to, you could see it as paragraphs, single word--in case you are trying
08:05to specify a particular word that you are trying to type in and see what the
08:08font looks like--or you could just simply go to Quick-use.
08:11It tells you how big the font is and what it will take to download.
08:15And you can also add it to a collection and continue to see other fonts and add
08:18them all to a single collection.
08:20Right now, this particular font has only one style. And if you scroll down, you
08:23can see that just to add this font, all you need to do is just simply add this
08:28code to your web site. So I'll just select that and I'll copy this code.
08:33I'll switch back. And we already have the rules set up here to take
08:36advantage of this font,
08:37so all I need to do is just paste that code right here and as you can see, this
08:41font has already been updated to take advantage of this particular rule, and
08:45it's as simple as that.
08:46If you don't want to download a bunch of fonts and add font rules or have to
08:50worry about this, you can simply use a font from something like Google Web
08:53Fonts, which is pretty cool.
08:54One disadvantage to using font services for your custom fonts is that they won't
08:59be available when your web app is offline, which is normally not a problem,
09:03especially on desktops, but it can become a problem on hand-held devices: when
09:07they lose connection they won't be able to download the fonts,
09:10so make sure you always specify an alternative so that the browser knows how to
09:14display your font when it doesn't find it, it can't link to it because
09:17the application is currently offline.
09:19So using fonts seems easy on the surface, but because of different browsers and
09:23platform issues and licensing issues, they can get very tedious.
09:27Thankfully, there are a couple of tools like Web Fonts and Font Squirrel that
09:30can make your life a lot easier.
Collapse this transcript
Creating custom input and buttons fields with CSS3 PIE
00:00Making your forms look great means understanding how to work with a variety of
00:04CSS3 rules like gradients, drop shadows, and border radius.
00:09Unfortunately, making several of these elements compatible with older browsers
00:12is a real challenge.
00:14We are going to take a look at a library called CSS3 PIE that you can use to
00:18make older browsers try to understand and display some of these elements.
00:22We will also take a look at how to target different browsers, specifically
00:26different versions of Internet Explorer, so we can fix problems with those
00:29browsers when we encounter them.
00:31So we are going to open up the exercise files, and we are going to open up the
00:34Starting Points folder and find the folder for this chapter.
00:38Open up the folder and copy the Working Folder onto the desktop, and I'm going
00:43to drag that on to Espresso. And I'm going to find the codesnippets file, drag it
00:48into the Workspace, double-click on the index for this project to also open it
00:53up in the Workspace, and then I'm going to Option+Click on this Preview icon to
00:58bring up a live preview.
00:59So you could see this form is a pretty simple form. It's just an input element
01:04where you can type something in and a button right next to that.
01:08So let's take a look at how we are going to be styling that with CSS.
01:11I already uploaded this project onto a web server, and you could see that
01:15we've got a nice background with the same input and submit button, but we
01:20have added CSS3 gradients.
01:22There is an inside drop shadow inside the form element, also a background
01:25that shows an image, and an input field where you can type in some text to do our search.
01:30So we are go into out codesnippets files and find the code where we link to a
01:35couple of CSS files that I'm going to be using for this project.
01:37I want to copy that and go back in here and in this head section just paste those two files.
01:43The first one is our normalize.css file that we have downloaded from a web site,
01:48and the purpose of this file is to help us standardize, or try to make browsers
01:53as compatible as possible. So go in here.
01:56So I've already downloaded this file, and I'm linking to it in our HTML project.
02:02So here is the call to the normalize file. It is right here.
02:05We are also calling another style sheet called mystyle.css, which is right now empty.
02:09You can already see that when we add the normalize.css file,
02:13it actually changes the margins and the way that the buttons looks.
02:17So it's already doing some work right there and standardizing the way that the
02:21forms are going to look.
02:22Now we are also going to add another library called CSS3 PIE, which you can
02:26find at CSS3PIE.com, and the purpose of this library is to try to make older
02:32browsers, mainly Internet Explorer versions 6 through 9, capable of rendering some of
02:37the newer elements in CSS3.
02:39So you could see that it has some support for drop shadows, box shadows,
02:43and other elements.
02:44Unfortunately, it doesn't show up things like inset drop shadows and multiple
02:48backgrounds, but it tries to do as good job as possible, and it's continuously
02:52under development, so hopefully we will be able to see some of those things come
02:55in at a later point in the project.
02:57So you can click right here to download a copy of this, and then I'm going to
03:00open up the copy that it downloaded.
03:02You could see there are different versions of this file.
03:06You are going to need the one called PIE.htc.
03:08There are different versions of them that do slightly different things in
03:11different environments.
03:13So what we are going to do is we need to copy it into our current working
03:16folder, which you can do by simply dragging this either into this Project Files
03:20area right here in Espresso or by dragging it onto our Working Folder, which we will do.
03:25Copy that right there.
03:26It will appear right here in the Project Files in Espresso.
03:31So this particular library is not going to work if you preview it on your browser.
03:36At any rate, most developers don't have really old versions of Internet
03:39Explorer installed.
03:40It's something that you are going to have to see on a web server,
03:43so you are going to need to copy these files onto your server. And there's one more
03:47issue that you might have with this particular file that needs to be addressed:
03:50you will need to create a file that will make sure that your server understands
03:55how to read this file properly.
03:56This actually happens quite a bit with different types of HTML5 elements.
04:00A lot of times they are in a format that the server will not understand.
04:04In this particular case, we've got a file that's called PIE.htc.
04:08If your server doesn't understand how to deal with that HTC file, they will be
04:11served with the wrong type of information and your server will interpret them as text files.
04:16So in order to fix that, we are going to need to create what's called an htaccess file.
04:21So I'm going to show you how to do that on a server.
04:25You would go into an FTP program and connect to a server.
04:28So I already have a server that I've created to upload these files to, and I'm
04:33just going double-click on this shortcut right here.
04:35And on the server that you want to place this PIE.htc file, you want to create a
04:41file and call this file .htaccess.
04:45You can't really create this file on your local machine and upload it, because
04:49by default, an htaccess file--or any file that begins with a period at the
04:53beginning--will be an invisible file in some platforms like Mac OS.
04:58So if you try to create this file on your desktop, the file would either
05:01immediately disappear or it won't let you create it at all on the machine
05:05that you are working on.
05:06So you're going to have to do this in the server and hit Create new file here
05:09which you could do by right-clicking and selecting New File from Cyberduck--
05:13just about any FTP program will let you create a new file though--and type in
05:16the name .htaccess and hit Create.
05:20Once the file is created then you can edit that file. And in this case my default
05:25editor for Cyberduck happens to be Espresso,
05:27so I can just click on this file to edit it. And I'm going to need to copy
05:31something from the codesnippets, which is this command right here.
05:35So all that this is doing is letting the server know that from now on when it
05:38encounters files with the extension .htc, that it should interpret it as a type
05:44of text/x-component, as opposed to a simple text file.
05:47So I'm going to come over here, paste this, save this file,
05:51it'll upload it to my server, and I'm going to close it.
05:55I'm going to refresh Cyberduck, just to make sure that it did upload.
05:57Notice that now instead of having a 0 byte size,
06:01it now has 29 bytes, which means that it does have some information in it.
06:04You don't really need to do this all time.
06:06As a matter of fact, if you put this on this folder, any folders that you
06:09create in this same directory will also automatically pick up that command from
06:14this htaccess file.
06:15Htaccess files are quite handy for handling a lot of issues,
06:18so that's the way that you have to create them.
06:20It's a little bit weird, but it'll prevent you from having a headache and
06:23noticing that this PIE file is not working.
06:26So once you've done that then everything should be fine with your document.
06:29Just remember, before you upload the rest of your files you want to make sure
06:32that you have an htaccess file so that it knows how to handle right file type.
06:37So I'm going to close out of here and go back into our form and continue to work on this.
06:41So now I'm going to copy some additional code that will set up the basics of our
06:45HTML page, and it's going to reset the input type text fields a little bit more.
06:49So I'm going to copy this from our codesnippets.txt, and I'm going to go
06:53into mystyle.css file.
06:55I'll double-click on it so that it comes in to the Workspace, and I'm going to
06:59paste this bit of code right here.
07:01You can see that I already brought in a lot of different things.
07:03I brought in the background, and I am displacing the position of the form a
07:07little bit, by 50 pixels, and I am also calling the PIE.htc file in here.
07:13Now if you only want certain elements in your document to be backwards
07:16compatible with older browsers,
07:18you can just place this call in any element that you want to attach that to.
07:23If you want to make it available to all of your form elements, you could use the
07:26asterisk universal selector--and I'm using that here with the form selector to
07:30make sure that all my form elements are calling the PIE.htc file.
07:34So once I've done that then I reset some of the appearance in browsers for
07:38different elements, mainly the text fields right here, and I'm going to set the
07:41borders of things and the radius and all that other stuff to zero, clearing
07:44everything out. And here on the body section is where I add a basic background
07:48color as well as the background that has the little line pattern that I want.
07:52So let me go back into codesnippets, and we'll grab the next piece of code. And
07:57what we're going to do is, instead of trying to style the actual input field
08:00to have rounded edges,
08:02we're actually going to style the form element to look like an input field and
08:05make our input field to be placed inside that form element.
08:09So I'm going to copy this piece of code right here. And this is a really large
08:13piece of code, but it's really just a bunch of browser prefixes.
08:17So I'll copy that and go back into my style sheet and paste that right here,
08:21and you can see that it already started to add quite a bit of information into our style.
08:25So what we're doing now is setting the position of this element to relative and
08:30the width and the height to a certain width and height, and this particular
08:33piece of code right here, setting the element to have a margin of 0 and auto is
08:37going to center the element.
08:38Let me take these out so you can see them at work.
08:39So if I take that out, you can see that the element's still on the left.
08:42Right now, if I add that in, adding the margin zero auto is actually what's
08:47going to be centering that element in the middle of the page, no matter how
08:50wide I make the page.
08:51And I'm giving it a simple one-pixel white border.
08:54It's just like a slight border around the whole thing. And then I go through
08:58and I set different background elements. So this is adding a magnifying glass
09:02picture, or a magnifying glass image, which is right here, as well as a basic
09:07background color for older browsers, and I'm also adding this version of the PIE
09:13background command.
09:14So normally when you do background elements with gradients or background
09:18images, you will be adding a bunch of different rules for different browsers,
09:22including WebKit, Mozilla.
09:24So when you're adding gradients or background elements, you add a gradient for
09:29each type of the different browsers that you're using.
09:31When you are using PIE, you're going to need to add a background rule for PIE itself.
09:36There are other things like border radiuses and shadows that it will try to
09:41pick up automatically, but for backgrounds and gradients you're going to have
09:45to use this special call.
09:46So you should definitely take a note of that.
09:48The next thing we're doing is adding a little bit of border radius to our form element.
09:53So you could see that if don't add them, the borders are rectangular;
09:57if add them, the borders have that nice round edge.
09:59Then I'm also adding a drop shadow.
10:02So you could see that there's an inside drop shadow that gets added with
10:07this command right here.
10:08Let's go back into our codesnippets and keep on plugging along with the code.
10:12Now we'll style the input type submit.
10:14It's also another very big piece of code, but it's a bunch of different rules
10:18with a bunch of browser prefixes.
10:21So we'll go back here and we'll paste that.
10:23You could see that now our button looks really nice.
10:25I'm actually positioning this button to the right of the form element. But since the
10:31position of the container, the form element, is set to relative,
10:35if I position this as an absolutely positioned element, it's going to align it
10:39to the previous form element and align it to the right of that form element and
10:44give it about the same width and height and no border,
10:47so it doesn't have that default border that buttons have a lot of times.
10:51Then I set up a bunch of gradients again.
10:53They're really not that complicated, except that we have to add the
10:56different prefixes.
10:57Then I set some border radiuses for the button itself again, and some shadows as well.
11:02Plus I'm adding a border to the left so that I get an extra little border to
11:07the left of the image, so it has a more of an embossed look.
11:11Then I set the color of the text inside that input field from the default black to white.
11:16Finally, I also need to create a hover state, so when somebody rolls over this
11:20button, I want it to have a little bit.
11:22So I'm going to copy this and I go into my style sheet.
11:25I'll paste it right here, and now when I hover over the button, it shows me that
11:30slightly different gradient, but this is really just another gradient.
11:33Same sort of rules as this, just a different color.
11:36Go back to my codesnippets and do the same thing with the text field
11:41that's going to go inside.
11:42Right now the text field is a little bit further out.
11:44Because remember, it looks like right now the text field is this form element,
11:48but in reality the form element is what allows us to place this icon back there.
11:52We need to change this input field so that it moved a little bit over to the
11:56right and aligned a little bit better.
11:58So that's the next piece of code that we're going to add, back into my style
12:01sheet, and now our text, looks a little bit better, and it's positioned better. And
12:06these are just some plain simple rules: positioning this, floating it, and
12:10aligning it so that it shows up in the browser properly.
12:13Now we're also changing the outline property because some browsers will
12:17automatically place an outline on focused elements.
12:20That's another thing that you might need to take out in some of your projects.
12:24One last thing that you are going to have to worry about is that even with CSS
12:27PIE, some browsers are not going to be able to recognize all the rules.
12:31Thankfully there's a really easy way to serve different code to different versions
12:36of Internet Explorer.
12:38To do that, we can use a conditional piece of HTML that will display a slightly
12:42different style sheet to browsers that are older than certain versions.
12:46So I know that this particular code is going to look really well on all
12:49browsers, including IE9, but versions before IE9 won't display some of the
12:54elements. Specifically the submit button won't be displayed properly.
12:58So I'm going to copy this piece of code, and this is actually going to be added
13:01into our index.html file.
13:03It's not going to make an impact right here because this browser supports all
13:07the features, but by adding this piece of code, we're telling the browser to
13:11make sure that if the browser version is earlier than Internet Explorer 9, then
13:16it's going to modify the input submit button to not have a border and to not
13:21have the little extra left border right here, plus the shadow that we used in the element.
13:25So I'm going to save that.
13:26I'm going to show you how that works.
13:28I'm going to switch to Adobe BrowserLab, and I'm going to pull a version of this
13:32form that's finished and show you that using that code allows this form to display
13:39properly on Internet Explorer 7.
13:41It looks a lot better in Internet Explorer 9.
13:43It did pick up some of this gradient in Internet Explorer 9, and it looks
13:47wonderful in other browsers
13:48that can pick everything that we've styled on this form.
13:52And I'm going to take off my conditional code in the version that are uploaded
13:55to the server, and I'm going to tell Adobe BrowserLab to refresh and show that
14:01without the conditional code, Internet Explorer 7 does pick up the gradient and
14:05it picks up the border radius for the input submit button, but not the
14:08border radius for the form field.
14:11Even though CSS PIE tries to do its best to make things compatible in older
14:16browsers, it isn't always perfect, and you always have to watch out for this kind of thing.
14:20So I'd highly recommend using something like BrowserLab to always check your
14:23work across different browsers.
14:25I'm going to go ahead and also just take the call to our PIE file so that you can see--
14:29so I'm going to save this and I'm going to reload it--
14:31so you can see, without CSS3 PIE, the gradient doesn't get picked up properly.
14:36So CSS3 PIE does a decent job of trying to make things that are older as
14:41compatible as possible, but like anything else, it's not perfect.
14:44I think it's best to try to determine which browsers you are going to be
14:47supporting and making sure that you have something like BrowserLab that can
14:50check the version of your code in different browsers.
Collapse this transcript
Working with text fields
00:00By far, the most common element you'll style with CSS is a text type field.
00:05There are different flavors of the text field, like the input type text or input
00:09type password and the text area fields, and working with these fields is similar
00:14to working with other types of CSS elements.
00:16So let's take a look at how we would style them.
00:18I am going to open up the exercise files and open up the Starting Points folder,
00:24find the folder for this video, and drag a copy of it onto the desktop, and I am
00:30going to drag this onto Espresso.
00:32Finally, drag the codesnippets.txt file into the Workspace.
00:38Double-click on the index.html file to bring it up also into the Workspace,
00:42and I am going to also double-click into the mystyle.css file to also bring it
00:46up into the Workspace.
00:48And finally I am going to move this over to the side and Option+Click on the
00:53preview icon to bring up this form on a live preview.
00:56So you can see this is a pretty simple form.
01:01It has a few different types of input fields, as well as the text area field, and
01:06let's take a look at what it will look like when we get done.
01:08This is a version that's already being completed.
01:11See that we have a background element, and we have these different fields
01:15with different gradients and inset drop shadows, as well as an icon inside
01:19one of these elements.
01:20You could see that when I click on these, they highlight to a different color.
01:24So we are using quite a bit of CSS styling to accomplish all these things.
01:28Now we are also using a number of libraries with this project, like the
01:32normalize.css library available at this URL, as well as the CSS3PIE library, and
01:40this library tries to make some of the older browsers understand some of the
01:44newer features in CSS3.
01:46Now we've covered how to install some of these libraries in the previous movie,
01:50and you can also check the movie on setting up the exercise files to check out
01:55how to install these libraries into your projects.
01:58So let's go back into our files and we are going to open up the codesnippets.txt
02:02file, scroll to the section for this movie.
02:05We are going to copy this first piece of code, and notice that we are calling our
02:11normalize.css file that we have already installed in this folder, as well as the
02:16style sheet for this project and a custom font from Google web font.
02:20If you want to find out more about installing custom web fonts, check out the
02:24movie on using custom fonts.
02:26So I am going to copy that, come back to my index.html file, and paste this code
02:32into the head section of my site.
02:33You see that it had already--some of the normalizing takes effect, and I am
02:38going to go back into codesnippets and copy the next piece of code, and in here
02:43I am calling my PIE.htc file, which will try to make some of the older versions
02:48of IE understand some of the new CSS3 rules.
02:51So I am going to copy that and I'm going to go into my style sheet and paste that
02:56in. And we are clearing out some additional elements here, you know, making sure
03:00that all our input fields have an appearance of nothing and clearing out some of
03:04the other elements from here.
03:05We are also copying a special piece of code that is going to take care of
03:09fixing another issue that you run into when you are creating elements that are
03:14set to float in CSS.
03:16This is a common problem. And let's take a look at our index file to take a look
03:20at what we have done to fix this issue.
03:22So you see that this form looks pretty good, except for a couple of things that
03:27I am doing differently here.
03:28Number one is you see that I added a class called group, and that class is the
03:32class that I have defined in my index.css file. And the job of this class is to
03:38make sure that when I float elements the container of the element is going to
03:42be able to track the height of the floated elements.
03:46When you float items with CSS, whatever element contains those items is not
03:51going to be able to understand the height of those elements.
03:54If it doesn't make any sense, it will in just a minute, whenever I add some
03:57additional code, and I'll take these out so you could see what effect adding
04:01this CSS does to our files.
04:03So let's go back into the index and take a look at the other thing that we have done here.
04:07The other thing that's different is that most of the time when you create
04:10labels you use the for field to associate the label to an input element.
04:15So we have these labels right here with a for field.
04:18We have to add an ID to our inputs to make sure these two things are tied together.
04:23In the case of this particular file, we have actually used the label element to
04:27wrap our input field.
04:29So when you do that, the for and the ID fields are not necessary.
04:33So you don't actually need to have those, only in the case of where you are using
04:38the label as a container of a field.
04:40So we can actually get rid of these. Because the labels are wrapping the input fields,
04:46it is implied that the labels belong with the input fields.
04:51So we can take these out, the IDs as well as the for attributes in the labels.
04:58This is a little bit simpler to write, but it's not always as semantic as the other method.
05:02This format is easier to write when you want to place some of the labels on
05:06top of your input fields.
05:07For our labels, we are also going to copy some simple styles.
05:10We are going to first copy the background image for our body and as well as a
05:16simple form element that will just center this form and put it further down from
05:21the top of the screen. So I am going to copy this into mystyles and paste that so that we get the
05:26background. The form is now centered in the middle of the page, and we are
05:32going to go back into codesnippets and copy this code for the labels. Back
05:38into my style sheet file.
05:40I am going to paste that, and you can see that my labels are now sitting right
05:44now next to the fields.
05:45So let's go back into our codesnippets and actually grab the code for our input fields.
05:52And this is quite a bit of code, but again, it's just a bunch of different
05:55browser prefixes. So we'll go into our style sheet and paste this entire bunch of
06:00code that will actually do most of the styling for the different input fields.
06:05We have created some styling for the input fields that make them display as block.
06:11When you display an element as a block element you can set the width of the
06:15element, so we set the width of these fields to be 250 pixels, and we have also
06:21made these fields center by using this margin 0 auto.
06:25That way they will center on the middle of the screen as we resize the screen.
06:29You added a little bit of padding inside the element, so that when you click
06:34right here, the elements will have a little bit of breathing room.
06:37We have given it a basic background, which we then overwrite over here with a
06:41bunch of background CSS, plus added a border, which is white--
06:46you can barely see that border right here on the edge--and made the font that
06:50you type in here a little bit different by choosing that Ubuntu Mono, changed
06:54the font size, and then added a border radius to give the edges a little bit of
06:59a round feel, as well as added a very slight background gradient from white to a very light gray.
07:06Finally, we have added an inset drop shadow to each one of the elements, so
07:10you could see there.
07:12So if I take that out, you could see the shadow will be gone. It's kind of nice
07:15to see these when you take them out.
07:17You can see if we take out the gradient, then it just becomes this default
07:20color. And if we take out the radius, we could see that these fields
07:23become rectangular.
07:25Okay, now we need to do something with our Submit button,
07:29so let's grab the code for that, paste it into mystyles.css.
07:36You can see that we are floating that button to the right side, adding no border
07:42to get rid of the default border that buttons normally have, and then just
07:45adding some basic background color, as well as a little bit of padding to give
07:49it more breathing room,
07:51and just a little bit of breathing room overall, as well as a border radius to
07:56make it have rounded edges.
07:59So we can also add some code to make sure that our text fields actually change
08:04when they become focused.
08:06So I am going to copy this piece of code right here, and what that is going to do
08:10is add an outline that has a color of red when the element becomes focused.
08:16So whenever the element gains focus like this, I am hitting just Tab to tab
08:21through different fields. Then it will get an outline that is solid red.
08:26Now the outline is super similar to the border, except that the outline doesn't
08:31actually take up any space like a border would.
08:33So you would use border normally when you want to just add a border to an
08:38element, and the width of that border would actually affect the width of
08:42the element itself.
08:43Outline doesn't, but with form fields, when you wanted to style the focus, you
08:49have to use the outline field, not the border field.
08:51The border field won't have any effect on the actual outline of the element.
08:56So as you could see, we are using the pseudo-class focus to change how the input
09:01fields look when they become focused, and obviously how the text area's fields
09:07look when they become focus as well.
09:09So now we are going to add an icon besides one of our text elements, so I am
09:13going to go back to codesnippets.
09:13I am going to copy this code right here. Back into our style sheets.
09:20So you could see that in this field I am using the pseudo-class type=text to let
09:25us choose fields that are only of type text.
09:28This is the only text input field in the code.
09:31You can see that this right here is the only text input field that we have; the
09:36other one is an input type password, and the last one is the text area.
09:40And we've added a special class to this field to let the browser know that this
09:43is a required element, so we can add a background image or some other kind of
09:48styling to the required fields.
09:50What I have done here is I created a class called required. Because I want
09:54to make sure that when users type their text, the text doesn't start where it normally would--
09:58I want it to be indented a little bit--
10:00I have to add a little bit of padding to my forms.
10:02If I take that out, you'll see that the form becomes smaller, and now when I type
10:06text, it's on top of the background icon.
10:09The problem is whenever I change the padding of a field, it also affects the
10:13width of the element. So if I take the padding out, you'll see that my element
10:18actually becomes shorter.
10:19So I have to make up for that shorter version of the element by adjusting the
10:24width. So if I didn't do this, my form will be too big. By changing the padding
10:29left so it indents in and then changing also the width, which on most input
10:34fields the width is normally 250, and here I have to adjust the width a little
10:38bit to make sure that I give it that breathing room.
10:41And here I am styling the required input fields and adding a background image to
10:47it, as well as a slight gradient.
10:50This gradient used to be there. Before we just added to the left of it
10:54an additional image.
10:56So here is a normal gradient that you could see.
10:59It's the same colors.
11:00Down here we've added that same gradient, as well as a background image.
11:05We can't just simply add the background image because it would replace the
11:08gradient that shows up, so you have to add both the gradient and the background
11:11image. And that shows up as that icon that you see right there.
11:16Finally, we can also style things whenever we hover on top of them, so whenever
11:19we roll our mouse on top of some elements, we can also change a color.
11:23I'm going to open up the codesnippets file.
11:25So what we are going to do is when we hover over a label element, we are going to
11:31affect the way that the input type text field looks.
11:36So whenever we hover over an element, it's going to affect the way all these
11:40different types of fields look by changing the outline to solid orange.
11:46Using the pseudo-classes, you can give a bunch of feedback to your users when
11:50they do different things, like when they hover or when they click on a
11:53specific element by using these different pseudo-classes and with the
11:57different input types.
11:58So working with text elements is a bit different than other elements.
12:02We don't just have to worry about background patterns, but we can also take a
12:05look at things like customizing the way that our input fields work, when users
12:09hover over different fields or change the outline when things become focused.
12:13So there are a few extra different pseudo-classes that are available to your
12:17input and text fields that are not available in other places.
Collapse this transcript
Designing labels
00:00Styling labels is a lot like styling other elements.
00:03Remember that you can use gradients, shadows, and even images on your labels.
00:08Let's see how we can do some of that with CSS.
00:10So I am going to go open up the exercise files and open out the Starting Points
00:14folder, find a folder for this project, and copy it onto our desktop.
00:20Then I'm going to drag this on to Espresso, and I am also going to move the
00:26codesnippets.txt file in the Workspace.
00:28I am going to also double-click on the index.html file and the mystyle.css file
00:35to bring them into the Workspace, and finally, I am going to scoot this over
00:39and click on the index.html and Option+Click on the Preview icon to bring up the live preview.
00:44Now I am using a few libraries here, like the normalize.css library and the PIE.htc.
00:51You can find those at this location for normalize.css and at this URL for css3pie.
00:58You also find out more information about how to install and work with these in
01:03the video on exercise files.
01:05So let me start by going to the codesnippets file and slide over to the
01:10section for this movie, and we are going to start off by copying the code to
01:14include our normalize.css file and the mystyle.css file.
01:18So we'll copy that, bring into the index file, paste that right there.
01:23You can see how it's already affecting some of our elements. And then we are
01:27going to go back into codesnippets and we are going to copy some more of this
01:32basic resetting code.
01:33I'm going to copy that, bring it into the mystyle.css file. And by applying that,
01:39you will see that we've cleared the remainder of this style sheet defaults,
01:43we moved the form down a little bit by 50 pixels, and we made all the form
01:48elements transparent.
01:49We call the PIE.htc behavior, which will try to make some of the new3css rules
01:55work in older browser, and we've reset the appearance of the input type text
02:00fields right here, clearing out all the borders and everything else.
02:04Plus we have a clear fix for clearing items that we are going to be floating,
02:09which we will do in this particular form.
02:11If you go back into the index file, you can see that we've created a form with
02:15the class of group, and each individual item in here has also an additional class
02:21of group to make sure that the containers that have the elements understand the
02:25height of these elements.
02:27So we will go back into the codesnippets file.
02:30Our basic code here sets up a color for the background and then brings in a JPEG
02:35file as the background image for the body. And then we are going to center and
02:39position the form elements.
02:40I am going to copy this and bring it to mystyle.css, paste that in there, and
02:45you can see that with this piece of code right here, we'll bring in an image that
02:49we've uploaded into this folder. Just in case that it has problems with that
02:53image, we have backup background color right there.
02:57The form element has been positioned relative to where it normally is, and I've
03:03set up a width for the element here, and this particular piece of code here
03:06centers the element.
03:07If I take that out, you can see that the element left-aligns.
03:10But by doing this, the element will center on the width of the browser.
03:14You can't see some of the borders, so you can't see that there is an input
03:16field here that makes the item a little bit more centered, plus some other room right there.
03:21So we'll go back into codesnippets. And the way that we have coded this
03:26particular form is we set up a series of items in our HTML, so we have this item
03:32and this item, and these items are containers.
03:37Let's take a look what this project is going to look like when we get done.
03:40So this form is going to look like this.
03:42You could see the form is centered.
03:44We have a background image with a drop shadow, and we have a label, and to the
03:49right of the label, we have an input type text field. Because we want to style
03:53the input background, we are actually creating an element called the item, and
03:59that is what actually has this rounded border with a little bit of transparency on
04:03the background, and it contains this input field.
04:06So we are not styling the actual input field;
04:08we're making the input field be transparent and styling the item containing
04:13the input field, and as well as styling the labels with the background image and a drop shadow.
04:21So that's where we are going, and this is how we've set up the HTML.
04:24Each one of these items is going to have the background style with the rounded
04:27edges, and then the input fields are going to be styled inside that, and the
04:32labels are also going to be inside this container, and that's why we have applied
04:36the clearing CSS so that the container understands the height of these label and
04:41the input element inside it.
04:43So let's go back into the codesnippets, and we'll get the CSS for the items.
04:50This looks like a lot of CSS, but it's really just a few rules with a bunch
04:54of browser prefixes.
04:56So we'll go back into mystyle.css, paste that code, and you can see the
05:00background of item has taken over. And what we've done here--let me expand
05:05this so you could read all the browser prefixes together--
05:08so we just created a slight border, given it a little bit of a margin so that they
05:12have a little room between, so let me take out the borders.
05:15So you could see the border right there.
05:16If I take out the margin, you could see that there is a little bit less room
05:20in between the elements, and we've set up a height for each element; otherwise
05:24they look like this.
05:25It's not particularly good. They look kind of skinny.
05:28Then we set up a gradient that has a copy of the brown lines.
05:32This is actually quite interesting.
05:34We have a copy of the same background that's back here and on top of that
05:39background, we have created a gradient that goes from pure white to a
05:44slight white, at 30%.
05:46That's what this means right here.
05:47We are using an rgba color in combination with a solid color.
05:52So we are using rgba because we want this color to be partially transparent and
05:56show some of these brown lines behind the element.
05:59So right now the only one that's affecting this, because this is a WebKit
06:02preview, is this one.
06:04So if I take this out, you could see that there is no background, and you can
06:07see that we've got two layers: one layer with the brown lines and one layer with a gradient.
06:15If I don't put in the brown lines, it's actually going to still show part of the
06:19ones that are in the background that are little harder in this position.
06:23So if I take this gradient out, you can see that I have no white transparent
06:29gradient on top of that.
06:30We also set up a border radius,
06:32so you could see that it just makes everything nice and rounded.
06:35And we've also set up a drop shadow into these elements.
06:40Normally, I make the drop shadow black or an rgba color, but I just made it a
06:44hexadecimal, that is, one of these green colors, from the background, just to put a
06:48very slight drop shadow on that item element.
06:52So once we have that, we need to go into our codesnippets and grab the code for the labels.
06:59So in here we have added essentially just a label,
07:02we've give the label a width, and we floated them to the left.
07:06We've also aligned the labels in the center of the box and just given the boxes
07:12a white color, a little bit padding.
07:14Otherwise, I need to have this padding that will show to be the height of the other element.
07:20We added a leaf background as well as some roundness to the edges.
07:26You need to add that to the labels also, because the background is already
07:30rounded. And then we added a drop shadow that is inset,
07:34so the drop shadow goes inside the element.
07:37We've also added a text shadow, which makes the text a little bit easier to read,
07:41because of the pattern in the leaf texture that we grabbed.
07:44So that looks pretty good.
07:46We need to actually add some additional styles for the input type text, and we'll
07:51copy that and paste it, because right now if we look at the input type text field,
07:57it's kind of sitting not exactly where it should be sitting.
08:01We need to make sure that we format it appropriately,
08:02so in the mystyle.css we are going to add a bit of code to make sure that we give it a
08:07width, display this block, add some padding to it.
08:11Make sure that we clear the outline out.
08:14You could see that it's already taken effect over here.
08:16So setting a width, displaying this as block. We are floating this to the left,
08:21changing the size of the font, and some other styles there, and making sure that also
08:25the outline is transparent.
08:26You are not going to able to see what this does here, but if you are previewing
08:29this in Safari, Safari by default puts sort of soft-blue outline whenever you
08:34focus on an element, which become annoying when you want your elements not to
08:38show an outline at all.
08:39It kind of breaks the illusion of having this kind of cool transparent field if
08:44you see a big outline of a box right behind it.
08:47So this clears that out,
08:48this outline style right there, and there we have those labels.
08:52Now let's check this out on Adobe BrowserLab, so we can take a look at how
08:56different browsers support it, and go into BrowserLab. And I load up a copy of
09:01this document that I've already placed on a server.
09:04You can see that Internet Explorer 7 doesn't do a perfect job of taking care of
09:10some of those elements, but it does pretty well.
09:13I mean, I think this is pretty decent for IE7.
09:15If you go to IE8, it looks kind of the same.
09:18It doesn't pick up any of the drop shadow elements, definitely not the inset
09:21drop shadow that we styled, but Internet Explorer 9 does a much better job. And
09:26as we go other browsers, you could see that they do a much better job of
09:30understanding the styles.
09:32So this looks pretty nice.
09:34One way that you can style labels is by adding background images.
09:37I think it works really well. And you can use positioning to place them wherever you want.
09:41You should be getting the hang of styling individual elements by now. Practicing
09:45what you can do with backgrounds on existing elements is a great way to get
09:49better acquainted with more advanced CSS features.
Collapse this transcript
Custom radio and check box styles
00:00Radio and check box styles look dramatically different depending on the browser
00:04and platform you are using.
00:06There is a great way to style them to give them a custom look and feel, and we are
00:10going to take a look at how we can do that with CSS. However, just remember that
00:15it's not going to look perfect in every browser.
00:18So I am going to open up the exercise files and open up the Starting Points,
00:23find a Starting Point folder for this video, and make a copy of this Working
00:27Folder into our desktop, and I am going to drag that onto Espresso.
00:32I want to drag the codesnippets.txt file into the Workspace, double-click on the
00:38index.html as well as the mystyle.css files. And I am going to move this over to
00:44the left, click on the index.html file, and Option+Click on the Preview icon to
00:50get a live preview of our project.
00:52Taking a look at the HTML, whenever you use radio on check box fields, they
00:58usually appear as a group of elements.
01:01So we've created two distinct divs to hold the two different groups that appear
01:06over here as a group of items.
01:08So we have this div right here for the Food Favorites and for this Ratings area,
01:13we have a separate div that groups these elements together.
01:16Let's take a look at what this project is going to look like when we get done.
01:19I've already placed a version of this on a web server, and you could see that we
01:23are going to be doing quite a bit of customizing into the element.
01:27Now one thing that's going to be really critical is that we actually label our
01:31fields, because what going to be holding the background elements is going to be
01:35the label and not the input field itself.
01:39So we'll start up our form by going to the codesnippets file, moving over to the
01:45section for this video, and I am going to copy the links to my style sheets, to the
01:51normalize.css file and the mystyle.css document.
01:54I'll go back into our index file and add those on the head section.
01:58You could see that the normalize CSS file has already done a little bit of
02:03work on the form itself.
02:04We're going to go back into our codesnippets and copy a few lines basic code
02:09that resets some of the other elements and adds this group clearing code to make
02:14sure our container has the right height.
02:16So I'll go back into mystyle.css and paste some of that code in there, and you
02:20can see that we are just moving the form down a little bit.
02:23We are resetting some of the styles, of some of our elements.
02:27Right now, it says change this to be input type check box and input type radio.
02:32We are also calling this PIE.htc file that will try to make these things as
02:37backwards-compatible as possible with some other versions of IE.
02:41Let's go back into codesnippet and grab the next piece of code.
02:45This just sets up a pattern for the background.
02:47I'm going to go into mystyle and paste that in there.
02:51You could see that we have a background pattern on this.
02:54It's really just a little bit of code setting up a height for our background and a
02:59background pattern, as well as a very slight gray gradient.
03:03So you could see that there is our background that looks really nice.
03:07This diamond pattern, we are going to use this diamond pattern inside the form
03:11itself as well. So just by using a slightly transparent background we can change
03:17some of the colors in the gradient that's behind it and be able to use the
03:21same background for different purposes.
03:23So we'll go back into out codesnippets and grab the code for the form itself.
03:27Again, this looks pretty long, but it's just a bunch of different browser prefixes
03:31for the different types of things that we want to do here.
03:33So I am going to copy this, go back into mystyle.css, and get down here. Paste this thing.
03:40You could see that in here we are changing the position of the form itself so
03:45that it is centered onscreen, and we set up a width right here for it.
03:49We also set a basic color for the text elements within, add a little bit of
03:54padding, then add a little bit of text shadow.
03:56You could see the text shadow on the edge of some of these text elements.
04:01So if you take that out, you could see how it gives it a little bit more depth
04:04when you add the text shadow. Then we add,
04:06it's the same copy of the pattern, but this time we use a partially
04:10transparent gradient that is two shades of black.
04:14We are using the gradient as 20% black here to 85% black.
04:19So if we took that out, you could see that it would just be a solid color. And
04:23this gradient, by using the same exact pattern on a different color gradient, we
04:28can get a slightly different effect than on the basic backgrounds.
04:31So we could reuse this diamondpattern over and over.
04:34Finally, we give this thing a border radius so the edges have a little bit of a
04:38radius around them, and we also have a WebKit box shadow that just sets up an
04:44inset or an internal drop shadow inside this element, and that I think looks
04:49really good for this form.
04:50You're not going to be able to see that in all browsers, but it looks
04:52really nice from here.
04:55Going back into our codesnippets, we will look for some other pieces of codes.
05:00So in this particular form I am using some h2 elements for the titles of this section.
05:05So I am going to grab this piece of code, and it's just simply going to style
05:08those a little bit different, just to make a little smaller, and clean up some of
05:12the margins around the h2 tags.
05:15Next I am going to style the input type check box and the input type radio
05:20to actually hide them.
05:21In this particular case, we want to use a background that is going to be part of
05:26the label, so we don't really want to see these check boxes, although we still
05:31want them to be there so that they can't become active.
05:33Remember that because we associate the labels with the check boxes, we can
05:38simply click on the labels to activate the check boxes.
05:41We don't have to click on the check boxes themselves.
05:44So even though we hide them, we can still activate them by clicking on the label.
05:48So I am come back here to my styles.
05:51In this particular style, I am going to just hide both the input type check box
05:56fields and the input type radio fields, by setting the display of the elements to none.
06:02That clears them out and even though they are not visible, they can still become
06:05active, by clicking on the labels.
06:08So let's go back into our codesnippet.txt file.
06:11So here is the tricky part about this particular project.
06:15In order to have custom controls, we need to hide the normal check box or
06:20radio input fields.
06:21We've already done that with the simple rule that just hides the fields by
06:25setting the display of the fields to none, but we don't want to do that in early
06:29version of Internet Explorer browsers,
06:32so we need to modify our rules with a hack.
06:34We are going to be using a not pseudo- class, and the not pseudo-class lets us
06:39select elements that are not part of another selector.
06:43If we use a selector that doesn't exist, the rule will essentially cancel itself out
06:49and as far as any modern browser that understands this rule is concerned, it's as
06:53good as not using it at all.
06:55However, browsers that don't understand the not rule will ignore the rule
06:59altogether and not do any of these things that we are about to do to these form elements.
07:04Since older browsers do not understand the not pseudo-class or this not rule,
07:10they won't even try to display any of these elements inside the selector.
07:14So all these rules right here will be ignored by browsers that do
07:18understand this pseudo-class.
07:21Let's copy this code that in most browsers will take the input type check box
07:25field and the input type radio field and not display them.
07:30I've already done that here, but the problem is that on certain browsers we
07:35don't want to hide these input fields.
07:37So we are creating a rule that essentially will work in every browser except for
07:42early versions of Internet explorer. By using this not rule,
07:46the not pseudo-class lets us select elements that are not part of anything
07:50else. By using a selector here that doesn't exist,
07:54we are essentially telling new versions of browsers to perform these rules, in
08:00other words hiding the input type radio and the input type check box like
08:04we've done up here, and versions of browsers that do not understand this not
08:09rule, essentially Internet Explorer before version 9, will not perform any of
08:14these style changes.
08:16So we are going to take this piece of code right here and replace our code for
08:21hiding the elements right here.
08:23So now this code, although it's a hack, it will prevent versions of Internet
08:27Explorer that don't understand the not rule from hiding the elements.
08:31So we are going to do a few more of those, and we are going to grab a whole bunch
08:36of other style rules that will do things only on browsers that we want to target,
08:42which are browsers like Internet Explorer 9 and later versions.
08:46Just pretty much ignore everything before this and read these style sheets as if
08:51you were starting from this point.
08:53On browsers that understand it, we want to change our labels to display as block
08:57elements, float to the left, have a certain amount of padding.
09:01It's giving them a little bit of breathing room so they can have a background
09:04image in them and changing the cursor at the pointer, because normally when you
09:10role over an element it will show this default pointer.
09:14So let's go ahead and add those styles here.
09:16You will see that I've added them right here to show you that
09:22we've added a little bit of breathing room to each one of the form elements.
09:26We changed the cursor to pointer, so now when we role over these fields, even when
09:30we role over the labels, it will switch the pointer to hand tool that we can use
09:34to click on the elements.
09:36This is just a visual change.
09:39This is a rule that applies to all the labels, regardless of the type of labels
09:43that they are, whether they are for check boxes or radio buttons. And then in here
09:47I am putting different backgrounds.
09:49If the input fields are check boxes and they have a label, I want the label to
09:54have a background of this file called uikit.png.
09:58So that adds the check box backgrounds to the labels.
10:01Remember, the check box, not only is it visually showing you a different
10:06background, because if the item is checked and it has a label, then I am
10:11switching the background position of this particular file that has our user interface.
10:17Now I want to show you this file so you could see how it's built, but we are
10:21using something called a sprite so that I can use a single
10:25version of an image several times and display them in different positions to
10:30show different versions of the elements.
10:32So if you look at this file called uikit.png, you will see that in here I have
10:37different versions of the radio buttons and the check boxes and I can use this
10:41one file positioned in different places to show the different versions of this
10:46input fields when they get checked on and off.
10:49If we take a look at it, this file here, and we look at our CSS, you could see
10:54that I am using the same exact call to the uikit.png file in each one of the
11:00different versions of these input fields.
11:02So we are saying, I want to you to choose the input type check box and I want you
11:07to modify the label element--
11:09remember the label is actually what has this background with what looks like a
11:14check box or a radio button--and I want you to make that background this file
11:19called uikit at this X and Y position.
11:23At this X and Y position, minus 43 pixels, the uikit is going to show the
11:28unchecked version of our check box.
11:31And when we go to the style sheet and we see when we need a check version of the
11:36labels, you could see that the background position goes a little lower to
11:40position 0 and minus 65, so it picks up the checked version of this background.
11:47The same thing happens to the radio buttons. When I call the normal radio button,
11:51notice that I don't need any X and Y values that's because this uikit, by default,
11:56starts off with the unchecked radio button and when I look at the radio
12:01button that has been checked, I call the same file.
12:04Notice that when I am using the checked pseudo-class I don't need to set the background;
12:09all I do is set the position of the background to another X and Y position.
12:13So let's take a look at how the different versions of our files are
12:18handling these elements.
12:19So I am going to go to BrowserLabs and I am going to load a copy of this file
12:24that I've already uploaded.
12:27Although it doesn't look at great in IE7, it's still usable.
12:31These check boxes are still on.
12:33Similar thing happen on IE8, because we prevented some of these backgrounds from showing.
12:37If the backgrounds were showing, you would actually see the check box on top
12:41of the background, with the pretty version of the check box, and that just
12:44really doesn't look great.
12:45However, IE9 looks a lot better. It does use those backgrounds.
12:49It doesn't have the inset drop shadow or some of the other things, but
12:54anything else, like Firefox and any version of Chrome or Safari, will pick up
13:00the entire style pretty well.
13:02Although it doesn't look awesome in every browser, I think it looks pretty
13:05good, and it's still usable on earlier versions that don't support some of these
13:09new elements.
Collapse this transcript
Working with select fields
00:00Although we've been able to find creative ways to style other form elements,
00:04select and option fields are the black sheep of CSS styling.
00:08Although a lot of browsers will allow you to style many elements, browser
00:11support is very inconsistent.
00:13So I'm going to open up the exercise files, and open up the Starting Points,
00:18find a starting point for this video, and take the Working Folder, copy it into our Desktop.
00:24And I'm going to drag that into Espresso.
00:26We are going to copy the codesnippets.txt file.
00:30We're going to take it and drag it into the Workspace, double-click onto our
00:35style.css file to bring it into the Workspace, and the index.html file to also
00:40bring it into the Workspace.
00:42And then I'm going to Option+Click on the Preview to get a live preview.
00:45This is a really simple page with just a form element and a label for a select
00:53field with a few options where
00:55we can choose different options of food favorites.
00:58One thing that you'll notice about working with select fields is that clicking
01:02on the labels does not automatically pop up the list.
01:06When we work with check boxes, we can click on the label to activate the check
01:10box or the radio button.
01:12We can't really do that with this.
01:14So it prevents us from doing some tricks to create the styling that we need and
01:19properly hide the select field while still being able to choose it.
01:23So if we could do that, we could just hide the select field and still be able to
01:27turn it on by clicking on the label, but because labels don't pop up select
01:32fields, we can't use that trick.
01:34For this particular project, we're going to go to the codesnippets and scroll
01:39down to the section for this video and copy our style sheets that will normalize
01:46our CSS and call our mystyle.css file. So we'll go into the index document and
01:52in the head section we'll call those.
01:54You can see that it's already normalizing some of the fonts and the spacings in our elements.
01:59And now I'm going to go into the codesnippets and grab some of the basic styling
02:04to clear out some of the other form element defaults.
02:08So I'm going go into mystyle and paste that, and you can see that I am moving the
02:12form down, getting ride of some of the default appearance for elements.
02:16So that hid the outline of this select field and made everything transparent.
02:21We're also calling our PIE.htc file, which will try to make some of the new CSS3
02:27elements available for older browsers.
02:29So let's go back into codesnippets, and we will grab the next section of code.
02:34And this is just some basic code that will style different things like the
02:40background and the form field and then try to set a background for the select field.
02:45So I'm going to copy this and go back into my style sheet and apply it right here.
02:50You can see that we've added a background color, just a gray background, changed
02:55our form to be positioned in the middle of the screen, and given it a width so
02:59it kind of centers this in the middle of the screen.
03:02And then we made an attempt at styling our background.
03:05It actually looks pretty good on this particular browser.
03:08It is setting a background color, a border-radius. And I actually bring in a
03:14select.png file that is just the background with two different states.
03:18You can see them right here.
03:19If I activate the select box, it will switch to that second state.
03:25So when it's not selected you could see that it looks like its gray and by using
03:30this sprite, when I select it, you can see that it turns blue.
03:34So when it has focus it changes the background to the same background add a
03:38different position, and this is what we call a CSS sprite.
03:41We take a single file and we position it in two different places when we need
03:45an element to change.
03:47And this looks really good on this browser.
03:49We've done some styling to the option, which should theoretically show us a
03:54different style when we actually use the pop-up menu.
03:56However, you could see that Safari doesn't take any of the style that we've
04:00added here into account.
04:01We set the background to a gray color, changed the color of the font to a
04:05lighter gray color, and added some padding and text alignment.
04:09You could see that this WebKit version of this browser completely ignored
04:13everything that we have used in this styles for this options fields.
04:18This is kind of a depressing state for select fields.
04:21There is no way to make a lot of
04:23even the newer browsers behave consistently when displaying select fields or option fields.
04:28Let's take a look at how this file looks on different browsers.
04:32I'm going to switch over to BrowserLab and pull up a version of this file that
04:36I've already uploaded to a server.
04:41You could see that Internet Explorer 7 doesn't even bother changing the
04:44background of this element.
04:45Internet Explorer 8 does, but it places the default form element on top of
04:51the background image.
04:52It's not really horrible, except for this little select field element right here.
04:56And something similar happens in Firefox.
04:59This looks beautiful, except that you see this little form element that we can't get rid of.
05:04And then we go to Chrome, and that looks pretty good.
05:08Safari also looks pretty good;
05:10however, as we saw when we were looking at it on a live browser, Safari
05:15completely ignores the styling of the option fields altogether.
05:18I think your best bet is to just create some styles, test it in different
05:23browsers, try to find some sort of middle ground, and live with the difference, or
05:26just not try to style the select and options field at all.
05:31I'm not really holding my breath for browser manufacturers to fix some of these problems.
05:36I could see how some people might be confused by inconsistent control elements.
05:39There is a few ways that you can get around this with JavaScript, but that
05:43creates additional usability problems for people that don't have JavaScript,
05:47so that itself might not be the best solution.
Collapse this transcript
3. Laying out Forms
Floating fields
00:00If your forms are simple and have only text area and input fields, there is a
00:04couple of quick ways we can lay them out.
00:06So I am going to open up the exercise files, open up the Starting Points folder,
00:10and find a starting point for this movie.
00:14And I am going to copy the Working Folder onto the Desktop, take the Working
00:18Folder and drag it into Espresso, and I am also going to copy the
00:23codesnippets.txt file by dragging it into the Workspace, and double-click on the
00:28index.html file and the mystyle. css to open that into the Workspace.
00:33And I am going to put this on this side.
00:35First I am going to click on the index. html file and Option+Click on Preview to
00:41bring up the live preview of the form.
00:43It's a pretty simple form that has a couple of input fields.
00:46You can see a text input field and a password input field.
00:49Input fields and labels are by default displayed as inline items, which means
00:54that they'll all run together, and that may not be the best way to display them.
00:58So I am going to show you a couple of ways of laying out these elements, but
01:02first we need to go ahead and normalize a CSS file to reset the styles for all
01:06browsers and add a link to the empty CSS file.
01:09I am going to go back to codesnippets and find the section for this movie.
01:14And I am going to copy these two lines right here into our index file, in the
01:18head section, so we are linking to those two style sheets.
01:23And the normalize.css file will try to make these elements appear as consistent
01:28as possible in multiple browsers.
01:31So we are going to go back now into codesnippets and grab the first piece
01:36of code for our form.
01:38It is just going to have additional reset code and code for styling the body,
01:44which will place the background on the body, as well as the h2 and the paragraph
01:48tag that we see on the form.
01:50So I am going to copy that, bring it into the mystyle.css file, and paste it right there.
01:54You can see that the background_wood pattern that we have in our HTML file
01:59appears, and we have also the h2 tag and the paragraphs tag style with
02:03pretty simple styles.
02:04I am going to go back to codesnippets and grab some basic code for the form.
02:09And on this code, we are going to see the basic elements that style our
02:19background, which are just the width and a piece of centering code for the width.
02:24I am going to position this a little bit, 50 pixels below the top of the screen.
02:28And then we have some gradients with browser prefixes for the different
02:33browsers, as well as a radius for the edges of this form and a shadow, a slight
02:41shadow, and then finally we add a little bit of padding, so we are offset.
02:46We have a little bit of breathing room inside this form element.
02:49So back to our Codesnippets.
02:51I am going to grab the next piece of code, which will style the button.
02:54And back into the mystyle.css file.
02:59 We'll paste this.
03:02And in this case we are just creating some basic styles for the buttons, but
03:07because we want to align the button to the right-hand side of the screen, we are
03:10floating the button to the right.
03:12And that creates a little bit of a problem.
03:14Whenever you float an element, the container of the element loses track of the
03:19height of this element that's been floated.
03:22So what we need to do is clear the floating of this element by adding some code.
03:28And unfortunately, different browsers require different versions of this code,
03:32so I am going to go back into codesnippets and grab the next piece of code.
03:36So this will let the container know about the height of this element.
03:41And I am going to copy this back into mystyle.css, and I am just going to
03:45paste that right there.
03:46And I have created this in a class called group, so we need to add this class
03:51to the HTML element.
03:53We'll do that by going to the index file and adding a class right next to our login form.
03:59We have class already, but you can add multiple classes to an element by using a
04:03space between classes.
04:04So we could just simply type in the group class and you can see that
04:07immediately, the container understands the height of this element.
04:11One option for laying out this form is to align our labels to the top.
04:16So we'll get in- to our codesnippets file and scroll down to grab this
04:20version of the code.
04:21And I am going to paste that at the bottom of the mystyle.css form.
04:28You can see that now the labels are at the top, and what we've done here is just
04:32simply declared the labels of the document to be a display type block.
04:37That makes them appear on their own line.
04:39And then we set some basic fonts for it.
04:42And then for the input fields, all we are doing is just setting up a width to
04:46make sure that it aligns nicely with the edge of the form, and that's a pretty
04:50quick and easy way of setting the labels to appear at the top.
04:54So labels at the top of the form are a little bit better for mobile devices,
04:59because when you pull up a form in a mobile device, the browser in the mobile
05:04device will zoom into the form.
05:06And if you have the labels to the left of the form, it's a little bit difficult
05:09sometimes to read them.
05:10So let's go ahead and pull up this form in our iOS Simulator.
05:14So I am going to find the iOS Simulator.
05:16I am going to open up Safari.
05:18We'll need to drag this index file into our browser, so I am going to drag it
05:22from the Project Files into our browser.
05:25If I click on an input field, the form automatically zooms in.
05:29Now if the label was to the left of the form, we would have a hard time reading the label.
05:33But because it's at the top of the form, we can read it very well because it's right there.
05:38So if you are designing forms for mobile devices, sometimes putting the labels
05:43at the top is really convenient;
05:44however, sometimes there is a lot of room on horizontal layouts on desktop
05:49devices, so labels to the side might be better.
05:51So let's see how we could do that.
05:53I am going to go back into my codesnippets file and find this version of the
06:01code and replace from the label all the way to the input fields, so that we can
06:09have a new version of the code.
06:10You could see that now the labels are side by side, and to do that, we've
06:13floated the labels to the left but aligned the text to the right and then added
06:19some padding, and then we floated the input fields to the right.
06:23Now if you look at that on our mobile device--I need to make sure that I save
06:29this so that we can preview it on a mobile device, so let me save the
06:32mystyle.css file and then go to mobile Safari, hit refresh-- we could see that
06:37the labels appear to the side.
06:39I am going to zoom out all the way and when I click on the labels, you can see
06:43that the labels to the side are a little bit hard to read on mobile devices;
06:46people might have to click and drag to see what you are supposed to type in there.
06:50So definitely this layout is a little tougher for mobile devices.
06:54However, you could see that the other layout with the labels on top obviously
06:58takes up a lot of vertical room, so that might not be the best thing for desktop
07:03devices where you have a lot of horizontal room.
07:06But you know, most people use their mobile devices in portrait orientation, and
07:12so you'd really have to balance what it is that you want to accomplish and maybe
07:16perhaps do different layouts for different devices.
Collapse this transcript
Organizing forms with lists
00:00If you think about it, a form is really just a list of elements and labels, and
00:04some people like to code more complex forms with lists, especially when the
00:09forms have radio or check box fields.
00:11So let's see how you could do that.
00:12I am going to open out the exercise files and find the Starting Points folder,
00:17open that up, and then go to the starting point folder for this video, make a
00:21copy of the Working Folder into our Desktop.
00:24I am going to drag that into Espresso.
00:27Okay and then I am going to copy the codesnippets.
00:31I am going to move the codesnippets.txt file into our Workspace and move this over here.
00:37Double-click on the index file and the mystyle.css file to bring them into the
00:42Workspace, and finally I am going to resize this and click on the index file and
00:47Option+Click on the Preview to pull up a live preview.
00:52So this particular form doesn't have anything in the body section,
00:56so right now it doesn't look like anything.
00:58So let's take a look at how you would code this form without using lists.
01:01First, I am going to go into codesnippets and find the section for this video.
01:12And first I am going to grab this version of the form and paste it into an index
01:17file and the body section.
01:18So you could see that this is just a form.
01:21One of the problems without using list elements is that everything kind of runs
01:25together on a form. By using lists, we can have nice containers that are very
01:29easily targeted with CSS.
01:31So let's see how this same exact form could be coded with list items.
01:37So we'll go back in here and copy this version of the form.
01:41It's a little bit longer.
01:44Back into the index.html file, and I am going to replace this form element with
01:50the new version of the form.
01:51You can see that it already looks more organized.
01:53We are going to have to do a few things to get rid of these numbers that an
01:57ordered list places when you create it.
02:00So, I don't necessarily want these numbers to be there.
02:03But you could see that our lists are now nicely grouped into list items, so
02:07every label and input field in a list item.
02:10And when we get to the radio fields you can see that that is coded as a sublist
02:16that is inside this other list element.
02:18So again, it's easier to get to targets when you group them into elements in HTML.
02:24So, let's see how would style this.
02:26First I am going to go back into codesnippets.txt. And the first thing I am going to
02:30do is just copy the normalize and mystyle.css links into our HTML.
02:37So back in here, I am going to go up and I am going to paste this into our head section.
02:42You could see that some of the styles are already being applied over here.
02:46And then back into codesnippets, we are going to grab just a little bit more
02:52normalizing code, as well as a float- clearing piece of code right here, just in
02:57case we float any items when we are designing this form.
02:59So, I am going to copy that, click on the mystyle.css document, and paste that.
03:04And it cleared some additional things about this form element, so we're ready to start
03:08to start our main styling for this form.
03:10So back into codesnippets, and we are going to get some code for the body element.
03:15The body element is just going to have a nice background with a bunch of
03:19prefixes. So I am going to go into mystyle.css, paste that, and you could see
03:24there is just a gradient that goes from top and bottom, and we have all the
03:28different browser prefixes here.
03:30So and that's why it look so long.
03:34So back into codesnippets. Now we are going to style the form element itself.
03:39It looks super long, but it's just a bunch of different things we're doing with
03:44prefixes for the different browsers. So I am going to paste that, and you could
03:48see that I get a background with a pattern and a gradient behind the pattern, and
03:55you could see that we have also moved this center form element and moved it
03:59down a little bit and set up some padding and a border.
04:04So everything else is just making the edges round here and also just adding a
04:09shadow onto the form.
04:10So it looks a little nice, but we have to make it really long to make sure it
04:14works in as many browsers as possible.
04:16Okay, so we are going to copy the next piece of code, which is going to style the
04:22input fields and the buttons. And I am going to copy that back into the
04:27mystyle.css, and I am going to paste that.
04:29You could see that the input fields get a nice border around the input fields, a
04:36white background, and they get a width and they get aligned also to the right so
04:40they aligned with the right of the form.
04:42And our buttons are also aligned to the right by floating them to the right, and
04:47thank goodness we have the clearing code that makes sure that the form element
04:50takes into account the height of each of these other elements. And we have some
04:55padding and just some backgrounds with the different browser prefixes.
04:59So, if you look at it like this, you could see that the button gets a background
05:06right here, and different versions of different browsers use these different
05:11prefixes to make that work.
05:12And we also give it a little border again.
05:14Some browsers give button borders and some don't,
05:17so that's why we have to clear them all out first and then insert them back in
05:19at a later point with CSS.
05:22So this form is looking pretty good. Some of these other elements aren't
05:24perfectly aligned yet, but we'll fix that in a minute. Back into codesnippets.
05:29And now I am going to add some code to fix our list items.
05:33So I am going to copy this into my style sheet, and I am going to paste this
05:43code. And when we get done with it, you'll see that the form looks really beautiful now.
05:48So let's go into the different pieces of what we are doing.
05:51The first thing that you have to do with any list items is make sure that you
05:55clear the default indentation that happens with form elements, the default
06:01indentation that happens with lists, and also get rid of the number system that
06:06happens with lists as well.
06:07So, if you get rid of this, you can see that ordered lists by default have a
06:12little bit of margin to them.
06:14So by clearing this out, we make sure that our forms align a little better.
06:18And then whenever we have an item like this, we are not targeting the first
06:23level of the lists, but we are actually targeting the second level of the lists.
06:28So we are doing something similar to make sure that our set member of this
06:31Beginner and Pro section are check boxes that are a list inside this other list element.
06:36So we have to deal with how we want to pad them in this case and how we want to float them.
06:41If we didn't float these elements, they would not align properly to the edge
06:45of the other fields.
06:46So, a little bit of cleanup there. And then each individual list item that is a
06:51second level list item
06:53we have to display as inline so that they appear side by side, because you may
06:58want your radio buttons to appear right on top of each other, but if you don't,
07:01you have to change how that second- level list, not the first-level list, but
07:06the second-level list displays.
07:08And if you set it to display as inline, the radio buttons will come right
07:12up next to each other.
07:14Then we have to worry about styling our label and our labels, as you could see
07:19right here, for the second level list.
07:22So this is dealing with ordered lists inside other ordered lists, and for that
07:26we need to apply some styling to make sure that they don't this, because these
07:31list items, if they don't have custom styles, will take up the same structure as
07:37these normal list items.
07:39And so we want to get those to be a little bit different, and so we are
07:42fixing that right there.
07:43Finally, we need to also take into account the labels right here for these
07:49elements, as well as this element right here. And if you look at the HTML, you'll
07:53notice that this element called Sign up for is not really a label, because the
08:00labels on radio buttons are placed to the right of the radio buttons themselves.
08:06These are actually the labels.
08:08Whereas in the Username and Password, we can style the label field itself,
08:12because it's to the left of the fields.
08:14When we get into this label group, we need to have a separate label that is not
08:19attached to a specific element like these other ones are, and so we need to style
08:24both the list item labels, which are right here, as well as this other class that
08:31I created called a group label that will group these elements together.
08:35And that just gets a specific font and some other basic alignment and display
08:40elements, as you could see right here.
08:42So, this targets this label as well as these other labels and by separating a
08:48style with a comma, we can define a style for two different fields or for two
08:53different elements in the same place.
08:54So we are making sure that those styles all match together and are the same.
08:58Let me pull up a BrowserLabs over here. And you could see that the layout is
09:05not perfect in Internet Explorer 7, and the form looks decent on these other older browsers.
09:11It looks a lot better on 9.0 and Firefox.
09:15It looks really good.
09:16It really picks up everything on some of these more modern browsers.
09:20If you want to try to emulate some of these elements into the older browsers,
09:24like the gradients, you may try to use CSS3 PIE.
09:28I don't use that particular library all the time because it can cause problems,
09:32especially when you have more complicated forms or more complicated layouts in
09:37your forms. But you may give it a shot and see how well it works with something
09:41like BrowserLabs to check out how they work in older versions of browsers.
09:46And with any of these kind of advance lab techniques you are going to have to
09:50make a decision as to how far back you want to support.
09:53I think as long as you give a decent experience to older browsers, it's a good
09:58thing, but don't go overboard trying to make everything work on every single
10:01browser and platform.
Collapse this transcript
Grouping elements
00:00Creating groups of form elements helps you organize the content in your forms
00:04into sections that can be used for layout purposes, or just to make the
00:08information in a long form easier to read.
00:11You can organize the information using the field set tag and add a title to the
00:15form through the legend field;
00:17there are some compatibility issues, so we'll take a look at how we deal
00:21with grouping elements.
00:22I'm going to open up the exercise files, and open up the Starting Points folder
00:27and find a starting point for this movie.
00:29I'm going to grab the Working Folder and make a copy of it onto the desktop.
00:36And then I'm going to drag that folder into Espresso.
00:39I'm going to get the codesnippets.txt document and drag them to the workspace,
00:46double-click on the index.html file.
00:49For this project we're using something that you might have already seen in James
00:53Williamson's CSS: Core Concepts classes.
00:56Some of these assets are from things that he has done on this particular course,
01:01if you want to take a look at how he creates the styles for this project, make
01:04sure you take a look at this course.
01:06We are going to isolate our form element CSS into a separate CSS file, so for this
01:12project we have a main.css file that we're already calling in here, and we're
01:17going to call this form.css file.
01:19We're going to double-click on it, because that's the one that we're going to be
01:23working on, and I've isolated all the form code into the separate file.
01:27So if you go to the index page, and you Option + Click on Preview to see the file,
01:33you'll see that the page itself has a lot of different styles that are already
01:38built into the project, and we're just going to add a form here, and add a
01:42form.css to style the form.
01:49So obviously the first thing we need to do is go to the codesnippet and make
01:53sure we include the form.css call into our index file, so I'm going to go into
01:58the HTML document and right after the call to the main.css, I'll add another one
02:03to our form.css file and we're going to add some styles into that form element.
02:07So going to switch to codesnippets again and we'll get a simple version of our form.
02:13So I'm going to select that and copy it and paste it into an index file,
02:20I've saved a large hole right here for our form, so I'm going to paste that in there.
02:25You can see that we have a basic form, right now it has no styles, other than
02:30the default browser styles, so everything is kind of running together, all these
02:34input fields are running together, we have a list, we have a text area and this
02:37is just your typical comments form, and it has a little bit of James' humor, So
02:43pour your heart out, and Oh really?, which is cool!
02:46And we're going to style those, but it's a really simple form, pretty
02:50straightforward, just different form elements, so we'll go to codesnippets and
02:56create some basic styles for some of the fields, so we'll grab this and this
03:01is just making the label block element, the input fields, giving them a width,
03:06and styling our submit buttons, and go into the form.css file, we'll paste this in here.
03:12You can see that the form already takes up quite a good look and feel with just
03:17a little bit of code that we've added here.
03:19So just some basic styles, it doesn't group these elements into different
03:24sections and we're going to do that right now.
03:25So if you take a look at this form, there are two distinct groups of
03:28information in the form.
03:30First there is user information area and then a couple of questions about the
03:34type of information that people need to type, and a few questions about the
03:41information that you're after here and then the actual comments field.
03:45So in order to create groups of elements, HTML provides the field set tag and you
03:50shouldn't arbitrarily create groups of elements just to put them together, the
03:54fields should be related into different field sets.
03:57So I'm going to grab some code with this same form already split up into
04:01different field sets and this is pretty much the same code as before, but
04:06we've added these field set tags right here and you see the other group is right there.
04:11So I'm going to grab this, it's a little long, but it's the same code as before,
04:15just with these additional field set tags.
04:18I'm going to copy that, go back into my index file, and I'll just replace this
04:22entire form right here with the new version of it.
04:26So when you add a field set, by default the browser places a border around the
04:30section, you can see that it created this border.
04:32And I think it's pretty ugly, so we need to go ahead and redefine the way that
04:38the browser is displaying these things.
04:40So we're going to grab another piece of CSS, back into our codesnippets, and
04:45you'll see that I just have some basic styling, because I really don't like the
04:49default sort of border that the browsers give onto field sets.
04:53So I'll just grab that, go back into our form.css, and I'll add this.
04:57And this is just making sure we get rid of that ugly border, giving it a
05:01background color and then actually giving it a radius only on one side of the
05:08form, so you could see the radius is right here, not on the other side, and just
05:13adding a little bit of breathing room into the form, so that already looks a lot
05:17better than it did just a minute ago.
05:19So you can add headlines to your different field sets by adding a tag called the
05:24legend tag, and the legend tag describes what these sections are about.
05:29The tags are pretty simple.
05:30We'll go into our codesnippets and grab another version of our form, this one is
05:34again the same as the previous version, except that it adds a legend field right
05:38here and right here to define a legend for each one of the field set sections.
05:42So I'm going to grab this code, and I'll copy this, go back into our index file
05:49and I'll replace this version of the form.
05:54And you could see that at the top of our forms, we see these legends that define
05:59what the forms are supposed to be about.
06:01Now I don't really like the way that the browsers display this and as a matter
06:06of a fact there's a problem because there are some serious inconsistencies
06:09between the different platforms when they display those borders.
06:13If you go to Internet Explorer and take a look at this form, you'll see that the
06:17legends are displayed within the field set box.
06:21In any other platform the field sets are around the border, which I don't really
06:25agree with it being around the border like this, but that's the way most browsers
06:29treat it, and so we're going to have to do some code in order to fix it, but
06:33let me show you how this looks on different browsers.
06:35So to do that, I'm going to make sure that I save this file, and I'm going
06:40to actually upload it to a server, so that we can pull it up in BrowserLabs
06:44to take a look at it.
06:45So I'm going to close these things out and I'm going to open up my FTP program,
06:52which is Cyberduck and I've already created a link to our server.
06:58If you need help with this make sure you take a look at the movie on setting up
07:01your working environment.
07:02So I'm going to double-click to open up this shortcut to our server, and I'm
07:08going to open up the Working Folder and copy all these files into our server, so
07:14just click and drag, it will take a second to upload all the files.
07:20Once this is done, we can switch over to Adobe BrowserLab and pull up this web
07:24site address into BrowserLabs to see how it looks on different browsers.
07:28So as you can see we're looking at this thing in Internet Explorer 7 and the
07:33field set display is inside the box, which really seems like the right way of
07:37doing it, but any browser like Safari, or let's try Chrome, it's right here on
07:45the edge of the border of the field set, you can see Firefox, everything else,
07:51other than Internet Explorer, let's check out IE 9.
07:54It also displays it within, so we're going to have to figure out a way of
07:58making it look the same on different browsers, and it's going to be a doozie,
08:02let me show you how you do that.
08:06So, I'm quitting out of Cyberduck, because I'm done with that and I'm going to
08:08pull back my Espresso window and what we're going to do is go back into
08:13codesnippets, and the first thing we need to do is actually hide the legend, so
08:19we're going to hide the legend that appears right here, and then we have some
08:23special code to actually add the legend back into browsers that are not Internet Explorer.
08:30So, we are going to make the legend disappear, except on browsers that are not
08:34Internet Explorer. In those browsers we are going to add the legend back using
08:39the before pseudo-class, this pseudo- class will add content into a container.
08:45In this case it's going to be the field set container.
08:47So we are going to take this legend out of here and we are going to put it at
08:50the top of our field set.
08:51So let me copy this, and go back into our form.css file and we'll add this piece of code.
08:58What we are going to do is hide the legend, and then we added some code that
09:03is going to add this legend back into the field set using an attribute called title.
09:09Now, we don't have that attribute yet, so all we've managed to do here is hide the legend.
09:13So I'm going to go back into codesnippets and what I'm going to do is add the
09:17title field into each field set, and what that second piece of code is going to
09:22do is take this title and put it at the beginning of each field set.
09:25It's going to add the legend back into the form inside at the top of the field set.
09:31I'm going to copy this form code and go into our index file, and then I'm going
09:36to find the form and replace it and this is the same code as before, but all we
09:41have done here is added the title tag into the field set, and with our little
09:48hack that we are doing here, we have told the field set, to add the beginning
09:53of the field set, add itself, the title tag, and that's what this is, and then we
09:58have defined a style for how that's supposed to look.
10:02Now this sounds really awesome, but Internet Explorer 7 does not support the
10:06before pseudo-class. This will work in every browser, except for Internet
10:10Explorer 7, so we actually need to do another part of this hack which will be
10:15adding a special piece of code, so that we allow Internet Explorer 7 to display
10:20the tag as it normally would.
10:22So we'll go back into codesnippets and grab our last piece of our hack here, and
10:27what this will do is this is conditional code for telling things that are lower
10:31than, and that's what this lt stands for, Internet Explorer 8, so Internet
10:35Explorer 7 and before.
10:37Since it already displays the legend inside the field set anyways, we're
10:41just going to tell it how to style that legend so it displays properly on those browsers.
10:46I'm going to copy this piece of code, this will go in the index file and we can
10:52put this in our head section, so it goes before anything else.
10:57And now this will display adequately in all browsers, including Internet
11:01Explorer 7, so let me go ahead and save this and I will hide these again.
11:08I will pull up my copy of Cyberduck, and we are already logged into our form.
11:15I'm going to open this working folder and copy all these files in there.
11:19I probably don't need to copy the images file, let me just copy the CSS and
11:26the index file, since this is the only things that we changed, and we'll hit Continue
11:35here to replace those files, and now let's go back into BrowserLab and refresh our browser.
11:42And as you can see Internet Explorer 9 is looking pretty good, let's go back
11:46into Internet Explorer 8, it also looks pretty good, both of those browsers
11:50understand the before pseudo-class, so they take the first part of the hack
11:54and Internet Explorer 7 doesn't, but because it already displayed the element
11:59in here, all we had to do is create a hack just for Internet Explorer 7, and
12:02if we look at other browsers like Firefox, they will all pick up the proper
12:07styling for that element.
12:11You should really look at grouping similar content into content groups whenever
12:15possible in your forms. We've also managed to learn about a couple of ways to
12:19handle form inconsistencies which continues to be a very challenging topic
12:24when dealing with forms.
Collapse this transcript
Floating groups
00:00If you're using field set tags to group elements in your forms, the field set
00:04tag becomes a container that can be floated or positioned with CSS.
00:08In this video I am going to show you how to take advantage of the extra space
00:12in some desktop browsers by floating the elements in our forms so that they are side by side.
00:17We are going to start from the files in the previous movie on group and form
00:21elements, so if you have that working folder on your desktop, you are ready to go.
00:25Otherwise open up your exercise files and find the Starting Points folder and
00:30find the starting point for this video.
00:34Copy that into the desktop, and I am going to drag that into Espresso, opens
00:43it up as a project.
00:44I am going to drag the codesnippets file into the work space, and I am going to
00:50double-click on the index file and open the _css folder and double-click in
00:55the forms.css file.
00:57So you could see that this file already has a lot of styles in this forms.css.
01:02We're going to modify them, so I am going to drag this over here so that we
01:05could see what this looks like, click on the index file, option click on the
01:09Preview icon to get the live preview, you could see that this form looks
01:14pretty good already.
01:15But there's a lot of horizontal spaces that's been unused and on desktop
01:19browsers where you have windows that are pretty wide, it will be nice to be able
01:23to just have these two things side by side.
01:25It doesn't really bother somebody to see these elements side by side and
01:29especially on desktop browsers we can take advantage of all that extra space.
01:33So let me show you how to do that, I am going to move this and just resize this
01:39window, so we could see our code.
01:46First thing I am going to do is go into my codesnippets and find the section
01:49for this movie.
01:51And what we need to do is we need to change the way that these field sets are
01:55styled, because since we want to have one container that has both field sets in
02:00it, we need to not give a background and width to each one of the fields sets,
02:05we need to actually create a container for both field sets that's going to have
02:09the background in it.
02:10So we need to get rid of a few styles and I am going to start off by copying
02:14this part of the code here from the snippets file and going into our form.css
02:20and we are going to replace this part right here, the field set, the legend and
02:24the field set before with new version of the code.
02:27And all I'm doing these is just getting rid of the background that happens in both elements.
02:32So you can see -- I am also floating these elements so that they are side by side.
02:37So I took out the border which I did before, I floated them to the left,
02:42they weren't floated.
02:43I made the elements 50% of the horizontal room on the container that they're
02:48in, which right now is a form container and I adjusted the padding and the
02:52margin, because I don't really want it to have margins or padding, I don't need
02:56breathing room around these form elements, I just need breathing room around the
03:00form element that contains them.
03:02And we also modified the field set before, which was a little hack that we
03:07were doing to make sure that the way that the legends were displayed was
03:11consistent across browsers.
03:13One thing we do have to do is grab this piece of code right here from the field
03:18set and make sure that we also add that in the index file where we created a
03:24little hack to make sure that IE 7.0 was able to display the legend in the same
03:30way as other browsers.
03:31And really all I am doing here is just getting rid of this width of 80%,
03:35just pretty much taken that out.
03:38Make sure that this style is consistent in this field in Internet Explorer 7.0.
03:43So back on to the codesnippets and as you could see this looks great except
03:48that now we have lost that really nice background.
03:50So we're going to need to go back into our snippets file, you can grab the code
03:56from here if you want to.
03:57And I'm going to go and now I need to define a style for my form element and
04:02that's going to be form a contact and because I am using floats, let me copy
04:08this and paste this it into the CSS and see how it looks.
04:13So I've got the form contact as an element here and I am giving it a
04:18background color with this kind of brownie light brown that you see right there,
04:21and it looks really good as a color, but you could see that because these
04:26elements are floated, the container, the form container, has lost track of the
04:32height of these elements.
04:33To fix that we need to have a clear fixing code which is what we've done right
04:37here, we created a group tag that automatically clears the floats on these
04:41elements so that the container here understands the height of these other field
04:46sets and is able to display things properly.
04:48And now that we've created a class, we have to go back into our index file and
04:52make sure that we add that class into the form element.
04:55So here is our form code and all we have to do is add the class group for this
05:02form and you could see that it fixes the height of this background
05:05appropriately and if we scroll over to the right we'll see that it even has the
05:09rounded edges on that one side.
05:10So this is actually a very cool thing to do on forms in desktop browsers where
05:17you have a lot of room, but it's not the best thing to with mobile devices
05:21because as you know they zoom in when they see this code and you wouldn't be able
05:25to see the form on the right-hand side.
05:27You may want to use media queries to handle some of that and you can check out
05:30the video later on, on dealing with media queries to take a look at how you
05:34can accomplish that.
Collapse this transcript
Positioning groups
00:00Occasionally you'll want to place form elements with pixel precision. We also
00:04want to learn how to hide default input field borders, so we are going to take
00:08a look at creating a custom form layout that uses a background image and CSS positioning.
00:13So we are going to open the exercise files, and open up the Starting Points
00:18folder, find the folder for this movie, copy the Working Folder onto the
00:25desktop, drag that Working Folder into Espresso so that it opens it up as a
00:30project, and I am going to move the codesnippets.txt file into my workspace,
00:37double-click on the index.html file to also bring it into the workspace, and
00:42open the form.css file, so that it also comes up in the workspace.
00:47So we'll move that over, click on the index file and Option + Click on the Preview
00:53icon to get a live preview.
00:55This form looks very similar to forms that we've worked on in previous movies
00:59but there are some significant differences that I need to talk about here.
01:02So if you look at the index file, we've got this form section right here, and
01:07we've got our labels are wrapping our input fields, and we've created a separate
01:13tag with a hidden class to make sure that we are able to hide the labels; the
01:18actual text of what's inside the labels for these elements.
01:21We don't really want any of these to show, we want a background to show that
01:26has a richer texture, so we are hiding these by putting them into a class that we can hide.
01:32Now let me show you what this form looks like so you can get an idea of what
01:35this is going to be when it gets done.
01:37So I pull this up in a web site that already has the form built in and we could
01:42see that we don't really see the text labels, but we can type comments into
01:47here. So you could see I also have a custom font that I am using from Google web
01:52fonts. If you want to find out more information about working with custom fonts,
01:55make sure you check out the movie on using custom fonts.
02:00So you could see that some things we can't really achieve, some special effects
02:05with CSS, it's really hard to get this sort of textured labels with CSS, it's
02:10practically impossible, and we also want to do a different kind of image button
02:15for our normal button here.
02:17I am going to go back and show you the rest of how this is structured.
02:20So we definitely want to be able to hide the text inside each of the labels and
02:24we are using the labels, because we want to position these labels at different
02:29places within the postcard.
02:31So we want to have a nice container that we can use to position things wherever
02:34we want, so we wrapped every one of these input fields into the labels, which
02:39is perfectly legal.
02:40When you do that you also imply that when you click on the label, you are going
02:45to activate the field itself.
02:48So we don't have to use the for element like we normally do on labels, if we're
02:52placing the input fields inside the labels, it's implied that when you click on
02:57the label text that you want to activate the input field.
03:00So we've done that as well.
03:01Another thing that we have done is we have changed the tab index order, because
03:05on this form we want the comments to be the first thing that people tab into in a
03:10browser, so when we go through this form, we get to this form and we tab, we want
03:17to tab into the comments field.
03:19Now normally the comments field wouldn't be the first thing on a page, it would
03:22be right after you type in your name, email and web site address.
03:25So structurally it's correct to have it after each one of these other fields, but in
03:30this particular case, the comments belong on that side of the screen, so they
03:35should be positioned first.
03:37So I have changed the order, even though I have quoted it in the normal way, I
03:41have positioned these elements however I want to, so the comments will actually
03:44be on the left side and appear first, and therefore, get a better tab index.
03:49Now another thing that I did from previous files is I got rid of the legends
03:54that normally appear on top of the different fields sets, I don't really need to
03:57see the legends, so I don't need to code them either.
04:00In addition to that we've gotten rid of a little piece of conditional code to
04:04make sure that those legends appeared in Internet Explorer 7, again, I don't
04:08need the legend, so I don't need to code them.
04:11One final thing is you'll notice that my button appears here with a value of
04:17nothing, that way the text for the button will not appear in my browser, and it's
04:22not something that I need to also hide with a special code.
04:25So the button is there and I am going to put it right on top of an image, the
04:30value of the button is nothing, so that it doesn't appear.
04:32So let's get into our code and we'll go into the code snippets file, and we'll
04:37find the section for this movie.
04:44So the first thing we need to do if we look at this plain code is get rid of
04:47these ugly borders for the field sets, and also make sure that all our labels
04:53are hidden, so we are going to copy this code right here and take that and put
04:57it into our form.css file.
04:59You can see that immediately we lose all the field labels; don't panic, you are
05:03going to see them in the form elements.
05:06You are going to see them in the background.
05:06We have taken all the text inside the labels, and we set the display of them to
05:12nothing, that way they also disappear, and we could just put these elements where they belong.
05:16So next up, we need to put the background into our form and we are going to do
05:21that by targeting the ID frmContact, which is the ID of the form itself.
05:25So all we are doing is loading up a background and then specifying a width and
05:30height for this image, and we're also setting the position of these form
05:34elements to be relative, which is really important, so let me copy that and go
05:38back into our form.css, and I am going to paste that in there.
05:42Now we can see the graphic up here behind the form and we need to just position
05:45some of these elements with CSS.
05:48And let's go back into our codesnippets, and the first area that we are going to
05:54position is this comments area.
05:56So I am going to grab the code for this comment area and copy it, I'll go back
06:00into my form.css file and paste it right there, and although it almost looks
06:06like nothing happened, if you were looking before, the actual comments field was
06:10the really big text area field right here and it's already been moved into
06:14position where it should go.
06:18So it's already where it needs to go, and the way that we did that is by setting
06:23up the position of the field set that has the comments field as absolute.
06:29Whenever we set the position of an element to absolute, it's going to position that
06:33element in relationship to some sort of anchor, something that will anchor the
06:38position of this new element.
06:40By positioning our elements using CSS, we can change the order and position
06:44elements outside of their normal flow.
06:47Elements in HTML are drawn according to the order that they have been coded in.
06:52When we use the positioning attributes,
06:54we can change that normal flow into whatever we want.
06:57Once you set the position of an element to absolute, we take it out of its
07:01normal order and place it according an anchor.
07:04The anchor is going to be one of two things.
07:06Either a container of the current element, whose position has been set to
07:11relative or absolute, or if that doesn't exist, the position of the element
07:16relative to the body tag.
07:17So if we anchor this to another element, like we've done here by setting the
07:21position of this comments field set to absolute, we have anchored it to
07:26whatever container has this element, in this case the form element that
07:31we've set to relative.
07:32If this position relative right here didn't exist, it would keep on looking up
07:37the DOM, the DOM tree, to see if there is any other containers that had a position
07:42of relative, and if it didn't find any of those, it would anchor itself to the top of
07:46the page or the body tag.
07:49So by changing this position to absolute, you could see we can move the element
07:54to another position and of course we can't see it right now, so let me just give
07:58it a border, and we are not seeing a border probably because I am resending the
08:04border somewhere else, so not a good idea.
08:06So let me type in some text in here and change the position of this object.
08:13You could see that that text is going to move according to the position that I
08:16specify here that's relative to this image, which is the background of this
08:22form element.
08:25So the next thing we are doing is we are positioning the text area element
08:29inside the field set and in that case we're changing the position of that
08:33element to absolute, so it's actually aligning to its previous container, which
08:38will be this field set, and we are specifying a width and height and essentially
08:42just making it be the width and height of this box right here, so as we type
08:47things in, eventually when we type too many things, it will scroll up and fit
08:52really nicely into our comments field right there.
08:55So that just sets the position of that element as well and now we can go back
08:59into our codesnippets and do the rest of the fields.
09:01So in here I am going to set a generic style for all of the input fields.
09:06Notice that my input fields are all hanging out up here, having a good time,
09:10kind of on top of their form elements.
09:11So I am going to copy this right here and these other styles to modify the
09:18way that they look, and I am going to click back to the form.css file and I am
09:25going to paste that.
09:26You could see that they have now moved into their normal position right here.
09:31So, let's take a look at that code a little bit.
09:37First we setup some generic styles for the input fields, making sure that we
09:41hide the normal appearance of those elements in different browsers, setting the
09:46background to transparent, so it doesn't have that white background that they
09:49normally have, setting up a font and here I am using a custom Google web font,
09:53wherein it's called satisfy, which gives that nice sort of handwriting look, set
09:57up a color and some other just generic things.
10:00I have actually set up the opacity, so the font actually blends a little;
10:03it lets us see a little bit of this brown line like what would happen if you wrote
10:06with a pen on a post card.
10:08And then after that then I am setting the position of the field set, so the
10:12field set actually has all these elements inside.
10:15Then I set up a basic style for the labels, all three labels, the label for the
10:22email, the name and the web site address. Remember the label doesn't just have
10:26what we used to read, but it also the input field them self.
10:29So I set the position of it to absolute and the first element is always going to
10:34be at the position of its container.
10:37The container right here is set relative to the position of its container which is
10:41the form element, so if I change the position of this you can see that it moves
10:46from the left-hand side.
10:47If I move this it moves up and down and this first field is already positioned,
10:54aligned to this container, which is the field set, and all I need to do after
10:59that is just change the position of the email and the web site fields, so that
11:05they move down from the top of where this field set is.
11:08So if I move these you could see that they'll move to a different place.
11:13So I just keep on adjusting those numbers until they align perfectly.
11:17So it's looking pretty good.
11:18We still have a weird sort of empty button right here that we need to style, and
11:23for that button what I decided to do was create it as a separate element, so
11:27let's grab the code for that and that element is this input type submit button.
11:35I am going to copy this code, put the code in the form.css file and that places
11:42the button as a separate element and it hides all the styling for the button
11:47here, positions it as a absolute.
11:50Now this button is also positioned, it's in the code, it's outside the fields sets,
11:55you could see the field sets are right here, and here, and this button is
11:59actually sitting outside.
12:01So its position is relative to the form element itself, and it gets a background
12:08of postcardsendbtn, it's a PNG file that I have placed in the images folder and
12:14you could see that when somebody hovers over the submit button; so if somebody
12:19hovers over the input type submit, I get the same copy of the image just at a
12:24different position and that's called a CSS sprite.
12:26So if we look in the images folder, we can look for the postcardsendbtn.
12:33Here is what the button looks like.
12:35So it has two different looks for when somebody hovers over the button and
12:39when somebody is not hovering, and what we do with the CSS is just use that same
12:44file, just position 50 pixels down.
12:47If I change the position of this button, when we hover over the button, you
12:52could actually see the button being misaligned, but by putting it perfectly at
12:5750 pixels up from where it used to be when hover over the element we'll just get
13:02immediately the second version of the button.
13:07So understanding absolute positioning and its relationship to relative
13:11positioning is a real critical skill and one that you need to have plenty of
13:15practice with to be successful in web development.
Collapse this transcript
4. Using HTML5 Additions
Exploring new input types
00:00HTML5 offers a lot of new elements that you should start using right away.
00:05They work fine even in older browsers and provide a couple of enhancements to
00:09users with modern browsers. Let's take a look at some ways to improve our forms
00:13with new HTML5 input types.
00:15I'm going to open up the exercise files and open up our Starting Point folder,
00:20find the starting point for this movie, and I'm going to drag the Working Folder
00:25into our desktop, and I'm going to drag that folder on to Espresso, so it opens
00:32it up as a new project, and I'm going to double-click on the index.html file,
00:38then Option + Click on the Preview to see a live preview.
00:41We're not going to really do a lot of coding on this particular movie, because
00:45I'm just going to show you how these different elements work.
00:47If you want to find out more about HTML5 elements you should also make sure
00:51that you check out Joe Marini's excellent course on HTML5: Web Forms in Depth
00:57from the lynda.com library.
00:59So HTML5 has added a number of new input elements; normally we use input type
01:04text to allow users to type in textual information, and for an email field you
01:10could also use an input type text, but HTML5 provides a special input type
01:14called the type email that has a few benefits.
01:17Now I'm using a Safari based browser here and it doesn't fully support this
01:21text, so we're not going to see a huge change in how the browser deals with
01:24this tag, but other browsers will actually have some advantages when using the proper input type.
01:31So the first thing to know about using new HTML5 input types is that browsers
01:36that do not understand the new input field will simply display them as text, and
01:41this is because any field that does not have an input type automatically
01:45defaults to a standard text field. You could see right here it's not taking the
01:50style because we haven't told a field width, we've only asked fields with input
01:54type text to show this new style for this particular field, but it still works
01:59as a normal text field.
02:00So I'm going to put that back and in addition to that any other browsers
02:04that doesn't understand new input elements will just treat them as regular text elements.
02:08The second really cool thing to note is that super modern browsers like Chrome
02:12will actually perform validation on some of these fields, so if you pull this
02:16form up in Google Chrome, and to do that I'm going to grab the index file from
02:20the Project Files, and drag it onto the Google Chrome icon.
02:24When the form comes up you'll see that it looks just like it does over here and
02:29when we type in something in the email field, if it's not a valid email and we
02:34try to submit the form, Google Chrome actually performs a little bit of
02:38validation and it let's us know that it's not a valid email field, which is kind
02:43of handy. Just by adding the proper input fields we can have some of the
02:46browsers perform automatic validation without having to write any JavaScript.
02:50Now this doesn't work in a lot of places, but it's a huge improvement that we
02:55achieve just by simply using a different input type.
02:58The third thing you'll notice is that users with mobile devices will also get
03:02some improvements from using these new input types.
03:05So I'm going to pull this form up in the iOS Simulator and we'll take a look at
03:08what it does when you use some of these new input fields.
03:10So let's check this out on an actual iOS device.
03:14I've put these files on a live server so that we can look at them on a regular iPhone.
03:18And I'm going to click on the first field which is a regular text field and as
03:22you can see when I click on that it gives me the normal iOS keyboard, but if I
03:26click on the email field you can see that the keyboard changes so that it has an
03:31@ sign at the very bottom of the screen.
03:33Same way if I go to the web site field, which has a type of URL, I get the slash
03:39and the dot com at the bottom of my keyboard and I don't get the spacebar
03:43because normally URLs don't have any spaces.
03:46If I click on the age field I get a custom keyboard that has the numeric keypad
03:50at the very top of the screen.
03:53And if I click on date and time, you could see that I get the default iOS date picker.
03:59And I can pick a date and a time, because I've chosen an input type date and time.
04:04Although you don't have a lot of custom styling options on the iOS devices,
04:09you get some really nice improvements to the way users can enter information
04:13by giving them custom keyboards and custom UI elements that they can use to
04:18enter their information.
04:19Make sure you check out Joe Marini's excellent course on the lynda.com online
04:23training library to find out more about the new form elements and how you can
04:27use certain work arounds, some custom input fields into older browsers.
Collapse this transcript
Working with new attributes
00:00As useful as some of the new input types like URL and date/time are in
00:05browsers that support it, there is a number of new attributes available in HTML5
00:10that will enhance the way your forms work and since they are new attributes, you
00:14can also use CSS attribute selectors to style them.
00:17Now remember that browser support varies widely when working with these new
00:22input types and attributes.
00:24So let's take a look at how you would implement them in a form.
00:27Let's go ahead and open the exercise files, open up the Starting Points, open
00:32the folder for this movie and copy the Working Folder onto the desktop.
00:36And I'm going to drag that onto Espresso, and I'm going to double-click on the
00:44index.html, and the mystyle.css file because we'll be working with those.
00:49I'm going to click on the index.html and Option + Click on Preview to see the
00:53live preview right here.
00:55So one of the new useful attribute types is autofocus. Autofocus will
00:59automatically highlight a field and place the cursor in there when the page loads.
01:04So if we tell the email input field to have the keyword autofocus, then as soon
01:10as the page loads this input field will automatically be selected and the user
01:15will be ready to type something in as soon as the page loads.
01:18Of course only one element should have this autofocus attribute.
01:22Another useful attribute is the autocomplete attribute and on browsers that
01:27support this, it will try to auto complete a form the second time the user types in a value.
01:34So if a user comes back to your site they will be able to see some of the
01:38information that they've already typed into the form fields.
01:41This is good of course also if you have certain input fields that you do not
01:45want to have auto completion on by default.
01:47Say if you're asking some sensitive information like somebody's social
01:51security number, you don't want to have that information appear in and be
01:55stored in an autocomplete field.
01:57So to use that, all we have to do is type in the autocomplete keyword, and
02:05either type in on or off if we want to turn that feature on and off.
02:09And of course the browser that is implementing this has to have the ability to
02:13keep track of the autocomplete, or it has to have autocomplete features and it
02:18has to be available to this input field.
02:19So we'll turn that on, I'm going to show you that in Chrome, which actually
02:23supports that feature, so I'm going to drag my index.html file from my Project
02:27Files onto Google Chrome, and in Google Chrome if I fill out a field with some
02:34data and I submit the form, the next time I try to fill that field with the O,
02:41that information will automatically come up in a pop-up list.
02:44And that can be handy and it can be dangerous information to store in
02:48this particular browser, so you can turn that on and off with the
02:51autocomplete feature.
02:53Another Boolean attribute that is quite handy is the required attribute.
02:57On browsers that support it, it will add validation that prevents the form from
03:01submitting without this field being filled.
03:04So I'm going to add that to the email field, I'll just say, I'll just add the
03:08keyword required, and I'll add that keyword as well into the county field.
03:14So I just in required and I'm going to save that.
03:17I'm going to go to Google Chrome, refresh this form and if I try to submit the
03:22form and I haven't filled out those fields, it's going to ask you to, please
03:25fill that information out.
03:28It's also doing validation here so of course I have to type in a valid email address.
03:32And now I could hit the send form then the form submits properly.
03:36So if I don't fill those out it will ask me to please fill them out, because I
03:41put in the keyword required.
03:42Now of course that only works with browsers that support it.
03:46The nice thing about these new input types is that we can target them with CSS
03:51using the Type selector.
03:52So, since we've got these two fields as required fields, I can go into the
03:56stylesheet, mystyle.css, so we can target the required fields by simply
04:02typing in the input and then in brackets typing in any attribute that we've typed in there.
04:07We're going to type in the required attribute, and then we're going to add a
04:11style that sets the outline of input fields with the require attribute to solid red.
04:19And I'm going to save that, refresh that, and now you can see that in Chrome
04:23those fields with a required attribute are automatically outlining with this red border.
04:29One more handy feature is the placeholder attribute.
04:33If you add the placeholder attribute it will give some instruction to the user
04:37as to what they are supposed to type.
04:39So I'm going to add the attribute to the email field here.
04:42I'll just put placeholder and inside I'll just ask for Please enter a
04:47valid email address.
04:49I'm going to hit save.
04:52And if I refresh this page, you can see that if I don't have the email address
04:57in focus it gives you that little instruction right there.
05:00As you soon as you'd click to highlight that field, and you type something in, it
05:04disappears automatically.
05:06Finally, there's another attribute that's handy for validation when supported
05:10and that's the pattern attribute.
05:12It allows you to specify and pre-validate a pattern to be used when the visitor
05:16enters information into a field.
05:19So let's add that to our age.
05:23In order to use the pattern attribute we have to change the type of this field
05:26from number to text, so this has to be a regular text field and what we do is
05:31we add a pattern attribute, and in the pattern we can type any normal regular expression.
05:38So I'm going to type in the number 0-9, plus, so that's at least one number
05:45or more, and I'm going to hit save, come over here and refresh.
05:49Now I've got some required fields here so I better type those in.
05:52And I'm going to go down here and type in something other than a normal age.
06:00If I try to send this it asks you to, Please match the requested format.
06:04So that is one place where you may want to type in some additional instructions,
06:09so perhaps the placeholder or the title attribute might be handy in there, so
06:13let's add those as well, age, placeholder,
06:17Please enter a valid number for your age, or we could use the title attribute.
06:25We'll save that and refresh and now at least we're giving the user some
06:30instruction as to what they're supposed to do in that section.
06:34The one nice thing about these attributes is that we can style with CSS by
06:39targeting with the attribute selector.
06:41Make sure you check out Joe Marini's excellent course on HTML5: Web Forms in Depth.
06:47If you're interested about patterns and text fields you can also check out this
06:51web site html5pattern.com that has a lot of useful patterns for different things
06:56like credit cards and other things that you may use with the pattern attribute.
Collapse this transcript
5. Styling for Handhelds
Creating a responsive form
00:00When designing with different devices in mind, it's great to create a form whose
00:04width is based not on pixels or other static measurements, but that can grow and
00:09shrink with the size of the device.
00:11There are a couple of things you want to watch out for so let's take a look.
00:13So I am going to open up the exercise files, and in the exercise files I am
00:18going to find these Starting Points folder and I am going to look for the
00:22starting point for this movie.
00:23I want to copy the Working Folder onto the desktop, and I'm going to drag that
00:30Working Folder into Espresso, which will open it up as a project.
00:34And then I am going to find the codesnippets.txt file and drag it into the
00:39workspace, double-click on the index file and the mystyle.css file to open it up
00:46in the workspace as well.
00:48Finally, I am going to drag this to this side, I'll click on the index.html and
00:53Option + Click on this Preview icon and that will give me a live preview.
00:57So this form has three different parts to it and each part is divided
01:01into different legends.
01:02The first part has some basic login information, the second part is just
01:06information we want to gather about the user, and the third part is comments
01:11that the user can type in.
01:13Everything is coded into an ordered list and we have added some HTML5 input
01:19attributes like required and autocomplete and use some new HTML5 input
01:24types like email and URL.
01:26If you want to find more information about using the new input types and
01:30attributes, make sure you check the videos on working with new attributes
01:33and new input types.
01:35So let's see what this form looks like when it is done.
01:38As you could see the form has some styling applied to it and when we resize
01:43the browser the form will actually shrink and grow up to certain point, so that's our goal.
01:49Let's see how we could do that with CSS.
01:51First thing we are going to do is go to the codesnippets.txt file and find the
01:56section for this video.
01:58We are going to copy the normalize and mystyle.css files into the head
02:04section of our form here.
02:05I am going to paste those links and you could see that it already affects a
02:10little bit of the form.
02:10And I want to go back into codesnippets and grab this piece of code which will
02:14clear out some of the other inconsistencies between the form elements.
02:18So now we are going to go into the mystyle.css file and paste those, and you
02:22see that it cleared out all the input fields and made everything a little bit more standard.
02:26We also have added a little piece of code to clear any floats that we do in the
02:32document so they display properly in all browsers.
02:35Let's go back into codesnippets, we'll grab the basic code for styling the
02:39background which just has some vertical lines and sets up the content of the
02:44body down a little bit.
02:45So we'll copy this, go into the mystyle.css file and just paste it at the
02:50bottom so you could see the little pattern that we have right here under verticallines.png.
02:56So set to the background, so I'll just go back to codesnippets and grab the next
03:00section, this is some basic styling for the form.
03:03So this is the myform ID that we have applied to this form.
03:07I want to copy in to mystyle.css, and you could see that the form itself just
03:13has some basic styling plus a gradient and also a border radius so that the
03:20borders of this form have round edges.
03:23Right now you can't see them very well, but they are right here.
03:26We got the fields of borders around the different field sets, so we'll need to take those out.
03:31Let's go back into codesnippets and here we are going to take care of
03:36standardizing and cleaning up our field sets and what I am doing here is -- let
03:41me grab this code and copy it over to the mystyle.css file.
03:44As you can see now the field sets look a little better, they don't have that
03:51border that we had a second ago.
03:53And what we are doing here is first we are clearing out the border for the field set;
03:58now you could see the rounded edges a little bit better.
04:01And we're also doing a little bit of a hack to make sure that the fields set are
04:05displayed the same way in different browsers.
04:08So there is a discrepancy in the way that Internet Explorer displays the legends.
04:13So we are doing a little bit of a hack here to make sure that they display the
04:16same in all browsers.
04:18And to do that we are using the before pseudo-class and making sure that we tell
04:22the normal legends not to display and on every browser that understand the
04:27before pseudo-class we are telling title attribute of the fields set to become
04:32the new headline for each fields set.
04:34So if you look at the index file, you'll see that everyone of this field sets
04:41has an attribute called title and that's what we are actually using here instead
04:45of the legend, and although the legend is no longer there, because we are hiding
04:49it, it's as duplicate information in this title field.
04:53You could see that everywhere you see a field set and a legend there is a title
04:57field that matches the legend.
05:02Okay, back into the codesnippets.
05:04Unfortunately, Internet Explorer 7 does not understand the before pseudo tag so
05:10we have to do another hack to take care of that.
05:12So I am going to copy the code for fixing that hack.
05:14I am going to go into the index.html file and paste that into the head section.
05:19So this is some conditional code that tells the legend of the form to display
05:25normally in versions of Internet Explorer which would mean IE 7 and below.
05:29And so in here, we're telling IE 7 to display this normally and adding some
05:33styles for the normal legend.
05:36Okay, back into codesnippets, next thing we are going to do is grab a little bit
05:39of code to fix some of our form elements.
05:42We don't want these numbers to be displayed and we want to get rid of some of
05:46the default padding and margins that you see in list items.
05:49So I am going to copy this code right here and paste it into my stylesheets,
05:55paste it into my stylesheet, so that it get rids of a little bit of the spacing
05:59and it gets rid of the numbers.
06:01And this just adjusts the first level of our list.
06:05So you could see that some of these elements have sublists like the comments
06:10section and we go through this area called request type.
06:13We actually have a list that we don't want to display in a separate line, we
06:17want to display individually.
06:19We have also added a border at the top and the bottom of every list item and
06:23we've added a border at the top and a border at the bottom.
06:27You could see that they give that emboss look and feel.
06:30And because we do that we want to make sure that we clean those up so that the
06:35first element doesn't have a border at the top, otherwise you'd see this kind of
06:39weird border without a border on the very first list item of every field.
06:44And we need to do the same thing at the bottom because we don't want this other
06:48weird border to be at the end without a matching top one, so by doing that we
06:54clear up anywhere where we have the beginning and the end of a list from doing
06:59the borders that we normally do between lists.
07:02Okay back into codesnippets.
07:03This part of the code fixes some of the problems in having multiple lists.
07:09Whatever you have in ol li that targets the first list item inside an ordered
07:14list, when you have them in pairs like this it means that you are now targeting
07:18the list items inside an ordered list that are in a list item that are in an
07:24ordered list, which means essentially you're just targeting these elements right here.
07:28And we are also getting the input type check box to make sure that this element
07:32displays inline as well.
07:35So let me copy this and paste it into the mystyle.css, and you could see that
07:42now the request type is here and this appears normally.
07:48Go back into codesnippets and get some fixes for the labels, there are some
07:52problems with the labels right now, remember that we have some text that are
07:56actually coded as labels for each one of these input fields right here.
08:00But we have some texts that are not coded as labels like this thing
08:04called request type.
08:06So we need to make sure that we style those similarly.
08:09We want these labels to all look the same, including this one right here.
08:13So we had in the code for the part that says request type, we created a div
08:22with a class of grouphead, and what we are doing here in the codesnippets is
08:25styling the labels and this item called grouphead in the same exact way, so they look similar.
08:29So I am going to copy that back into mystyle.css, and I am going to paste that
08:35and you can see that now the request type is right here and all the other labels
08:42are styled in an identical manner.
08:45We also have a special label for this single line item.
08:48So this particular item right here, subscribe to our mailing list, is in a list
08:52item, but is not going to be on top of the input field, the input field there's
08:59a check box input field right here.
09:00So we have to style that a little bit differently and tell it to be inline just
09:04to make sure that on all browsers it's going to be right next to our check box.
09:08Same thing, with the second level labels, the second level labels would be the
09:13labels for this element and this element.
09:15We don't want the font weight to be bold.
09:17Remember we just told here all the groupheads and labels to be bold, so these
09:21would actually be bold normally.
09:23So we have to undo that, make sure that we clear for that.
09:28So in addition to that we are adding a cursor pointer style so that when people
09:32rollover on the labels, they can actually click on these form elements.
09:36Okay back to our codesnippets, we'll grab the next piece of code, and this is
09:41just a little bit of code that adjusts all of our input fields and also our text
09:46area to be the right width.
09:48Notice that what we are doing here is making sure that we are not adding pixel
09:52widths but we are using widths that are a percentage of the screen and that
09:56we'll make sure that when we resize the screen things adjust accordingly.
10:00So you could see some of that already in the form and you could see that in
10:03this input field and text area, we've also added some code that adjusts to the
10:08width of the screen.
10:09So let me copy all this code back into mystyle.css, and there is a lot of stuff
10:16going on in there, but it's all related to the input fields.
10:22So display them as block elements, give them a percentage width and then for the
10:26input fields in text area we add a border radius.
10:30Since we are using a required attribute for some of the elements, namely the
10:34name, the email and password fields, we can style that by targeting it with an
10:38attribute selector, so we can say I want only the input fields that are required
10:43to have a different border color which is what we are doing here.
10:49Then we do a little bit of styling on the select box, we are not really
10:52worrying about the option pop-ups because those are all inconsistently styled
10:57in different browsers, so we are just adding some basic styles to the way the select boxes look.
11:02Also notice that on some of these items I am specifying the width by first
11:06giving the element a pixel width, and then giving the element a width of that's
11:11a percentage of the screen.
11:12The reason I am doing this is because some older browsers are not going to
11:15understand a dynamic width like this, so we give those browsers a pixel width.
11:21Then we are also using the min-width attribute which has a cousin called a
11:24max-width attribute, to make sure that this particular select item never gets
11:29smaller than a 100 pixels.
11:30So I don't really want the select item to get smaller than a certain amount
11:36because I think it's annoying to see some of the select things be super, super tiny.
11:41In the same way, I use that in other places just to make sure certain fields do
11:45not grow smaller than a certain amount.
11:48So I am going to go back into codesnippets and grab the next section, this
11:55styles the button, and I am doing something similar there when I am specifying
11:59a width and a percentage width and then a minimum width to make sure that the
12:03button never gets too small, and I am going to copy that and paste it into the mystyle.css file.
12:08And you could see that now my buttons looks really nice.
12:11It does adjust in size, but it never gets smaller than what I consider to be
12:16a comfortable amount.
12:17To me there is a lot of sizes, just adjust the width to be whatever the width of
12:20the browser is, and when you have a super wide browser that can get really
12:25annoying because it can get really hard to read very long lines of text.
12:29I remember reading a lot of books where when I am reading a very long line and I
12:34finish reading that line and I tried to read the next line I actually end up
12:37reading the same line, because the line widths are so wide that your eye doesn't
12:42know how to move down properly to the next line.
12:43So I would like to limit the amount of resizing that I do.
12:49And you could do that by using those min-width and max-width attributes,
12:53which are kind of handy.
12:57Because we've used percentage styles as well as minimum and maximum width
13:01rules, we now have a form that will behave well in lot of mobile devices,
13:06especially tablets.
13:07To find out more about designing for multiple screens make sure you check out my
13:11title on Creating an Adaptive Web Site for Multiple Screens.
Collapse this transcript
Adjusting the viewport
00:00Your page just might already be optimized for desktop and tablets, but on
00:04handheld devices, you should make some additional improvements to the user experience.
00:09Let's take a look at how we can use the viewport tag to improve things.
00:12So if you're working with the assets from the previous video, you may already
00:16have a working folder on your desktop, we're going to continue from the code
00:20that we did in the last section.
00:22If this is the first time you're opening this movie, then open up the
00:26exercise files, then open up the Starting Points folder and find the starting
00:30point for this movie.
00:33Copy the Working Folder on to your desktop.
00:35I'm going to drag this while holding down on the Alt key to make a copy of it, and then
00:41open up that Working Folder in Espresso, it'll open it up as a project and find
00:46the codesnippets.txt and move it into the workspace, double-click on the
00:51index.html file to also move it into the workspace.
00:54And finally I'm going to drag this over here and I'm going to hold down
00:58Option and click on Preview to bring up the live preview.
01:01So this form automatically adjusts to the screen.
01:06But if we'll look at this form on a handheld device, and to do that I'm going to
01:10open up the iOS Simulator.
01:15And on the iOS Simulator I'm going to open up Safari and I'm going to drag the
01:19index.html file from the Project Files and drag that into the empty window in Mobile
01:25Safari, and it'll pull up this form.
01:27You can see that the form on a handheld device shows up super, super tiny.
01:32As soon as we click on a field you could see that it does zoom in, but it would
01:35be better if we could optimize the display so that it looks better on a handheld device.
01:40The problem is that most handheld devices try to interpret any page on the web
01:44as if it were a large web site.
01:46We can dramatically improve the way our form looks by using a single tag.
01:51So we're going to the snippets.txt file and we're going to locate the code for this video.
01:57We're going to copy this single tag right here and paste it into the head
02:02section of our HTML file, and I'm going to save this and go back into Mobile
02:07Safari and I'm going to hit the refresh key.
02:10Now you can see that when the page is refreshed, instead of the form looking
02:13really tiny on the screen it has now been adjusted for a mobile device.
02:17See that the form looks bigger on the display, the fonts are larger and overall
02:21it's easier to read, that's because the viewport tag redefines how the mobile
02:25browser displays the page.
02:27So if we take a look at this viewport tag you'll see that it's essentially a
02:30meta tag, and the meta tag usually has a name attribute and a content attribute.
02:35And within the content attribute, this is very important;
02:38we have name and value pairs.
02:40Notice that the content has quotes around it, but the name and value pairs
02:44don't. And we have a few different values that we can add here, but most
02:48important one is the width of the device.
02:51And by default most mobile devices assume that the page is going to be about a
02:551,000 pixels, like 960 to 1,000 or thereabouts, and so most pages are displayed
03:02super tiny on the screen.
03:04But by adjusting the width of the device we're telling this mobile browser to
03:09assume that this form is going to be the width of whatever the device currently
03:14is, and so in this case it zoomed into the form.
03:17Notice that if we go into a regular form, on the desktop it doesn't look any different;
03:22it looks exactly like it did before.
03:24So this is only going to effect mobile devices, which is quite good.
03:27So there's a few other options, you can specify the initial scale or how much the
03:33form will be zoomed in when the user sees it, so you can actually have it be
03:37zoomed in a little more if you wanted to.
03:39There is really no reason to do that, because the form looks really good at
03:42that size and you also adjust how much users can scale the form, which means
03:48that if they try to zoom into the form it's going to let them zoom only by this maximum-scale.
03:52Since we have set the initial scale to one and the maximum scale also to one,
03:56it means that the browser is not going to allow you to zoom into this form like
03:59you normally would.
04:00We have also set this users-scalable value to know which also means that this
04:05form is not scalable in any way.
04:07But we can play with those if you want to.
04:09This is a good starting point for the viewport tag.
04:11That sets it to the width of the device and generally tells it not to scale.
04:16You may turn some of these off, because you may want users to be able to
04:20scale even small forms.
04:23We've managed to significantly improve on the way the form looks by using a simple meta tag.
04:28This tag is not just for forms, you should be using the viewport meta tag to
04:31optimize the display of your content for mobile devices on all of your pages.
Collapse this transcript
Using media queries
00:00You've probably run into an online form that's been tough to fill out on your phone.
00:05Using media queries you can provide alternative style sheets that makes using
00:09your forms less of a pain for your clients on handheld devices, so let's take a look.
00:14Open up the Exercise Files folder and open up this the Starting Points folder
00:19and find the Starting Points folder for this video and I'm going to drag the
00:24Working Folder onto the desktop and hold down the Option key so that makes a copy of
00:29it, and then when I drag that folder into Espresso, it's going to open it up as a
00:36project and I am going to move the codesnippets.txt file into the workspace by
00:43dragging it from the desktop, and double -click on the index.html file and I'm
00:49going to open up the _css folder.
00:52You'll see that I have two different style sheets here the regular form.css
00:57and an additional style sheet for handheld devices.
01:00So I'm going to double-click on each of those to bring them into the workspace,
01:03you can see that the handheld.css file is empty right now.
01:06And the next thing we are going to do is click on the index.html file in the
01:10workspace, and move this over, hold down the Option key and click on the Preview
01:17icon to get a live preview of this form.
01:20So this is the form that we did on Chapter 3 and as you can see it's a
01:25form where we floated the elements to make sure they took advantage of the space
01:29in a desktop browser.
01:32Now if we pull this form up on a mobile device we'll use the iOS Simulator,
01:40I'm going to open up Mobile Safari here.
01:42I am going to click on these index files from the Project Files area and drag it
01:47into Mobile Safari, go ahead and zoom out, and I'm going to click on this area
01:53right here of the form, you could see that the form zooms in into this name section
01:57and we can start filling out the form, but these filter so big they
02:01haven't really been optimized that it's hard to fill out, plus when you're here
02:06you might think you are done and you start looking for those submit button and
02:10it's nowhere to be found, so then you have to kind of move this form around and
02:14find the beginning of this part.
02:15So it's really not the best experience, so we can use media queries to try to
02:20provide a better experience for a mobile device users. We probably want the lay
02:24this out a little bit differently so that it's easier to see the form whenever
02:28we first arrive onto the web site.
02:30So let's see how that's done.
02:32So I'm going to go to the coedsnippets.txt file, and I want to find the section
02:36for this video, and I want to copy this link and paste it back into my index.html file,
02:44this is going to go in the head section of our document, and here we're using
02:49what's called the media query; it's really just a link to another style sheet,
02:54just like you would do a link to a style sheet like the ones that's right up
02:56here, but we're adding an additional attribute to this link that only displays
03:01this style sheet if the device happens to be no more than 480 pixels wide.
03:06So I am going ahead and save this, and this will link on mobile devices to this
03:12alternative style sheet that we've created here, but we don't have any code on
03:16this alternative style sheets so I am going to go into my codesnippets and grab
03:19this next piece of code. What we are doing here is instead of setting a pixel
03:23width for each one of these devices, I am actually setting a percentage width
03:27for the device and resetting some of the elements, so let me just copy this and
03:32paste it into the form_handheld.css file, and save it, and if I come over here and
03:40I refresh my page you will see that this form looks the same as it did before so
03:45it's not taken effect in this particular form.
03:47And if I come over here, I refresh the page, let me zoom out you will see that
03:56this form is now displayed in a vertical orientation.
03:59So now when the users click right here and they hit this Next button, or they
04:04keep on filling out the fields, it's a little bit easier for them to see what it
04:08is they are supposed to be doing.
04:10So you could click on some of these elements and keep on going and now your
04:15Submit button or in this case the Oh really?
04:17button is down here in a sequential manner.
04:19So we've created the form that adjust to different devices, on a desktop it takes
04:25advantage of the extra width of the screen and on a handheld device it presents
04:29the form in a vertical fashion and we've done that with this media query.
04:33So let's take a look at what we are telling the media query to do, so back into
04:38our index.html file.
04:40And you see that it looks exactly like a normal link to a style sheet with an
04:44additional media attribute.
04:46So in this media attribute we can specify that this style sheet would take
04:49affect only screen type devices, you can also specify print style sheets and also
04:55on devices where the screen is no bigger than a certain pixel amount.
04:59There's a number of different pixel amounts that you can check for so if you
05:03wanted to do style sheet for perhaps tablet devices you might change this number
05:06to be a different number.
05:08So in addition to creating a link to a separate style sheet, you can have
05:12conditional media queries within your existing CSS.
05:15So what I am going to do is I am going to delete this section right here, so it
05:19no longer calls a separate style sheet, and I'm going to save that and go back
05:23into my codesnippets, and here is a different version of how you can use media
05:28queries within existing CSS.
05:31We took the code that was on the separate style sheet right here and we've
05:36applied a media query that you can put on your CSS.
05:40So I am going to copy this piece of code and we can actually insert that into
05:44a regular form.css.
05:47So I am going to go all the way to the bottom, paste that piece of code.
05:51Here is where you have to be really careful, notice that we've done is created
05:56styles like this style with a beginning curly bracket and ending curly bracket
06:01inside a set of curly brackets here and here, and we just created @media rule
06:08looks pretty much the same as the media query on the link element before, and the
06:15rest of it is pretty much the same, but the main difference is that you are
06:18going to put your code within these, make sure you don't get confused about the
06:22quantity of these curly brackets or this is not going to work.
06:25So if we save this you will see -- you should see that this doesn't take effect in the
06:29normal browser, but in here we should still see the form as a vertical element
06:37when you refresh the page, so it works exactly the same way.
06:40It's not doing anything with this separate style sheet, but you are doing
06:44everything within the current style sheet that you are doing, and all you need
06:47to do is make a new version of whichever elements you want to override in the original CSS.
06:53If you want to find out more about media queries, make sure you check my course
06:58on iOS Web Applications with HTML5 and CSS3, I have a video on targeting devices
07:05and orientations with media queries that goes more in depth into the different
07:09media queries you would need for different types of devices.
Collapse this transcript
Resizing elements
00:00Anything that makes life easier for your visitors is great, and one thing we can
00:04do is make sure that things are bigger on handheld devices.
00:08So let's see how we might approach that.
00:10Open up the Exercise Files folder, and find the Starting Points folder and then
00:15find the starting point for this video.
00:17I want to copy the Working Folder onto my desktop, and then I'm going to drag
00:24the Working Folder into Espresso, it'll open it up as a project.
00:28Then I'm going to drag the codesnippets.txt file into the workspace and I'm
00:34going to move this over, and click on the index.html file and Option + Click on
00:40Preview to take a look at this form.
00:42I'm going to also double-click on this index.html file to bring it into
00:49the workspace.
00:50So this is the form that we worked on before and we have a created a media query
00:54to make sure this form displays differently on handheld devices.
00:57Let me go ahead and pull up the iOS Simulator.
01:04And I'm going to run Mobile Safari, and I'm going to drag the index.html file
01:09from the Project Files, and I am going to resize this form, you could see that on
01:15a desktop this form has a two column layout, and on a handheld device it has a
01:20single column layout and that's a lot better for our users, but it would be nice if
01:24this text was bigger and more visible on a handheld device.
01:27If we need to take a look at how we achieved these different layouts on
01:31different devices you can take a look at the movie on using media queries and
01:35using the viewport tag.
01:37So the easiest way to make the fonts bigger is to use a property of WebKit
01:41called the WebKit size adjust attribute, just go into the codesnippets file and
01:47find the section for this video.
01:50And I'm going to copy this line of code right here, and I'm going to open up the
01:55CSS file for this project, we've got the form code on a separate CSS file, so
01:59I'll double-click on that.
02:01If you look way down at the bottom of this file, you'll see that we already have
02:05a media query that targets handheld devices and in here we're essentially just
02:10telling everything to display as a single column.
02:14To make this apply into our form elements, we can type in the form element with
02:19the universal selector, and paste this attribute into the universal form
02:25selector, this will select every form element underneath any one of our forms
02:29and what we could do is ask the text inside those elements to be 200%.
02:34You can apply this to any specific element so if you wanted to bring some of
02:38these other fonts up that would be great, but in this case I really just want
02:41the form to be a lot bigger.
02:43So I just want all my form elements to adjust their text size by 200%.
02:47Once we have added this rule we can go into our form and refresh our form, and
02:52our form elements are now all a lot bigger.
02:55That's a really quick way of adjusting the fonts for everything on a specific
03:01section and like I said you can add that anywhere.
03:03In this particular case it just makes the form a lot more visible on mobile devices.
03:08Now certain mobile devices do not support the WebKit-text-size-adjust attribute,
03:14so in this case you would have to do things manually, so let me go ahead and
03:17delete this attribute here, and I'm going to go back into my codesnippets and
03:23grab this next version of the code, and all we're doing here is adjusting the
03:28label size, making it a lot bigger than it used to be, I think it used to be 1em
03:32and we have adjusted to 2em, and also making the text inside the form element
03:37bigger, so I'm going to copy this, go back into my form CSS.
03:41I deleted the not always supported WebKit-text-size-adjust attribute, I'm going
03:47to paste this underneath and save it and refresh our form.
03:53And you can see that it's not exactly the same but it's another way of
03:56making the text bigger, you can manually just put in new values for some of the elements.
04:02Either way this makes the form a lot more visible to our users and a lot easier
04:07to immediately recognize that we need to do something with this page and what we
04:11want you to do here is fill out this form.
04:13So you should always try to make things as easy and pleasant as possible for your users.
04:18I'm sure you've had a hard time with some forms, I know I have that are not
04:22optimized for handhelds, and it's just a pain to run it to those, so make sure
04:26the same thing doesn't happen to your users.
Collapse this transcript
6. Advanced Design Patterns
Styling for progressions
00:00Some forms can get so complicated that you'll need to find ways of the
00:03dividing the information into different sections.
00:06In this chapter, I am going to show you how to style a form, so that the
00:09different field sets appear as different tabs.
00:13This video is part of a series where I'll show you how to use jQuery to handle
00:16navigation between field sets as well as how to validate the form and style the
00:22validation elements.
00:25Let's get started by defining our basic style sheet for our form.
00:29So I am going to go to the exercise files and open up the Starting Points
00:33folder, find the starting point for this video.
00:37And I am going to copy the Working Folder onto the desktop, holding down the
00:40Option key and dragging it, and then I want to take this Working Folder and drag
00:46it onto Espresso, so it will open it up as a project.
00:51And then I am going to take the codesnippets.txt file and move it into the
00:54workspace, and I'm also going to double-click on the index.html file and the
01:01mystyle.css, so it also goes into the workspace.
01:05So let's take a look at our HTML document and I'm going to hit the Preview
01:09button holding down the Option key so that we can get a live preview.
01:13So we have an HTML form with three different field sets;
01:17one for login information, another one for other information, and a section for comments.
01:23Two of the fieldsets have an additional class called hidden right here, that will
01:28hide these fieldsets on the final form.
01:31Let me show you what this page is going to look like after we get done with this video.
01:37Our page will look like this.
01:38So we could do that.
01:39We can get started by going into the codesnippets.txt file and scrolling up to
01:44the information for our current video.
01:46So we'll copy the links to our normalize.css document and then mystyle.css file
01:52and we'll put that in the index document, in the head section.
01:57So you could see that some of these styles have already taken effect, we'll go
02:03back into codesnippets and grab some additional code for clearing form elements
02:09a bit further and to clear any items that were floating.
02:12So I am going now to the mystyle.css document and I'm going to paste that and
02:17you could see that we are clearing the appearance of most of the input fields to
02:21make them all start with similar look.
02:24Back into codesnippets, I am going to get some basic styling for the body
02:27section as well as some basic styling for the form, so I am going to copy that
02:33and go back into my stylesheet.
02:35And here I'm adding some background to the body section, this looks like a lot
02:40of code, but it's really just some code for a background texture and a gradient
02:46beneath that background texture with different browser prefixes so that it
02:51displays in most browsers.
02:52Now for the form element we have added a font and some other basic styling plus
02:57a border-radius, so that the edges of this form are rounded, as you can see
03:02right here, and we have a different texture that we have applied to the form
03:07plus some roundness to the edges and a slight drop shadow.
03:14Now we need to fix the fieldset outline and style the legends as well.
03:17So we are going to go back into codesnippets, scroll down and I am going to
03:24grab this piece of code right here, go back into our stylesheet and just paste
03:29that at the bottom.
03:31What this is going to do is just style the fieldsets and because the fieldsets
03:35display differently in different versions of Internet Explorer and other
03:40browsers, we need to do a little trick that we have done before in other videos.
03:44And because the legends will display differently in different browsers,
03:47especially versions of Internet Explorer, we are going to hide the way the
03:51legends are displayed and then display the legends by grabbing the title from
03:56the fieldset and styling then that by using a before pseudo tag.
04:02This will work for most versions of Internet Explorer except for versions of
04:06Internet Explorer before version 8.
04:07So we are going to have to go back into codesnippets and grab another piece of
04:11code that will fix this problem in Internet Explorer 7.
04:15So we'll grab this little piece of code.
04:16This is a conditional stylesheet that applies only if the version of Internet
04:21Explorer is less than Internet Explorer 8.
04:23So we'll copy that, go back into our index file and paste that in our head
04:28section, and then we'll go back into codesnippets to grab some code to handle
04:36the list items. By default list items display with numbers right next to them
04:41and they're indented quite a bit, so we're going to grab some code to take care of that.
04:48Go back into mystyle.css.
04:50I'm going to paste that and you can see that here I took care of some of the
04:54margins and the numbers that appear normally on ordered lists, and I also took
05:00care of adding a little bit of a border before and after each one of the list
05:04items giving the form an embossed look between each one of the fields.
05:09And then on the first element and the last element of each list, I deleted the
05:15borders so that we don't see these weird kind of borders that will appear at the
05:19beginning and at the end of the form.
05:22So if we don't do this, you'll see an extra border appear at the beginning and
05:26end of each list item.
05:30All right our form is looking pretty good.
05:32This field right here needs to be fixed a little bit further.
05:35This is a second level ordered list, so we'll go back into codesnippets and
05:40we'll grab the code to fix those elements asking them to be displayed as inline elements.
05:47So now those appear as inline elements right next to each other, how they should.
05:52So back into codesnippets we'll grab a little bit of code to fix our labels.
05:57So back into mystyle.css, and this will style all our labels so that they look
06:03really nice now, and notice that I have some basic code for the labels, and then
06:09I have a special version of the code for a singleline label, which is a special
06:13class that I use for styling this particular label.
06:16I don't want this label to be bolded like the other one, and for the labels
06:21that are part of a group, so I have this special request type text as a
06:27grouphead class because technically it's not a label, although it's a label
06:31for these other elements.
06:32Each one of these elements are already a label.
06:35So I can't style those.
06:37I have to style a headline which I've done with this group class right here.
06:41You can see it in the index.html.
06:42If I scroll down to that section on the Comments, I have this div class that's
06:49acting as our headline, have a class of grouphead so that I can style it like
06:53the other labels as well.
06:55Back into our codesnippets, now we're going to grab some code to handle the
06:59text area and the input field.
07:01So these inputs fields right now are just a little bit too short and this text
07:06area also needs to be a lot bigger and have a little bit of a better style.
07:10So we'll grab this, back into mystyle.css, I'm going to paste that, and you can
07:16see that our fields are now a good width and so is our text area, and they have
07:22essentially just a slight gradient so that you can see they are just a bunch of
07:27browser prefixes, and so they have a nice little slight gradient for the inside
07:32and some other settings here to just give it a little bit of breathing room and
07:37width that looks more appropriate to the form.
07:41So back into the codesnippets, now we are going to grab a section for second
07:46level inputs. Notice what's happening down here, our second level inputs are
07:50displaying kind of right on top of each other, because we've done that to all
07:55these other input fields, we've all told them to display right on top of each
07:59other so that the labels appear on top.
08:01So we need to fix that with this section right here, and we are also going to --
08:06let's go back to mystyle.css.
08:09So that kind of fixes most of it.
08:11I am going to refresh the screen because sometimes the live preview in Espresso
08:15doesn't refresh appropriately.
08:17So you can see now by adding those pieces of code we have fixed our second level
08:22input fields, asked them to display as inline, and we've also made sure that on
08:28all browsers that the check boxes are also displayed as inline elements that
08:31way, this will always be right next to it.
08:34Then we have added a little bit of a taller height to our text area to make sure
08:39we have plenty of room to write in here.
08:42So back into the codesnippets, so let's now style the select field which looks
08:47a little plain, looking white like that, so we're going to grab this piece of code.
08:51And this is essentially just some width and height styles plus a gradient
08:55that looks really nice.
08:56Let's go ahead and apply that so we can see it.
08:58Let's see the gradient, it's a slight gradient that just gives it a different
09:02color, and we have a bunch of different browser prefixes here as well as some
09:08roundness to the edges.
09:09So back into codesnippets, just about the only thing that's left is to style the
09:12button, so it gets a lot of code, but again most of it is right here in the
09:16background gradient that we are applying there.
09:17So I am going to copy that, go back into the mystyle.css area, and I'm going
09:22to paste that and you can see that the send button gets some standard width and height.
09:28My entire form is using variable width, so you could see that if I resize these
09:32forms, the forms will resize up to a certain point.
09:38Finally, I am going to go back into my codesnippets to get the hover version
09:43of this arrow, and the hover version of the arrow is just going to be a
09:50different color background.
09:52So back into the CSS file, and this has the pseudo-class hover here, so all we
09:58do here is just change the color of the gradient so that when we roll over this
10:01button, we get a different color gradient and these are all just browser prefixes.
10:08We've done a lot of styling that you've probably seen in some of the other
10:11videos in this series, and this already looks like a great form, but in future
10:16videos I am going to show you how to add navigation and interactivity.
Collapse this transcript
Visualizing navigation
00:00In this movie I am going to show you how to style a form so that you can display
00:03different fieldsets into different tabs.
00:06When we get started, we'll have a form that looks like this and we are going to
00:10add navigation tabs at the top of the screen, and buttons that allow you to
00:15navigate between fieldsets.
00:17In future movies, I'll show you how to use jQuery to let visitors navigate
00:21between these buttons and tabs, plus add styles for validation.
00:30Let's open up our exercise files and open the Starting Points folder, find a
00:36folder for this video and make a copy of this Working Folder on our desktop.
00:40I'm going to hold down the Option key while I click and drag.
00:44And then I am going to drag that folder into Espresso, and I'm going to move the
00:49codesnippets.txt file into the workspace, double-click on the index.html file as
00:55well as the mystyle.css.
00:57Then I am going to move this over to this side, make sure I am in the index.html
01:02document and Option + Click on the Preview button to pull up a live preview.
01:07So you can see our form looks pretty good right now, but we need to add some
01:10navigational elements.
01:11We're going to go into codesnippets.txt and scroll down into our section for this video.
01:19And I am going to copy navigation buttons that will go into each
01:24different fieldset.
01:25So I'm going to copy the code for all the buttons, then I am going to go to
01:29the index.html file.
01:31And at the bottom of our first fieldset underneath the ordered list, I am going
01:36to paste these, and then select the last three items so that we just have a next
01:42button at the bottom of this fieldset.
01:45Then I am going to move over to the end of the second fieldset, and after the
01:49ordered list, I am going to paste those elements and just keep the previous and
01:54next version of the button.
01:58And I'm going to go to the last fieldset, and at the end after the ordered
02:03list, before the button, I'm going to paste the last version of the link to the button.
02:06So you could see the buttons are right here after the first fieldset and right
02:11here after the second fieldset, and then the previous button is right there right
02:16at the end, before this Send button.
02:19So now we need to style these to make them match this Send button.
02:24So we're going to go back into codesnippets, and we are going to modify
02:27two stylesheets here.
02:28I'm going to grab these, go into mystyle.css and find the piece of code that
02:34says just myform button.
02:37I'm going to select that, and I'm going to paste this, delete the second one
02:42because what I want to do is add the myform .buttonnav and give it the same
02:48style as our button navigation for this previous element has.
02:53So then we are going modify the hover version of the button to add our second
03:00style, so that they more or less match the submit button which is right here.
03:05They are a little out of place, but we are going to fix that with some
03:07additional styles, so we're just setting up the basic shape and the background
03:11of each one of those elements.
03:13I'm going to go back into codesnippets to grab the next version, and in here we're
03:18going to add a piece of code that cleans up a little bit of the craziness
03:23that's happening here with these elements.
03:24So I am going to grab that, go into mystyle.css and at the end right here I am
03:30going to paste that, and you can see that now they are displayed a little more
03:33evenly, they have just a little bit -- we added a height and allowed these
03:37elements to be displayed as inline block elements.
03:40Inline block elements are like block elements, but can be resized.
03:44Unfortunately some earlier versions of Explorer did not support the inline block,
03:50so we've added a little bit of a hack here to fix some display problems in
03:53Internet Explorer 7.
03:56We still need to fix a little more code.
03:58You could see the previous button is happening before the send button.
04:02So I am going to style the previous button here as well as the hover version of
04:08the previous button.
04:09I am going to copy that, go back into mystyle.css, and that really looks like a
04:16lot of code, but it's a bunch of browser prefixes, and I am going to paste that
04:20code, I'm going to refresh my preview here in Espresso because sometimes it
04:24doesn't update when you do some of the changes.
04:26You could see that now the buttons are where they belong.
04:29So this looks like a lot of code, but it's really mostly a bunch of browser
04:33prefixes for the different gradients.
04:38And also a little bit of floating that we are doing here, and other than the
04:42floating and the margin that we do here to make sure that they are not at
04:46the edge of the screen.
04:48So if we don't have this margin then some of these buttons will go through the
04:51edge improperly of the screen, right here.
04:56And we also have a hover version of the previous button and that version is what
05:01happens when we roll over these buttons right here.
05:04You'll also notice that when we place the background in the normal button,
05:09we're asking this background to be aligned to the right top of the document.
05:15This background is a series of arrows that has the left and right version of the
05:20arrows in the same file.
05:21They are partially transparent so I can't show you the document or it will
05:25look like a bunch of white, but there's both versions of the arrows going to
05:30the right and to the left, you can see the other one down here.
05:33And what I am doing to make sure that they align properly is on these normal
05:36versions of the arrow I am aligning the graphic to the right top of the button,
05:42and down here on the previous versions of the buttons, I am aligning that to the left bottom.
05:50So because these use the top version of the image, it's showing you the
05:55image to the right, and because this used the bottom version of the image, it's
05:59showing you what would be underneath which would be the same graphic with the
06:03graphics going to the other side.
06:05Like I said, we do have that graphic here, but it really doesn't show you the
06:10background like it should.
06:12Now let's go ahead and hide the different fieldsets, so that these other
06:19fieldsets that are in this form are not showing up, we only -- we'll have the
06:23first fieldset, we'll add a bit of navigation at the top.
06:26So I am going to go back into codesnippets and just grab this piece of code.
06:30We already have in our HTML a class for each of these other two fieldsets that
06:35we don't want to show up that's called hidden.
06:37So if you look at the index.html, right now this fieldset with the comments has
06:42a class of hidden, and so does this fieldset with the other section, which is
06:48this part right here.
06:49So I am going to go into mystyle.css, all the way to the bottom and just paste
06:53that and that will hide both of the other fieldsets.
06:56Then go back into my codesnippets and I'm going to grab some code for basic
07:01navigation and in this navigation, this navigation happens to be a list of
07:06items. I am going to go into my index file and paste that before the form, after the body.
07:11So right now you see it looks like a normal list, so we are going to need to add
07:15some styles to make that look like navigation and to do that we are going to
07:19grab basic code to style the unordered list, so back in here, back to the
07:26bottom, paste it, so that just indents it and makes sure that it's aligned like
07:30the rest of the form is centered on the page.
07:34Back into codesnippets, now I am going to grab some code for the list items
07:38that's going to get rid of these bullets right here and also just do some
07:42additional styling to make them look like tabs.
07:44So back into mystyle.css and every list item is going to look like this orange
07:51versions of the tab.
07:52I have added a little bit of a drop shadow that is inset that's not going to
07:55show up in all browsers.
07:57Plus I have added different border- radiuses, so that they are rounded at the top
08:01and they look like tabs.
08:02And some other generic sort of styling code, you see that I am styling these as
08:06inline-block, that's so that the lists will remain centered.
08:11It's really hard to center block level elements.
08:13So if you leave them as inline-block, then it's easier to center them.
08:16We do have a fix down here for Internet Explorer 7 that does not understand
08:21inline-block so this piece of code right here is a little hack.
08:24Plus we changed the cursor to a pointer, when somebody rolls over
08:28these different tabs.
08:29Now this is the normal version of the tabs.
08:31So we need a highlighted version of the tab.
08:33And if you look at our HTML, we have defined the tab that is active to have
08:39an id of activetab.
08:40When the form first loads, it's going to be this Step 1 piece right here so I am
08:44going to go into the codesnippets and grab the code to style the activetab.
08:48So I am going to copy that, go back into the mystyle.css, paste that, and you
08:56can see that now my first tab is styled a little bit different than the other
08:59ones because this one has an id of activetab.
09:02Finally, I want to add a little bit of code to make this thing behave a
09:06little better in mobile browsers.
09:07I am going to save this and pull up the iOS Simulator, pull up Mobile Safari,
09:15and then I am going to drag this index.html file here.
09:18It looks really good, but it shows up really small on-screen.
09:22So I really need to add a little bit of code to make this behave better on a
09:25mobile device so that it looks a lot bigger.
09:27I'm going to go back into codesnippets, and I'm going to add a viewport meta tag
09:32to make sure that it thinks of this form as being the width of this device.
09:37So I am going to go back into index and add this in my head section, save it,
09:43and I am going to refresh this page, and you will see that the form already
09:46looks a lot bigger on mobile devices.
09:48It won't have an effect on a desktop device, but it looks a lot nicer.
09:52There is a little bit of additional spacing that I have here.
09:55So I want to clean that up only on mobile devices.
09:59So I'm going to change the navigation actually has a little bit of code to
10:03push it down the screen a little on desktop devices, just so it has more breathing room.
10:08So what I am going to do is add a media query that makes that margin be a lot
10:12smaller on mobile devices, not the delete it because then it would be flushed
10:16right here to the top of this browser page.
10:18So I'm going to go back into the mystyle.css, and then at the end paste
10:22that piece of code.
10:23After I pasted this media query to make sure that the navigation margin is
10:27smaller, and refreshed this page, I am noticing that it's not moving up.
10:32The reason for that is earlier I had put in a little bit of margin on the body
10:36tag to try to make sure that it moved down so although the actual form is moving
10:42up, this margin at the top of the body is taking over the space.
10:46So if I remove this margin from the body section, I'll save that and refresh,
10:50we'll see that the form does move up.
10:53Now that we have styled the form and arranged the fieldsets so that they appear
10:57in different tabs we need to build interactivity.
11:00We'll tackle that in the next movie.
Collapse this transcript
Adding jQuery navigation
00:00In this movie I'm going to show you how you build some interactivity into a form
00:04with three fieldsets.
00:05Each fieldset is in a different tab, when we get started we'll have a form
00:09that looks like this.
00:11Right now the tabs don't show or hide any of the other information and the
00:15buttons don't take you to the next fieldset.
00:19When we're done you'll be able to use the tabs at the top of the screen as well
00:24as the navigation buttons at the bottom of each fieldset.
00:28In future movies I'll show you how to add validation elements and how to style them.
00:32So let's open up our exercise files, open up our Starting Points and find the
00:38starting point for this video.
00:40I'm going to drag a copy of the Working Folder on to our desktop, holding down the
00:46Option key to make a copy, and I'm going to drag a copy of the Working Folder on
00:50to Espresso to open it up as a project.
00:53I'm also going to drag the codesnippets.txt file into the workspace and I'm
00:58going drag the index.html document also into the workspace.
01:03We'll go to the codesnippets and drag down to our section for this video.
01:08We're going to need to add a link to our scripts, so I'm going to copy these two
01:14links right here to script files.
01:16I'm going to go to the index file and in the head section of the document paste
01:21the links to our two scripts that we're going to need.
01:24We're going to use a library called jQuery that you'll need to download from the
01:28jquery.com web site, and we want to make sure that we choose the production
01:32version that's already been minimized so that it's as small as possible and hit
01:36the download jQuery link.
01:39You may have to save this as a separate document.
01:42So I'm going to put it on my desktop and make sure that we choose Page Source
01:48and we're going to add .js extension, save it to the desktop, go back into our
01:55file and I'm going to need to copy this file into our Project Files.
01:59To copy things into a project file folder in Espresso you can simply just drag
02:04into this Project Files section.
02:06You can also drag it into the folder on your desktop, either way will work.
02:10I'll put it right here, it adds it right there, and you could see this if I open
02:14up this Working Folder it's already added right there.
02:16Since I have a link to an additional myscript.js file, I'm going to need to add a new file.
02:23So I'm going to click right here and select New File, and I want to call it myscript.js.
02:32And now we have the links to these two files and we have a copy of each of these
02:35two files in our index page.
02:38So jQuery is a JavaScript library that allows you to use versions of
02:42JavaScript that have been optimized for different browsers and take care of some
02:47discrepancies between browsers in the way JavaScript is implemented.
02:51First thing we have to do when we work with jQuery is define a function called
02:55the document ready function that executes after the page has been loaded.
03:00So I'm going to do that by going to the codesnippets, and I'm going to grab
03:04this first piece of code right here and this has the code for the document ready function.
03:08Functions that we want to execute after our page loads will be inserted inside
03:13this function, so I'm going to copy that and go into myscript.js file and paste
03:19our document ready function.
03:21So I want to go back into codesnippets and the first thing I'm going to do is
03:25make sure that we execute some code, so that when somebody clicks on the
03:29navigation list items, we make all the tabs inactive which will hide them, and
03:35then we will make the tab that we clicked on active.
03:38We do this by using a series of selectors and then adding methods or functions
03:43onto the selectors.
03:44So jQuery is really cool in that, it allows you to specify selectors much like
03:49you would do with CSS.
03:50So here we're asking jQuery to find any item with the nav class that is also a
03:57list item, and then we're asking to see if that navigation link has an attribute
04:03and setting that idea of that attribute to nothing.
04:06When we set the idea of the attribute to nothing, if any of the IDs were active
04:11tabs before, then it will make them nothing, so this essentially makes all tabs
04:15inactive and it clears in it.
04:17Let me go ahead and move this window over here, I'm going to click on my index
04:21file, open up the Preview.
04:23If it says that the document has been renamed just because I named it before, so
04:28I'm going to hit Save, I'm going to go back to codesnippets.
04:31I want to grab this piece of code here.
04:34Now although Espresso has an excellent live view, one of the things that it will
04:39not update automatically is any scripts that you type in.
04:43Whenever you're typing scripts in this movie make sure you save this script
04:46before you try to preview the document, and you'll need to come over here and
04:49actually refresh the page unlike most of the time when you're just updating CSS or HTML files.
04:55So I'm going to save this and if I come over here, just remember that most
04:59of the time you'll have to remember to refresh your HTML to make sure that
05:04this operates properly.
05:05So this particular piece of jQuery takes care of making sure that these tabs
05:10switch and activate whichever page we're going to be on depending on which item we click.
05:14So they do that by first looking for using the selector, so it's going to look
05:19for navigations that have list items in them.
05:22And if we look at the HTML, when we define the navigation we define it with a
05:27class of navigation, and each tab is defined as a different list item.
05:32So it's going to look for all these and it's going to clear out any IDs
05:36that currently exist.
05:38Right now there is only one id that exists which is this activetab.
05:42So the first piece of that code is going to get rid of any IDs that currently exist.
05:47So if I take this one out, I'll save it, refresh over here.
05:51When I click, you will see that it will essentially clear out any tabs that
05:56are active right now.
05:57And then the second piece of code changes the attribute of the item that we clicked on.
06:02Since we're checking anytime somebody clicks on a list item, it knows with this
06:06variable that this is the item that we clicked on and we can set the attribute
06:10of id to be activetab, so what that does is make sure that the item gets
06:16highlighted once you refresh it.
06:18Then when we click on these different elements it will highlight them.
06:21It doesn't switch any of these fieldsets around but at least it's visually
06:25showing you the different tabs.
06:27So we'll need to take care of that next.
06:28So I'm going to go back into codesnippets and grab the next piece of code.
06:31And that piece of code handles --
06:33when somebody clicks on the navigation links it's going to hide all the tabs,
06:38make the one that we want active, and then in addition that it's going to hide
06:43all of the fieldsets in this part, and then we're going to show the one that we want down here.
06:47So let me just copy this part, and go into myscript.js and replace this
06:53section of the code with a new version of the code, and I'll save it, come
06:57over here, refresh.
06:59Now when I clicked on these tabs it's going to just hide all of them.
07:02So whenever I click one of them, it's going to switch the tab to be active and
07:07have the proper style, and it's going to hide all these other things.
07:12That's good, move up to the next piece of code.
07:16Remember that to hide the Step 2 and Step 3 parts of our form, we had styled them
07:22with the class hidden and what this is doing is taking all the fieldsets and
07:27giving them the class of hidden, so it hides all of them.
07:31So in the next piece of code we're going to add a little more code right here,
07:37so we'll replace this entire piece of code here.
07:40So we've added just a couple of other lines of code.
07:42What this is doing is, we are looking to see what the title of the item that
07:48we clicked on is and we're going to store that object into a variable called whichitem.
07:52So what that will do is if you take a look at the index.html you'll see that
07:57each one of these list items has a title and that title happens to match the
08:02title of our legends.
08:05This one says Login Info, this one says Other Info, if you go down here into
08:09this fieldset you'll see that there is a title called Other Info, and if we
08:13go down here to Comments you'll see that there is another title here called Comment.
08:16So on purpose I make sure that those things matched.
08:19And I'm going to go back into my JavaScript and show you that it's going to find
08:23out which one of those items we clicked on, and then it's going to look for a
08:27fieldset with the title of what we just checked for, the matching title.
08:33And then it's going to take that fieldset and change the class of that
08:37fieldset to nothing.
08:38So that means that it will not be hidden, because the ones with hidden input
08:42fields are the ones that are hiding.
08:44So I'm going to save that, come over here, refresh, and now when I click you'll
08:49see that it allows you to navigate to the different fieldsets.
08:53Back into our codesnippets.txt, now we need to code the previous and next buttons.
08:59So we'll grab a little piece of code for the previous button, we'll do that one
09:02first, the next button is pretty much the same piece of code.
09:06So, back into myscript.js, be very careful about this;
09:09we need to make sure that this is all still within the document ready function.
09:13So here is the function for handling clicking on the navigation links, we don't
09:18want to get rid of this one right here.
09:19I'm going to add a few extra spaces down there and add the next piece of code right here.
09:25If you remember what we did with each one of these list items, is create an id of
09:30activetab to highlight which one of these elements was the current element.
09:36The next and previous buttons can't understand which fieldset is active,
09:41but by keeping track of which of these tabs is active, we can know which number
09:46fieldset is also active.
09:47So that's what this part of the code does.
09:50We look at the entire document for anything with an id of activetab.
09:55That will be one of these tabs right here, whichever one happens to be active.
09:59In the next line we find out the index of that item, so we want to find out
10:03which number tab is active.
10:06So we could do that by taking a look at which index of the list item is this
10:12item that we have selected up here.
10:14When we switch to another fieldset, we want to update the tabs by making them all
10:19inactive and then updating the tab that belongs to fieldset that we want.
10:24So this piece of code right now, if we save it and we refresh, when we go to
10:29another tab -- I'm going to hit the previous button now to go to the
10:33previous tab -- it's really only going to update the tabs right now, because all
10:37we have done is found out which one of the tabs was active, which and when we
10:42first reloaded this it was tab 2, and we store that into this variable.
10:46And then we just clear all the tabs like we did before.
10:49And then we have a selector here that allows you to check which nav item is
10:54equal to the current one that we have clicked on, minus 1, so it's going to
11:00find the nav item before the current nav item, and it's going to change the id
11:05of that nav item to activetab, activating the tab so that it shows up as the current tab.
11:10We haven't done anything with the fieldsets yet, we're going to do that next.
11:14So back into codesnippets, this is the same code as before.
11:18We're just adding a couple of lines to care of the fieldset.
11:20So let me grab that code, I'm going to copy here, go back into myscript.js.
11:25Again, make sure you're not deleting this last piece of code, because it goes
11:29with the document ready function.
11:33And we're going to actually select all of this and replace that code that
11:37has the next two lines.
11:39This is pretty much like the code that we did before to hide all the fieldsets.
11:42It just sets the attribute of all the fieldsets to hidden, and then we do
11:47something like what we did with the list items, we're finding out which fieldset
11:51is the current fieldset minus 1, which will be the previous fieldset, and then
11:56we're adding a class of nothing.
11:57When we add the class of nothing to the fieldsets, the nav fieldset would
12:01actually show up, because over here we've set all the fieldset to be of class hidden.
12:06When they are not hidden, they are showing.
12:07So I'm going to save that, come over here and refresh, and I'm going to click
12:12on Step 2 and I'm going to click on the previous button and it's going to
12:16navigate the tabs properly and it's also going to show this fieldset that is
12:21the first fieldset.
12:22So that's pretty much all you have to do for the previous button.
12:26The next button is going to be pretty much identical, but obviously we're not
12:29going to go the previous item using minus 1, we're going to the next item using plus 1.
12:35So back into the codesnippets, and we'll grab the next piece of code into our
12:40scripts.js, and paste our code for the next button.
12:45This will be pretty identical to the previous button.
12:48The only difference is going to be that here we're going to add 1 to the
12:52whichOne item, so that it increments to the next element.
12:55So we'll save that, come over here, refresh, we can hit this next button now and
13:01it will clear all the tabs, activate the current tab and then set the fieldset
13:06to the proper fieldset.
13:07We can hit the next button and go to the third element and we can hit the
13:11previous button, previous button, we can hit the tabs to navigate and we have
13:15built an animation to navigate between our fieldset in different ways.
Collapse this transcript
Designing validation feedback
00:00In this video I'm going to show you how to style validation feedback and use
00:05jQuery to activate it.
00:07Make sure you watch the rest of the videos in this series to see how the form
00:10was styled and how I dealt with programming the navigation elements.
00:14So open up the exercise files and open up the Starting Points folder, and find
00:20the folder for this video.
00:22Take the Working Folder and make a copy of it on to your desktop, then I'm
00:25going to drag that folder onto Espresso, which will open it up as a project.
00:30Then I am going to take the codesnippets.txt document, drag it into our
00:34workspace, and I'm going to double-click on the index.html file, the myscript.js,
00:41and the mystyle.css files to bring them into the workspace.
00:44I'm going to move this over to this side, and then I'm going to click on the
00:48index page and Option + Click on the Preview icon to bring up the live preview.
00:53So the first thing I need to do is to add a thank you page to this document,
00:58right now the form doesn't submit anywhere, so we need to go into
01:01codesnippets.txt, find the section for this movie and copy this replacement
01:07for the form field.
01:09So I am going to go back into index.html and I am going replace this form field
01:14right here with the new version that's going to send this form to a thank you
01:18page when users submit it, of course we have to create this thank you page
01:22because we don't have it yet.
01:23In Espresso I can just click right here to create a new file and call it
01:28thanks.html, and I'm going to go into my codesnippets.txt and copy the code for
01:35that page; it's pretty simple code, just a div with an id of thanks and then a
01:39headline and a paragraph.
01:40So we'll go into the thanks.html file and we'll paste the text for the page, hit
01:48Save, I'm going to hit the Save again here.
01:50And now when users submit the form they'll go to a thank you page, we need to
01:55add a few styles to make sure that this thank you page looks nice.
01:58So I'm going to go back to codesnippets, and grab some basic styles for the thank
02:02you page, copy that and go into mystyle.css, and just add some very basic styling
02:09to make the page look nice, save it.
02:12So now I need to add some jQuery that's going to prevent the form from
02:16submitting unless they have filled out the required fields.
02:19So I'm going to go back over here and click the back button, go into my
02:23codesnippets, find the next section of the code and grab this little piece of
02:29jQuery right here, go into myscript.js.
02:32And I want to add this code right here after the last click function, but not
02:38deleting this little piece of code right here which goes with the document
02:42ready function, the document ready function, just execute this code after the page has loaded.
02:47So I want the code to go right here.
02:49I want to hit Paste.
02:51And what this function does is make sure that all the required fields have a
02:55value of something when the form is submitted.
02:58If the form is submitted and these fields do not have a value, then this will
03:03return a false value which will prevent the form from being submitted.
03:08If all of these values have a value then this function will return true and
03:13the form will submit.
03:14So I'm going to save this, go back here, make sure that whenever you are dealing
03:18with JavaScript, you reload your page, and then I am going to try to submit this
03:23form and now the form doesn't submit, it will only submit if I fill a value for
03:29these different fields.
03:30So I fill the required fields, when I hit the send button it will take us to
03:35the thank you page.
03:36It would be nice to add some feedback to the user to make sure that they
03:40understand that they have failed to fill out some of the fields that we require.
03:44So I am going to go back into codesnippets, grab the next piece of code,
03:48which is just a div with an id of message so that we can place some feedback code in there.
03:53And so I'm going to go back into my index.html file, and I want to place this
03:58after the form field, but before any of the field sets.
04:02So it will appear at the top of the form fields, go back and refresh this page,
04:07it should appear right up here.
04:10I'll paste that right there;
04:11right now you can see that nothing is showing because this doesn't have any text
04:15in it, it will whenever we program it with jQuery.
04:17So I am going to save that.
04:20The next thing I want to do is actually create a style for the message.
04:24So back into codesnippets and I'm actually going to grab this and add it our
04:28style sheet to make sure that our messages have a little bit of a border radius
04:32and some color, background color so we'll go back into mystyle.css, and we'll
04:38paste that right there, hit save.
04:41Go back into the codesnippets and now we are going to grab a slightly different
04:46version of our submit function, copy that back into myscript.js and I'm going to
04:53replace this version of our submit function.
04:56So this version is pretty much like the last version, we have added an
05:00additional if statement, check to see if the name has been filled out and if it
05:04hasn't been filled out it adds a message, we've appended this message to the
05:09message id section and given it a class of message.
05:13So when I save this, go back into my file, I'm going to make sure I refresh this
05:20page and I am going to go to step three, try to submit the form and now I get a
05:26little bit of feedback.
05:27Notice that the feedback faded in a little bit and I did that by adding
05:31an animation function.
05:32If I just append the message then the message would appear immediately. In order
05:37to fade it in, first I need to hide the message and then fade it in and add a
05:41millisecond amount here to tell how fast it's going to fade in.
05:44And we have a problem with this form in that if we try to submit this form
05:47again, it's going to keep on adding messages on top of the field sets which
05:52might not be optimal especially when you have a lot of input elements that we're
05:55checking, this will get a little messy, so we need to clear this out when
05:59somebody tries to submit the message.
06:00So I'm going to go back to codesnippets, and grab the next piece of code, go
06:05back into myscript, replace the submit function, in this version we are
06:10clearing out all the messages when people resubmit by setting the message id
06:16that we created to empty.
06:17So if I come back here, I want to make sure I refresh this page, try to
06:21submit it, it will appear the first time, if I hit it again it will disappear and then reappear.
06:27Now it would be nice to have an alert that let us know where are on this page
06:31we needed to type the information that we forgot to include, so I am going to
06:34do that next, go back into codesnippets and grab the next version of our submit function.
06:39I am going to go back into myscript, replace this submit function, and in here
06:46we're adding an alert message after the myname input field, so you could see that
06:52this is pretty much like the last thing that we had, but we've added this line
06:55right here that says you find the element called myname and after it add an
07:00alert that says enter your name.
07:02So we'll save that, come back into our form, make sure we refresh, try to submit
07:07the form, we get this feedback right here, and if we tab over to Step 1, we
07:12can see that after the input field we have a little message, it doesn't look
07:16that great, so let's style it a little bit better.
07:18We'll go back into codesnippets and we created a special style, and this style
07:25just positions the element in the middle of this input field and adds a little
07:29bit of background color and roundness to the element.
07:31So we'll go into mystyle.css, and just paste that at the end and you can already
07:37see that feedback is a lot better with this style, so I'll save that.
07:42Back into our myscript.js file, we also take care of clearing that message if
07:47somebody resubmits the form in a slightly different manner, we are going to find
07:51the any alert class on the page and remove it.
07:55We can't empty it because it's not something that is inside this element, it's
07:59an item that we want to completely remove, so it's just going to remove this
08:03class if we try to submit this even though we forgot it this one time, we didn't
08:07fill it out even when it asked us to, if I try to submit it it's going to make
08:11this disappear and reappear.
08:13If I come back here I won't have more than one of these elements onscreen
08:17because I make sure that I am clearing them out right here.
08:20So now that we've done that for one element all we have to do is repeat that for
08:23all of the elements and I am going to grab this last piece of code, copy that,
08:29go into myscript.js, replace this function, all this is doing is repeating the
08:36same thing for all the other fields, the email field and the URL field.
08:40So I'll save this, I'll come over here, I'll refresh this form, go to Step 3,
08:45not fill anything out, try to submit it, it gives us three lines of feedback.
08:49If I go into Step 1, I can see the feedback is also in the individual input
08:53fields that needs to filled out, so I'll type in just one of them.
08:59Go to Step 3, try to submit this, now it's telling us that we forgot
09:02to include two things.
09:03If we go back to Step 1, you'll see that the little alert is no longer here,
09:07and I fill out my email.
09:10Go into Step 2, fill out a web site address, and go to Step 3 and send the
09:17form and now I can get to the thank you page.
09:20In this video we learned how to use jQuery and CSS to handle
09:23navigation feedback.
09:24To find out how this form was styled and how to get the navigation to work, make
09:29sure you check out the rest of the videos in this chapter.
Collapse this transcript
Additional Resources
Next steps
00:00To learn more about some of the topics on this course, there's a lot of
00:03excellent resources on the lynda.com Online Training Library.
00:07To find out more about designing forms make sure you check out Web Form
00:11Design Best Practices.
00:13To find out more about HTML5 and web forms, which gives you some tips on how to
00:18create alternatives for some of the new HTML5, form elements and attributes,
00:23make sure you see Joe Marini's HTML5: Web Forms in Depth.
00:27You might also want to check out a couple of my own courses Creating an Adaptive
00:31Web Site for Multiple Screens, and iOS Web Applications with HTML5 and CSS3.
00:38In this course I'm using some Seamless backgrounds and this is a really cool web
00:41site that I like for backgrounds in general, which also has some Seamless
00:46backgrounds that you can use on your web projects.
00:49If you love reading books there's a couple of really good books I like
00:51Introducing HTML5 by Bruce Lawson and Remy Sharp, it's a really good read, and
00:57also the jQuery Cookbook from O'Reilly.
01:01You can also check out my own web site, planetoftheweb.com and you can find me
01:05just about anywhere at planetoftheweb.
01:07I hope you have a great day and enjoy working on your code.
Collapse this transcript


Suggested courses to watch next:

CSS Fundamentals (3h 14m)
James Williamson

CSS: Core Concepts (8h 49m)
James Williamson


CSS3 First Look (6h 34m)
James Williamson

Managing CSS in Dreamweaver (4h 40m)
James Williamson


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,141 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,025 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked