11 Handout 1
11 Handout 1
CSS3 Properties
I. Linear Gradients
A. Creating Linear Gradients
• CSS gradients enable you to display smooth transitions between two (2) or more specified
colors. CSS defines two (2) types of gradients: Linear and Radial.
• To create a linear gradient, you must define at least two (2) color stops. Color stops are the
colors among which you want to render smooth transitions. You can also set a starting point
and a direction--or an angle--along with the gradient effect.
• For example:
o The CSS:
DIV {
float: left;
width: 300px;
height: 100px;
margin: 4px;
color: #FFF;
background:-moz-linear-gradient(DeepSkyBlue, Black);
}
o The HTML:
<DIV>Linear Gradient</DIV>
B. Color Stops
• Color can be added one (1) after the other, separated by a comma. The browser will then
determine each color stop position.
• For example:
• The CSS:
DIV {
float: left;
width: 300px;
height: 100px;
margin: 4px;
color: #FFF;
background: linear-gradient(blue,
yellow, green, pink, white);
}
• The HTML:
<DIV>Multiple Colors</DIV>
o The HTML:
<DIV CLASS="first">Left to Right</DIV>
<DIV CLASS="second">Bottom to Top</DIV>
E. Repeating a Linear-Gradient
• The repeating-linear-gradient() function is used to repeat a linear gradient.
o The CSS:
DIV {
float: left;
width: 300px;
height: 100px;
margin: 4px;
color: #FFF;
background: repeating-linear-
gradient(blue, green 20px);
}
o HTML:
<DIV>Repeating Gradient</DIV>
• The background-size also accepts the cover keyword. The image is scaled to fit the entire
container, however, if that has a different aspect ratio, the image will be cropped.
o The CSS:
background-size: cover;
}
o The HTML:
<DIV ID="first">
<P>background-clip: padding-box</P>
</DIV>
<BR />
<DIV ID="second">
<P>background-clip: content-box</P>
</DIV>
E. Multiple Backgrounds
• The ability to have multiple background images is a new feature in CSS3.
• Multiple background images are specified using a comma-separated list of values for the
background-image property. The first image will appear on the top, and the last on the
bottom.
• For example:
o The CSS:
div {
width: 400px;
height: 300px;
background-image: url(csslogo.png), url(csscode.jpg);
background-position: right bottom, left top;
background-repeat: no-repeat;
}
o The HTML:
<DIV></DIV>
• For example:
o The CSS:
transition:transform 5s ease-in;
C. The transition-timing-function
• The transition-timing-function property specifies the speed curve of the transition
effect. It can have the following values:
• ease - the animation starts slowly, then accelerates quickly.
• ease-in - starts slowly, then accelerates, and stops abruptly.
• ease-out - starts quickly, but decelerates to a stop.
• ease-in-out - similar to ease, but with subtler acceleration and deceleration.
• linear - constant speed throughout the animation; often best for color or opacity changes.
• Finally, we have cubic-bezier(), which allows you to define your own values in the cubic-
bezier function. Possible values are numeric values from 0 to 1.
o The CSS:
width: 50px;
height: 50px;
background: #32CD32;
transition: width 3s;
transition-timing-function: cubic-bezier(0,0,1,1);
-webkit-transition: width 3s;
-webkit-transition-timing-function: cubic-bezier(0,0,1,1);
}
DIV:hover {
width: 250px;
}
V. CSS3 Transforms
A. The transform:rotate() Property
• CSS3 transforms allow you to translate, rotate, scale, and skew elements.
• A transformation is an effect that allows an element to change its shape, size, and
position.
• CSS3 supports 2D and 3D transformations. The following is an example of rotate
transformation.
o The CSS:
DIV {
width: 200px;
height: 100px;
margin-top: 30px;
background-color: #32CD32;
}
• Now let us apply the DIV element to rotate by 10deg.
o The CSS:
DIV {
width: 200px;
height: 100px;
margin-top: 30px;
background-color: #32CD32;
transform: rotate(10deg);
}
margin: 60px;
width: 200px;
height: 100px;
background-color: #8bc34a;
transform: scale(1.5,1.5);
color:white;
}
D. Multiple Transforms
• Multiple transforms can be used at once. Rotating and scaling the size of an element at the
same time is an example of multiple transforms.
• Here is an example with two (2) transforms defined:
o The CSS:
DIV{
width: 200px;
height: 100px;
background-color: #8BC34A;
transform: rotate(45deg) translate(100px);
-webkit-transform: rotate(45deg)
translate(100px);
color:white;
}
References
SoloLearn. (n.d.). HTML. Retrieved on July 19, 2018, from https://www.sololearn.com/Play/HTML
Beaird, J. & George, J. (2014). The principles of beautiful web design. Collingwood, AU: SitePoint
Pty. Ltd.