Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Writing global classes

From: Managing CSS in Dreamweaver

Video: Writing global classes

For the most part, your style sheets will consist of specific styles targeting elements on the page; However, it's extremely helpful to have a global serve classes that can assist when needing to do common tasks, such as floating elements, clearing floats and basic elements styling. These classes can then be used to add styling without needing to write extraneous markup all the way throughout your styles. So here I have the main.css, and I want to go down to my global classes sections. I am just going to scroll down through my sections until I find this one, about line 129.

Writing global classes

For the most part, your style sheets will consist of specific styles targeting elements on the page; However, it's extremely helpful to have a global serve classes that can assist when needing to do common tasks, such as floating elements, clearing floats and basic elements styling. These classes can then be used to add styling without needing to write extraneous markup all the way throughout your styles. So here I have the main.css, and I want to go down to my global classes sections. I am just going to scroll down through my sections until I find this one, about line 129.

Now, these are going to be what I consider to be utility styles, meaning I'm not going to rely on them to do this every single time, but if I'm working and maintaining my site later on, and all of sudden, I am like, hey, I need to float this element to left, or float it to right, and I don't want to change its parent selector, then I'm going to apply the class, alright. So the first class I want to do is .floatRight. Notice that's all one word, and the dot is in the front of it because this is a class selector. I'm going to go ahead and open up my curly brace and come down and choose floatRight, just like that.

So now anytime I need to float an image, or some text, or an element to the right, and it's not part of my overall stylessheet, I can simply select it and apply this class to it. So that's why I kind of think of it as a little utility. I can just go ahead, anytime I need it, go ahead apply it. Let's keep going. Let's do a .floatLeft, again notice that I'm preceding that little period, and for that one I want to choose float, and I want to choose left of the value. There we go. Let's keep going. I'm also going to do a .clearRight, and its property is indeed going to be clear right.

Now this is actually a more common need, frankly, than the classes above it. Anytime we do in a float-based layout, a lot of times you have an element that you really don't want to wrap around another element, or an element that you don't want to float above to affect. Well, if that's the case, then I can just go ahead and apply this, and again, it's going to eliminate the need for me to have this property as part of the parent class. Let's go ahead and do .clearLeft, all one word, while we're at it, and indeed do clear left on this one as well as a property. So you will notice that these are a single property and very descriptive as to what they do: clearRight, clearLeft and in case of the next one .clearBoth.

Now, did you see how I left that period off? It's so easy to do when you are hand-coding that. So always get in the habit of putting those on there. Sometimes, like me, you'll just kind of forget them. clearBoth, and now anything that we don't want any floating, left or right, we can use that class to apply. We are going to do one more, and here I'm going to go ahead and do .quote and under that, I'm going to do font style, so font-style, and we are going to do italic. So those are our global classes, very simple, very easy: floatLeft, floatRight, clearRight, clearLeft, clearBoth, and the just a quote so when we want to italicize some text and we don't need to use the emphasis tag, then we will use a Span tag and apply this class to it.

Now, by no means is that all of the global classes that you can write. I have seen css styles out there where they have hundreds and hundreds of lines of global classes that they can apply anytime they need it. You have to be very, very careful about that. Global classes can really speed up your site development, but you can also become too dependent upon them. Overusing classes is one of the most common mistakes made when writing css, and it results in a lot of unnecessary code and harder styles to edit and maintain later on. Imagine that if you want all of yours headings to be a certain color, instead of just writing a heading selector, you apply that class.

Now, you have got to go in and if you delete the class, really make them, just really large edits to your styles. Be careful about that. My advice is to add global classes that won't conflict with any specific rules, because that's the other thing. You want to avoid style conflicts, and you can turn to them and use them when you need that particular styling without having to affect or write a brand-new parent style for it.

Show transcript

This video is part of

Image for Managing CSS in Dreamweaver
Managing CSS in Dreamweaver

41 video lessons · 20882 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 4m 12s
    1. Welcome
      1m 10s
    2. Who is this course for?
      1m 5s
    3. Using the exercise files
      1m 57s
  2. 1h 21m
    1. Controlling CSS in Dreamweaver
      2m 34s
    2. Style formatting options
      4m 59s
    3. Controlling shorthand notation
      6m 9s
    4. Building a style-focused workspace
      6m 10s
    5. CSS Styles panel overview
      8m 18s
    6. The Properties Inspector
      6m 39s
    7. Creating styles visually
      11m 32s
    8. Hand-coding styles
      8m 15s
    9. Code hinting and code completion
      7m 11s
    10. Modifying styles visually
      5m 24s
    11. Using the Code Navigator
      4m 47s
    12. Using CSS Inspect
      9m 52s
  3. 1h 14m
    1. Structuring style sheets
      4m 52s
    2. Writing a style header
      2m 40s
    3. Building a color guide
      6m 5s
    4. Writing a style sheet table of contents
      8m 46s
    5. Creating sections for styles
      9m 10s
    6. Using the CSS Styles panel to organize styles
      10m 29s
    7. Resolving conflicts
      7m 3s
    8. Organizing style properties
      9m 33s
    9. Writing a CSS reset
      5m 20s
    10. Writing global classes
      3m 57s
    11. Creating a style guide
      6m 6s
  4. 1h 7m
    1. Preparing custom starter pages
      11m 32s
    2. Building custom starter pages
      10m 8s
    3. Working with code snippets
      9m 54s
    4. Writing snippets
      11m 30s
    5. Importing snippets
      6m 3s
    6. Understanding snippets libraries
      8m 11s
    7. Building a CSS framework using snippets libraries
      10m 36s
  5. 52m 15s
    1. Writing a print style sheet
      10m 3s
    2. Creating print-specific styles
      10m 45s
    3. Preparing modular styles
      4m 33s
    4. Creating modular style sheets
      7m 9s
    5. Checking browser compatibility
      6m 25s
    6. Using conditional comments for Internet Explorer
      6m 58s
    7. Optimizing CSS with Dreamweaver
      6m 22s
  6. 38s
    1. Goodbye
      38s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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

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 Managing CSS in Dreamweaver.

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 ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.