Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
One of the most efficient practices in CSS is the use of shorthand notation for certain properties. Rather than writing four separate properties for top, right, bottom, and left margin, for example, you can write a single margin property and cut down the code required throughout your CSS, considerably. If you hand-code, you're likely to handle the creation of shorthand notation yourself; however, if you use Dreamweaver's Visual CSS tools, you can control how Dreamweaver handles shorthand notation by setting some quick CSS preferences.
And you can see that we have a rule on our style sheet, a list item selector. It's written incredibly and efficiently, as you can see as I scroll through this. So, we have padding all the way around. We have margin all the way around, and we have font-family and font-size, and we have a lot of borders going on here. We have borders top, right, bottom, and left, background color, image, position, repeat. Okay, so anybody that would create code by hand understands that this is incredibly inefficient. This is not the way that you would probably want to write this code.
Well, if you're creating your CSS through Dreamweaver visually, you'll likely use shorthand notation, so that instead of say five separate properties, you're really only writing one. Well, if you're going to create styles through Dreamweaver's Visual tools, you can control how the shorthand notation is written and when it's written. All you really have to do is set one simple property. So, what I'm going to do is go up again to Edit and choose Preferences. Again, if you're on the Mac, you're going to go to Dreamweaver > Preferences, and I'm going to click on the CSS Styles Category.
Now you can see the main focus of the CSS Styles Preferences is on shorthand notation. I can see here that I don't have any of these items selected. Now if you're opening up this dialog box for the first time, chances are you'd probably see a few of those checked, because Dreamweaver, by default, will go ahead and try to write the most efficient styles possible for you, but you are able to go in here and control this yourself. Now what I'm going to do is I'm going to go ahead and choose using shorthand notation for Background, Margin and padding, Border and border width, and List-Style, but I'm going to leave Font off.
Now the reason I'm going to that is because if you use the shorthand notation for the Font selector, you generally have to pass a lot of information into it: font-weight, font-style, font-size, the font-family that you're looking for. You're free to leave all that off. In fact, for a font shorthand notation, you really only need to pass in size and the font-family itself, but all the things that you leave off it goes ahead and defaults to the default value. Now if you have a style in the cascade above this that has a font-weight bold on a paragraph, and then later on you write another style for paragraph where you just pass in size and font family, well, your paragraph is going to reset from bold, because it will overwrite the earlier style.
So I really don't like Dreamweaver controlling that. If I use shorthand property for the font notation, I'll go ahead and do that myself. So I've got those four selected, and you'll notice it has a choice here for when editing CSS rules. So after the rule has been written, if you edit it, you know when should shorthand be used? Notice that I'm going to go ahead and leave the default according to the settings above. That means that whenever a rule is edited, regardless of its current state, it's going to look at these rules above to determine whether it should convert it to shorthand notation or not. We also have an Open CSS files when modified.
That means if you modify a rule, and the CSS file itself was not already opened, it would go ahead and open that up. Now, since we have related files in Dreamweaver, that's not as important as it used to be, but it's still nice to leave that checked. Now, in the CSS Styles panel, which we're going to be using in just a moment, when you double-click a style to edit it, it's going to do one of three things. It's either going to edit it using the Visual CSS dialog box which is the default, it's either going to edit it through the Properties pane which the Properties Inspector would change to reflect that particular selector, or edit using Code View which would switch you over to Code View, jump to that style and let you edit it.
So, you could sort of choose your own personal preference for that ,as well. For the moment, I'm just going to leave it as Edit using CSS dialog. All right. I'm going to go ahead and click OK, and now we've reset our Preferences. Now, speaking of the CSS Styles panel, I'm going to go over to that and then click on All. So even though we are looking at our CSS in Code View, I can still access and control things through the CSS Styles panel. I'm just going to come right over here to my shorthand.css, double-click the li and notice that based on our preferences, it goes ahead and opens up the CSS Rule definition dialog box.
Okay, so we're going to make a couple of changes here. I'm going to click on the Background Category, and I'm just going to go ahead and change my Background repeat to no-repeat. I'm going to go to my Box Category, and I'm going to change Padding, Same for all to 20 pixels. I'm going to do Margin. I'll leave everybody the same, except for, let's see, the Left Padding. We're going to take the Left Padding, and we're going to change it to 15 pixels as well. Then finally, I'm going to go to my Border Category, and I'm going to change that to 2 pixels.
Now, we do have some font information here, too. So let's make sure that it's not going to rewrite the font selector as shorthand notation. I'm going to go ahead and change the Font -size to 0.9 ems, and I'm just going to go ahead and click OK. Now as soon as I do that, look at how Dreamweaver changed the code. It listened exactly to my Preferences, and it left the font alone. So I still have a font- family and a font-size selector. It did not go ahead and convert that to shorthand notation. Background, Margin, Padding and Border, on the other hand, now I have shorthand notation for those, and look how many fewer lines of code we have here.
We went from 20 something lines of code, I think, to around 7 lines of code for the same selector. So, that's really, really impressive. Now, one of the main objections that I've heard from those that prefer to hand-code over letting Dreamweaver automate some of that process is they feared giving up control of exactly how the code is written. They just preferred to do it the way that they want to do it. However, if you access the CSS Style Preferences, like we just did, you can control when and how Dreamweaver handles the creation of shorthand notation. Now, that alone can go a long way towards making sure your styles remain consistent, whether you or Dreamweaver is writing them.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 103232 Viewers
58 Video lessons · 55908 Viewers
61 Video lessons · 89966 Viewers
56 Video lessons · 105085 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.