CSS: Styling Forms
Illustration by Mark Todd

Styling for progressions


From:

CSS: Styling Forms

with Ray Villalobos

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Video: Styling for progressions

Some forms can get so complicated that you'll need to find ways of the dividing the information into different sections. In this chapter, I am going to show you how to style a form, so that the different field sets appear as different tabs. This video is part of a series where I'll show you how to use jQuery to handle navigation between field sets as well as how to validate the form and style the validation elements. Let's get started by defining our basic style sheet for our form. So I am going to go to the exercise files and open up the Starting Points folder, find the starting point for this video.
please wait ...
Watch the Online Video Course CSS: Styling Forms
4h 1m Beginner Jan 20, 2012

Viewers: in countries Watching now:

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
    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
Subject:
Web
Software:
CSS
Author:
Ray Villalobos

Styling for progressions

Some forms can get so complicated that you'll need to find ways of the dividing the information into different sections. In this chapter, I am going to show you how to style a form, so that the different field sets appear as different tabs. This video is part of a series where I'll show you how to use jQuery to handle navigation between field sets as well as how to validate the form and style the validation elements. Let's get started by defining our basic style sheet for our form. So I am going to go to the exercise files and open up the Starting Points folder, find the starting point for this video.

And I am going to copy the Working Folder onto the desktop, holding down the Option key and dragging it, and then I want to take this Working Folder and drag it onto Espresso, so it will open it up as a project. And then I am going to take the codesnippets.txt file and move it into the workspace, and I'm also going to double-click on the index.html file and the mystyle.css, so it also goes into the workspace. So let's take a look at our HTML document and I'm going to hit the Preview button holding down the Option key so that we can get a live preview.

So we have an HTML form with three different field sets; one for login information, another one for other information, and a section for comments. Two of the fieldsets have an additional class called hidden right here, that will hide these fieldsets on the final form. Let me show you what this page is going to look like after we get done with this video. Our page will look like this. So we could do that. We can get started by going into the codesnippets.txt file and scrolling up to the information for our current video.

So we'll copy the links to our normalize.css document and then mystyle.css file and we'll put that in the index document, in the head section. So you could see that some of these styles have already taken effect, we'll go back into codesnippets and grab some additional code for clearing form elements a bit further and to clear any items that were floating. So I am going now to the mystyle.css document and I'm going to paste that and you could see that we are clearing the appearance of most of the input fields to make them all start with similar look.

Back into codesnippets, I am going to get some basic styling for the body section as well as some basic styling for the form, so I am going to copy that and go back into my stylesheet. And here I'm adding some background to the body section, this looks like a lot of code, but it's really just some code for a background texture and a gradient beneath that background texture with different browser prefixes so that it displays in most browsers. Now for the form element we have added a font and some other basic styling plus a border-radius, so that the edges of this form are rounded, as you can see right here, and we have a different texture that we have applied to the form plus some roundness to the edges and a slight drop shadow.

Now we need to fix the fieldset outline and style the legends as well. So we are going to go back into codesnippets, scroll down and I am going to grab this piece of code right here, go back into our stylesheet and just paste that at the bottom. What this is going to do is just style the fieldsets and because the fieldsets display differently in different versions of Internet Explorer and other browsers, we need to do a little trick that we have done before in other videos. And because the legends will display differently in different browsers, especially versions of Internet Explorer, we are going to hide the way the legends are displayed and then display the legends by grabbing the title from the fieldset and styling then that by using a before pseudo tag.

This will work for most versions of Internet Explorer except for versions of Internet Explorer before version 8. So we are going to have to go back into codesnippets and grab another piece of code that will fix this problem in Internet Explorer 7. So we'll grab this little piece of code. This is a conditional stylesheet that applies only if the version of Internet Explorer is less than Internet Explorer 8. So we'll copy that, go back into our index file and paste that in our head section, and then we'll go back into codesnippets to grab some code to handle the list items. By default list items display with numbers right next to them and they're indented quite a bit, so we're going to grab some code to take care of that.

