Professional Documents
Culture Documents
When using CSS image rollovers, two, three, or more images must be loaded (and
often be preloaded for best results). We've got one image for each state (normal,
hover, active, visited etc). Putting all states into one image makes dynamic
changes faster and requires no preload.
Let's have a simple example. The menu items are the a-elements
with display:block. Proper padding and background image
for a, a:hover and a:active make the rollover. To simplify the rollover, I used only
one picture containing three states of a button normal, :hover, and :active.
(padding) a obrzek na pozad pro a, a:hover a a:activevytvej dynamick tlatko (rollover). Pro jeho zjednoduen jsem
pouil jen jeden obrzek, obsahujc ti stavy tlatka normln, :hover a :active.
#menu a {
...
#menu a:hover {
...
background-image: url("button-over.gif");
#menu a:active {
...
background-image: url("button-active.gif");
/* etc... */
Using one common picture, we don't need to change the background image. We
just change its background-position. The :hover state will use the background
image moved proper count of pixels (in the example the shift is 157px to the
left), the :active state will use bigger shift (by 314px in the example).
Kdy ale pouijeme jeden spolen obrzek, mnit obrzek na pozad nemusme. Sta zmnit jeho umstn (hodnota backgroundposition). Pro stav :hover se pouije pozad posunut o vhodn poet pixel (v naem pkladu to je o 157px doleva), stav :active pouije
posun jet vt (v pkladu o 314px).
#menu a {
...
#menu a:hover {
background-position: -157px 0;
...
#menu a:active {
background-position: -314px 0;
...
Sin sombra:
VARIAS SOMBRAS
Tambin es posible poner ms de una sombra. En general, el
resultado es un tanto extrao:
h3 {text-shadow: 0.2em 0.5em 0.1em #600,
-0.3em 0.1em 0.1em #060,
0.4em -0.3em 0.1em #006}
BRILLO DE NEN
Si se pone una sombra borrosa justo detrs del texto, es decir,
con desplazamiento igual a cero, el efecto es un resplandor
alrededor de las letras. Si el resplador de una sola sombra no
es suficientemente intenso, basta repetir la misma sombra
unas pocas veces:
h3.a {text-shadow: 0 0 0.2em #8F7}
h3.b {text-shadow: 0 0 0.2em #F87, 0 0 0.2em #F87}
h3.c {text-shadow: 0 0 0.2em #87F, 0 0 0.2em #87F,
0 0 0.2em #87F}
Before I know about this technique, I was using different images for each
of the button I needed in a navigation bar. I found that it is not user friendly and also need more
CSS coding. Besides, it is increasing the processing time and bandwidth in loading a site. In this
tutorial, I will show you how to code the navigation bar using only 1 image. I will not cover the image
creation part because I think you should know how to do that after follow few of my tutorials in the
past. So, start here
The Image
I will not show how to create this but I will let you guys download the psd file as a reference. I
provided 4 types of colors as default, you can edit them according to your preferences. Download
the psd here and I even prepared the slices for you. What you need in building the navigation menu
is only a 493px X 24px image like below.
Before we start, head over and see what we are going to achieve from this tutorial.
Concept
The concept of the sliding door is to use a background image for the buttons in a navigation menu. I
am using a span within a link in the list to hold a part of the image. the link itself will hold another
part of it. Which means, the important part will be the background-image position.
HTML
?
<ul class="blue">
</ul>
Now, I add in a <span> for each of the link to hold the left hand side of the background image.
?
<ul>
</ul>
CSS
1. <ul> Unorder-List
?
ul {
2
padding: 5px;
margin: 10px 0;
list-style: none;
5
6
float: left;
}
7
8
ul li {
float: left;
10
11
12
margin: 0 10px;
}
13
14
ul li a {
15
text-decoration: none;
16
float:left;
17
color: #999;
18
cursor: pointer;
font: 900 14px/22px "Arial", Helvetica, sans-serif;
19
20
21
22
ul li a span {
margin: 0 10px 0 -10px;
23
24
25
26
27
float:left;
}
We need to make list-style as none because no image for any list within it. I use a float left here
because I am going to use float left for the <span> and also <li>. I am not going to define a width
for it because this is just a sample.
4. <Hover> mouse over action
?
color: #0d5f83;
5
6
7
8
Since we are going to have the same effect for the mouse over and active link. I combine the codes.
Here is another example with 4 colors.