04.06.2013 Views

Head First HTML with CSS

Head First HTML with CSS

Head First HTML with CSS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Putting the coupon on the page<br />

Add the new coupon rules to your “starbuzz.css” file,<br />

save, and then reload the page. You may need to make<br />

the browser smaller to be able to see that the coupon<br />

stays put even when you scroll. Clicking on the coupon<br />

should take you to the “freecoffee.html” page.<br />

You know, this looks great, but it might just be even more<br />

snazzy if the coupon was offset to the left, so it looks like<br />

it’s coming out of the side of the viewport. Now, we could<br />

get into our photo editing software and cut off the left<br />

hand side of the image to create that effect. Or, we could<br />

just use a negative offset so that the left side of the image<br />

is positioned to the left of the edge of the viewport.<br />

That’s right, you can do that.<br />

Using a negative left property value<br />

Specify a negative property value just like you do a positive one:<br />

just put a minus sign in front. Like this:<br />

#coupon {<br />

position: fixed;<br />

top: 300px;<br />

left: -90px;<br />

}<br />

By specifying -90 pixels,<br />

we’re telling the browser to<br />

position the image 90 pixels<br />

to the left of the edge of<br />

the viewport.<br />

The browser will gladly position the<br />

image to the left of the viewport<br />

for you, and only the part of the<br />

image that is still on the screen<br />

will be viewable.<br />

-90<br />

pixels<br />

div id=“coupon”<br />

300 pixels<br />

layout and positioning<br />

you are here 537

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!