7 May 2012
Basic understanding of HTML and CSS. Familiarity with Dreamweaver interface.
All
When an HTML element changes state—for example, if you mouse over a link—changes to its CSS properties are instantaneous. This looks fine with links, but the effect can be very jarring if you use CSS3 transformations to scale and/or rotate elements. To smooth out the sudden jump from one state to the other, you need to apply a CSS3 transition. Although the CSS3 Transitions module is still only a working draft, it's considered stable, and is widely supported by all mainstream browsers (Internet Explorer plans to support it in IE 10). The only drawback is the need to create five versions of each style rule—one for the standard property, plus vendor-specific versions for each of the major browsers.
The new CSS Transitions panel in Dreamweaver CS6 simplifies creating a transition not only by automatically generating the style rules for each browser, but also by creating the style rule for the state at the end of the transition. In this tutorial, you'll learn how to use the CSS Transitions panel to rotate and scale images when you mouse over them. You'll also learn about new options for images in the Property inspector.
The sample files for this tutorial contain a simple web page to which you'll add three images, rotate them using the CSS3 transform property, and then use the CSS Transitions panel to rotate and scale them when moused over.
The images in column on the right of the page are scaled down by adjusting the width and height in the Property inspector, and are styled to look like photographs scattered at different angles.
Although you shouldn't normally use HTML to resize images, scaling them down is necessary to prevent distortion when they're scaled back up to their original size when hovered over.
<div> on the right contains only placeholder text (Figure 4).
<div> , and insert nice_seafront.jpg inside the <div> , either by selecting Insert > Image or by dragging and dropping the image from the Files panel.
If it's unlocked, click the icon to lock the padlock. Clicking the icon toggles it on and off.
The middle icon resets the image to its original size.
The check mark icon on the right commits the new image size. Do not click this icon, because it permanently resizes the original image.
The width and height should be displayed in bold, indicating that the dimensions in the underlying HTML are different from the original image.
<div> , adding appropriate alternate text and scaling them to the same size as the first image.To style the images like printed photographs, you just add white as the background color, some padding, and a border.
The CSS3 transform property makes it easy to rotate elements. Although the property is stable and is supported by the latest versions of all mainstream browsers (including IE 9), it's officially still regarded as experimental, so it requires using vendor-specific prefixes. To rotate the images in opposite directions, you need to create two classes.
transform property. So click OK to create an empty style rule.transform from the list of properties.rotate() , as shown in Figure 8.
rotate() , and type 6deg. There must be no space between the number and deg . This rotates an element 6 degrees clockwise.rotate() . Using a negative value rotates the element counterclockwise..rotateright {
transform: rotate(6deg);
}
.rotateleft {
transform: rotate(-6deg);
}
transform style declaration in the rotateright class, insert a new line, and paste it four times. Then add the vendor specific prefixes for Firefox, Internet Explorer, Opera, and WebKit-based browsers (Safari, Chrome, iOS, and Android) like this:.rotateright {
-moz-transform: rotate(6deg);
-ms-transform: rotate(6deg);
-o-transform: rotate(6deg);
-webkit-transform: rotate(6deg);
transform: rotate(6deg);
}
Dreamweaver's code hints should speed up editing the style definition by presenting you with the vendor-specific prefixes as soon as you type a hyphen.
rotateleft class, which should look like this:.rotateleft {
-moz-transform: rotate(-6deg);
-ms-transform: rotate(-6deg);
-o-transform: rotate(-6deg);
-webkit-transform: rotate(-6deg);
transform: rotate(-6deg);
}
rotateright class to it.rotateleft class to the second image, and rotateright to the last one.
Although a transition is applied when an element's state changes, the recommended practice is to define the transition in the style rule that governs the element(s) in their normal state rather than in the pseudo-class that defines the new state. The new CSS Transitions panel in Dreamweaver CS6 follows this convention, but also creates the style definition for the pseudo-class at the same time.
A CSS transition is a simple animation that controls the speed of transitioning from one state to another, such as when you hover over an element.
To create a CSS transition, you specify how long the transition should take (in seconds or milliseconds), and how long a delay there should be (if any) before the transition starts. You also specify what's called a timing function, which controls the speed of the transition as it progresses. The timing function expects one of the values listed in Table 1.
Table 1. Timing functions for CSS transitions
Timing Function |
Meaning |
cubic-bezier(x1,y1,x2,y2) |
Specifies a cubic-bézier curve to control the speed. The x values must be in the range of 0–1. The y values can exceed this range. |
ease |
Starts slow, speeds up, and slows at end. |
ease-in |
Starts slow, and speeds up. |
ease-in-out |
Similar to ease, but slower at each end. |
ease-out |
Starts fast, and slows towards the end. |
linear |
Constant speed throughout. |
Using cubic-bezier() as an option requires a specialist knowledge of cubic-bézier curves. The other keywords are sufficient for most purposes. If you have used Flash, the concept of easing will be immediately familiar. If you're new to the concept, just experiment with the different settings to see which you prefer. The default is ease .
When specifying a transition, you can apply the same values to all properties or different values to each one. Although many properties are animatable, some are not. For example, you can change the height , width , and opacity of an element, but not its display property. Similarly, you can animate the top , left , bottom , and right properties, but not the position property.
To make working with transitions easier, Dreamweaver's CSS Transitions panel lists only properties that are currently known to be animatable. So, if a property isn't listed, it's almost certainly not animatable.
By default, the CSS Transitions panel is not displayed, so you need to open it before you can use it to apply a transition.
<div> . Although it's not essential to select the target element(s) beforehand, I have found it useful in my tests, because Dreamweaver occasionally applies the transition to whatever's selected in addition to the settings you create.
You want to apply the transition to all the images in the gallery <div> , so click the down arrow and select #gallery img.
s (seconds) as the unit of measurement, so this sets the duration of the transition to half a second.NOTE: The drop-down menus to the right of the Duration and Delay fields also have ms as an option. This sets the value in milliseconds (one-thousandth of a second).
transform .NOTE: Instead of using the transform property to scale the image, you could add the width and height properties to the Property pane, and set the end values to 400px and 266px respectively. However, using the transform property to rotate and scale the images in the same operation is simpler.
#gallery img with 3 instances of a hover transition, as shown in Figure 12.
transform property rotates elements from the center.
#gallery img style rule now looks like this:#gallery img {
background-color: #FFF;
padding: 10px;
border: 1px solid #000;
-webkit-transition: all 0.5s ease-out 0.2s;
-moz-transition: all 0.5s ease-out 0.2s;
-ms-transition: all 0.5s ease-out 0.2s;
-o-transition: all 0.5s ease-out 0.2s;
transition: all 0.5s ease-out 0.2s;
}
Dreamweaver has added the transition property with all the necessary vendor-specific prefixes.
At the bottom of the style sheet, there's a new style rule that looks like this:
#gallery img:hover {
-webkit-transform: rotate(0deg) scale(1.33);
-moz-transform: rotate(0deg) scale(1.33);
-ms-transform: rotate(0deg) scale(1.33);
-o-transform: rotate(0deg) scale(1.33);
transform: rotate(0deg) scale(1.33);
}
This controls the state of the images at the end of the transition. Because the transform property requires vendor-specific prefixes, Dreamweaver has added them automatically, saving you a lot of work.
To fix the problem with the images not coming to the front, you need to use relative positioning, and change the z-index property when the image is hovered over. The other problem of the images being cut off on the right can be fixed by using the transform‑origin property, which specifies the anchor point of a transformation.
#gallery img style rule in the CSS Styles panel, and click the Edit Rule icon at the bottom of the panel to open the CSS Rule Definition dialog box.transform-origin property, so the easiest way is to work in Code view with the help of code hints. Edit the rotateright and rotateleft class definitions like this:.rotateright {
-moz-transform: rotate(6deg);
-ms-transform: rotate(6deg);
-o-transform: rotate(6deg);
-webkit-transform: rotate(6deg);
transform: rotate(6deg);
-moz-transform-origin: right top;
-ms-transform-origin: right top;
-o-transform-origin: right top;
-webkit-transform-origin: right top;
transform-origin: right top;
}
.rotateleft {
-moz-transform: rotate(-6deg);
-ms-transform: rotate(-6deg);
-o-transform: rotate(-6deg);
-webkit-transform: rotate(-6deg);
transform: rotate(-6deg);
-moz-transform-origin: right bottom;
-ms-transform-origin: right bottom;
-o-transform-origin: right bottom;
-webkit-transform-origin: right bottom;
transform-origin: right bottom;
}
This anchors the rotation and scaling of the rotateright class to the top-right corner of the image, and of the rotateleft class to the bottom-right corner. Note that the horizontal keyword must precede the vertical one.
NOTE: If the CSS Transitions panel is blank, click anywhere in Design view to restore the focus to the HTML page.
This opens the Edit Transition dialog box, which is the same as the New Transition dialog, except that the options to change the Target Rule, Transition On, and style sheet are grayed out.
z-index property is increased to 10 on hover, but returns to 1 in the normal state.transform-origin property has made the images look untidy in their normal state.Amend the rotateright and rotateleft classes to add a margin-top of 20px and -40px respectively.
transform property, but older versions of Internet Explorer still have a large market share. To adjust the top margin of the images in IE 6–8, add the following Internet Explorer conditional comment just before the closing </head> in transitions.html:<!--[if lte IE 8]>
<style>
.rotateleft {
margin-top: 20px;
}
</style>
<![endif]-->
The images won't be rotated in IE 6–8, but they'll be displayed with a 20-pixel gap between each one.
If you decide to remove a CSS transition, select it in the CSS Transitions panel, and click the minus button at the top-left of the panel. This opens the dialog box shown in Figure 15.
Resist the temptation to accept the defaults without checking them. The options for Remove Target Rule allow you to remove the entire rule or just the transition properties. If you select the Entire rule radio button, the whole #gallery img style rule will be removed from transitions.css. Normally, you would want to remove only the transition properties. However, if you have applied multiple transitions to the same element(s), you might want to preserve the transition values, in which case you should deselect the Remove Target rule check box.
Selecting the Remove Transition On rule(s) check box removes the pseudo-class style rule that sets the values for the end of the transition. In this example, it would remove the #gallery img:hover style rule.
The Remove class from element(s) check box is grayed out in Figure 15 because the example in this tutorial uses a descendant selector as the target rule. However, if you use a class as the target rule, this gives you the option to remove the class from the element(s) when deleting a transition.
The CSS Transitions panel adds the transition property to the style rule that controls the normal state as well as creating the pseudo-class that controls the end state, all in a single operation. However, there are occasions when you might want to create the transition independently of the pseudo-class, for example if you want to use a parent element to trigger a transition. To deal with such situations, there's a new Transition category in the CSS Rule Definition dialog box, as shown in Figure 16.
The options are identical to the New Transition dialog box in the CSS Transitions panel. However, they set only the transition. You need to create the pseudo-class for the end of the transition separately.
The CSS Transitions panel in Dreamweaver CS6 makes it easy to smooth the change from one state to another, such as when hovering over an image, without the need for JavaScript. The panel builds all the CSS style rules for both the transition and the end state. It also simplifies editing and removing the style rules cleanly. For more complex transitions, you can use the new Transition category in the CSS Rule Definition dialog box.
To learn more about CSS3 transitions, you might find the following resources helpful:
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.
Tutorials and samples |
Dreamweaver user forum |
More |
| 04/23/2012 | Resolution/Compatibility/liquid layout |
|---|---|
| 04/20/2012 | using local/testing server with cs5 inserting images look fine in the split screen but do not show |
| 04/18/2012 | Ap Div help |
| 04/23/2012 | Updating |
Dreamweaver Cookbook |
More |