Go back into mystyle.css. I'm going to paste that and you can see that here I took care of some of the margins and the numbers that appear normally on ordered lists, and I also took care of adding a little bit of a border before and after each one of the list items giving the form an embossed look between each one of the fields. And then on the first element and the last element of each list, I deleted the borders so that we don't see these weird kind of borders that will appear at the beginning and at the end of the form.

So if we don't do this, you'll see an extra border appear at the beginning and end of each list item. All right our form is looking pretty good. This field right here needs to be fixed a little bit further. This is a second level ordered list, so we'll go back into codesnippets and we'll grab the code to fix those elements asking them to be displayed as inline elements. So now those appear as inline elements right next to each other, how they should. So back into codesnippets we'll grab a little bit of code to fix our labels.

So back into mystyle.css, and this will style all our labels so that they look really nice now, and notice that I have some basic code for the labels, and then I have a special version of the code for a singleline label, which is a special class that I use for styling this particular label. I don't want this label to be bolded like the other one, and for the labels that are part of a group, so I have this special request type text as a grouphead class because technically it's not a label, although it's a label for these other elements.

Each one of these elements are already a label. So I can't style those. I have to style a headline which I've done with this group class right here. You can see it in the index.html. If I scroll down to that section on the Comments, I have this div class that's acting as our headline, have a class of grouphead so that I can style it like the other labels as well. Back into our codesnippets, now we're going to grab some code to handle the text area and the input field. So these inputs fields right now are just a little bit too short and this text area also needs to be a lot bigger and have a little bit of a better style.

So we'll grab this, back into mystyle.css, I'm going to paste that, and you can see that our fields are now a good width and so is our text area, and they have essentially just a slight gradient so that you can see they are just a bunch of browser prefixes, and so they have a nice little slight gradient for the inside and some other settings here to just give it a little bit of breathing room and width that looks more appropriate to the form.

So back into the codesnippets, now we are going to grab a section for second level inputs. Notice what's happening down here, our second level inputs are displaying kind of right on top of each other, because we've done that to all these other input fields, we've all told them to display right on top of each other so that the labels appear on top. So we need to fix that with this section right here, and we are also going to -- let's go back to mystyle.css. So that kind of fixes most of it.

I am going to refresh the screen because sometimes the live preview in Espresso doesn't refresh appropriately. So you can see now by adding those pieces of code we have fixed our second level input fields, asked them to display as inline, and we've also made sure that on all browsers that the check boxes are also displayed as inline elements that way, this will always be right next to it. Then we have added a little bit of a taller height to our text area to make sure we have plenty of room to write in here.

So back into the codesnippets, so let's now style the select field which looks a little plain, looking white like that, so we're going to grab this piece of code. And this is essentially just some width and height styles plus a gradient that looks really nice. Let's go ahead and apply that so we can see it. Let's see the gradient, it's a slight gradient that just gives it a different color, and we have a bunch of different browser prefixes here as well as some roundness to the edges. So back into codesnippets, just about the only thing that's left is to style the button, so it gets a lot of code, but again most of it is right here in the background gradient that we are applying there.

So I am going to copy that, go back into the mystyle.css area, and I'm going to paste that and you can see that the send button gets some standard width and height. My entire form is using variable width, so you could see that if I resize these forms, the forms will resize up to a certain point. Finally, I am going to go back into my codesnippets to get the hover version of this arrow, and the hover version of the arrow is just going to be a different color background.

So back into the CSS file, and this has the pseudo-class hover here, so all we do here is just change the color of the gradient so that when we roll over this button, we get a different color gradient and these are all just browser prefixes. We've done a lot of styling that you've probably seen in some of the other videos in this series, and this already looks like a great form, but in future videos I am going to show you how to add navigation and interactivity.

There are currently no FAQs about CSS: Styling Forms.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Styling Forms.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

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.

Sign up and receive emails about lynda.com and our online training library:

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

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.