One of the main reasons why designers use images on a Web page is to create curves and round corners. It's currently impossible to create any kind of curved shapes using pure HTML, so images need to be applied.
The problem? Putting these images into an HTML document with a table layout can create a large amount of superfluous code. In this tutorial, we'll use CSS to create this box with round corners, without an tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvaW1n">
tag in sight!
How it Works
The above is basically a normal box that has an orange background colour, over which four corner images are superimposed. All these images have been called up through CSS commands.
So, we start off with the following snippet:
We've used 1465_1bl (click to view image) We'll use the above image, called bl.gif, which we'll place in the bottom-left corner with the following CSS command: The CSS background command is broken into three sections: the image URL, its position, and a repeat command. We also inserted a width CSS command so that the box doesn't cover the whole of the screen. Let's examine the three background commands in turn: It doesn't matter in which order these three CSS background commands are placed. Our box with curves now looks like this. Next, we'll stick in that bottom-right curve. As previously mentioned, we can only assign one background image to each Here's the image we'll use: 1465_1br (click to view image) Naming this bottom-right image br.gif, we'll insert a new CSS rule: This CSS rule is essentially the same as the last one, although now we've changed the position from the left to 100%, where previously it was 0%. The box now looks like this. To make our top curves, we'll need two new images: 1465_1tl (click to view image) 1465_1tr (click to view image) We'll call these tl.gif and tr.gif. We'll need to create two new The new CSS rules are as follows: These give us this display. We'll now insert our orange background colour into the box, in order to achieve the whole round corners effects. By default, a background colour covers the entire As before, it doesn't matter where we place this colour command within the CSS background rule. Our box now looks like this. Padding is needed to prevent the text from overlapping on to the images, which are 10px x 10px in size. Therefore, we need 10px-worth of padding on the text. But to which Whichever element we assign padding to, each of the elements inside it will inherit that padding. If we were to assign padding to the very first To get this padding to work properly, we need to assign it to the very last You may have noticed the bottom corners were called up before the top corners. If we were to do things the other way round, that is, call the top corners first, some parts of the orange background colour would sneak out under the bottom curves, causing a rather unsightly effect. Switch the order of the Another issue in Internet Explorer is that the background colour of the box sometimes overlaps on to the element below, again causing an unattractive effect. This can be solved simply by placing a tiny placeholder beneath the box with round corners. Immediately after the fourth closing Now, assign it this CSS rule: Our finished HTML now looks like this: Here's the CSS that makes it all happen:class="bl"
as we're going to assign our bottom right corner to this tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
.bl {background: url(bl.gif) 0 100% no-repeat; width: 20em}
0 100%
in our CSS rule. The first number represents the distance from the left edge of the %
was used, but a different distance value, such as em or px, could just as easily have been used instead. If this command was left out, the default value, 0 0
, would be used, and the image would be placed in the top-left corner.no-repeat
CSS command. If we wanted to, we could have used repeat-x
, to repeat the image horizontally, repeat-y
, to repeat it vertically, and repeat
to repeat it both horizontally and vertically. If this command was left out, the default value, repeat
, would be used. Bottom-Right Curve
tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
Lorem ipsum dolor sit amet consectetur adipisicing elit.br {background: url(br.gif) 100% 100% no-repeat}
Top Curves
tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
Lorem ipsum dolor sit amet consectetur adipisicing elit.tl {background: url(tl.gif) 0 0 no-repeat}
.tr {background: url(tr.gif) 100% 0 no-repeat}Background Colour
The background colour must always be assigned to the very first CSS rule. This is because each CSS background rule is essentially a layer on top of the previous one. So, in this example, we have a layering order of br.gif, bl.gif, tl.gif and then tr.gif. But, in this example, the images don't overlap, so we don't really notice this layering effect. tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
.bl {background: url(bl.gif) 0 100% no-repeat #e68200; width: 20em}
Padding
tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
.tr {background: url(tr.gif) 100% 0 no-repeat; padding:10px}
Internet Explorer Issues
tag in the SitePoint HTML Reference." href="http://c-lien.blogspot.com/?aHR0cDovL3JlZmVyZW5jZS5zaXRlcG9pbnQuY29tL2h0bWwvZGl2">
, insert the following HTML:.clear {font-size: 1px; height: 1px}
The Final Code
Lorem ipsum dolor sit amet consectetur adipisicing elit.bl {background: url(bl.gif) 0 100% no-repeat #e68200; width: 20em}
.br {background: url(br.gif) 100% 100% no-repeat}
.tl {background: url(tl.gif) 0 0 no-repeat}
.tr {background: url(tr.gif) 100% 0 no-repeat; padding:10px}
.clear {font-size: 1px; height: 1px}
Aucun commentaire:
Enregistrer un commentaire