Creating rounded corners

From Joomla! Documentation
(Difference between revisions)
Jump to: navigation, search
(Putting it into practice)
(Putting it into practice - creating the images)
Line 23: Line 23:
 
We will use Inkscape to create a simple rounded box with a pink foreground and a white background, and a drop shadow at the lower right corner.  This is the same box as shown in the animation above.
 
We will use Inkscape to create a simple rounded box with a pink foreground and a white background, and a drop shadow at the lower right corner.  This is the same box as shown in the animation above.
  
# To begin, we need to decide what maximum size we want for our box.  As stated above, this will determine the size of image we need to use.  Since a larger image will have a greater file size, and hence cause a website to load more slowly, there is no point making the image any bigger than is necessary.  For the purposes of this example, we will use a maximum size of 800px wide by 600px high.  We therefore create a new image in Inkscape having these dimensions.
+
# [[Image:New inkscape image 800x600.png|thumb|200px|Create a new Inkscape image]]To begin, we need to decide what maximum size we want for our box.  As stated above, this will determine the size of image we need to use.  Since a larger image will have a greater file size, and hence cause a website to load more slowly, there is no point making the image any bigger than is necessary.  For the purposes of this example, we will use a maximum size of 800px wide by 600px high.  We therefore create a new image in Inkscape having these dimensions.<div style="clear:both"></div>
 +
# [[Image:Inkscape create rounded rectangle.png|thumb|200px|Draw a rounded rectangle]]We will leave a 5px margin around our image.  In addition, we will need 5px width of shadow on the right-hand and bottom edges of our rounded box.  We therefore need to draw a rounded rectangle with a width of 785px and a height of 585px.  We will also give the rounded corners a 5px radius. To do this, select the rectangle tool from the toolbar at the left, and left-click-drag anywhere within the blank document.  The exact size of rectangle you draw doesn't matter at this stage.  Then go to the options toolbar and enter the following settings: W:783.00 H:583.00 Rx:5.000 Ry:5.000 px.  Why the difference in sizes?  These dimensions don't include the width of the border.  We are going to give our rectangle a 2px border, which will therefore increase each dimension by 2px.<div style="clear:both"></div>
 +
# [[Image:Inkscape set border width.png|thumb|150px|Set the border width]][[Image:Inkscape set fill colour.png|thumb|150px|Set the fill colour]]Next, we need to adjust that border, and set the colour of our rectangle.  With the rectangle selected, go to Object > Fill and Stroke on the menu bar, or press Shift + Ctrl + F, to bring up the Fill and Stroke dialogue.  Under the 'Fill' tab, choose the colour of the foreground fill.  We are going to use the hex colour #ffe7db, so enter 'ffe7dbff' in the RGBA input.  (The final 'ff' hex value sets the alpha transparency level for the fill - in our case, completely opaque).  Under the 'Stroke paint' tab we set the border colour.  In our case, we want a black border, so we can leave the RGBA input at the default value of 000000ff.  Finally, under the 'stroke style' tab, we set the stroke (border) width to be 2.000px.<div style="clear:both"></div>
 +
# [[Image:Inkscape set position.png|thumb|200px|Set the position of the rectangle]]We now have a rectangle, but it is not in the correct location.  Inkscape measures positions from the lower left corner of the document,, so we need to place our rectangle at x=5 and y=10.  Choose the selection tool from the toolbar at the left, left-click anywhere inside the rounded rectangle, and enter the position values in the options toolbar.<div style="clear:both"></div>
 +
# Next, we create a new layer to hold the drop shadow.  Go to Layer > Add Layer... on the menu bar, and create a new layer named 'Shadow' below the current layer.  Then select the upper layer (by default called 'Layer 1') from the box at the bottom of the screen, and click the eye icon just to the left to hide this layer and the rounded box we created above.  Select the 'shadow' layer again and create another rounded box.  Make this one 785px wide, 585px high, with corner radii of 5px, and located at x=10 and y=5.  In the 'Fill and Stroke dialogue, set the fill RGBA to '00000081', and the blur slider to '0.6'.  On the 'stroke paint' tab, select the 'no paint' icon.
 +
# Finally, unhide Layer 1.  Congratulations - you can now see how your rounded box will look!
 
[[Category:Templates]]
 
[[Category:Templates]]

Revision as of 18:50, 2 March 2008

Introduction


This chunk should take the reader through a step-by-step procedure for creating the corner images using a selected open source image editor (eg. The Gimp), placing the image files in the correct location in the template directory and amending the template file to use the "rounded" module style. It should be illustrated by suitably annotated screenshots.


The theory

In order to avoid the problems described above, we use separate images to provide the four corners of our rounded box. In order to ensure that the border of our rounded box is always continuous, these images need to be big enough to completely fill our container at the maximum permissible size. To provide our rounded box at sizes below this maximum, we place the images into four layers, overlapping one another, to create the illusion that the border of our rounded box is unbroken.

Rounded corners
The process is illustrated by the animation shown on the right. At each stage, an image is applied on top of the last.
  1. Firstly, a large image containing the left-hand and top borders, and the top-left rounded corner, is placed at the top left corner of our container <div> (outlined in red for clarity). The image is bigger than required for this container, and so extends beyond the bottom and right-hand edges; this is shown in partial transparency in the animation to illustrate the process, but would not be seen in practice.
  2. Next, a thin horizontal image containing the bottom border and lower-left rounded corner is placed at the bottom left corner of the the container <div>, on top of the first image. This image has been given a thin border in a darker pink to illustrate the process; this border would not normally be used. Again, it can be seen that the image extends beyond the right-hand edge of the container.
  3. Thirdly, a thin vertical image containing the right-hand border and top-right rounded corner is placed at the top right corner of the container, on top of the second image.
  4. Finally, a square image containing just the lower-right rounded corner is placed at the lower-right corner of the container.

Putting it into practice - creating the images

To create the images we need, we will use the open source vector drawing program Inkscape. Unlike raster drawing software (such as the GIMP), which deals in individual pixels, vector drawing software works with geometric shapes. This makes it much easier to create rounded corners having exactly the geometry we want.

We will use Inkscape to create a simple rounded box with a pink foreground and a white background, and a drop shadow at the lower right corner. This is the same box as shown in the animation above.

  1. Create a new Inkscape image
    To begin, we need to decide what maximum size we want for our box. As stated above, this will determine the size of image we need to use. Since a larger image will have a greater file size, and hence cause a website to load more slowly, there is no point making the image any bigger than is necessary. For the purposes of this example, we will use a maximum size of 800px wide by 600px high. We therefore create a new image in Inkscape having these dimensions.
  2. Draw a rounded rectangle
    We will leave a 5px margin around our image. In addition, we will need 5px width of shadow on the right-hand and bottom edges of our rounded box. We therefore need to draw a rounded rectangle with a width of 785px and a height of 585px. We will also give the rounded corners a 5px radius. To do this, select the rectangle tool from the toolbar at the left, and left-click-drag anywhere within the blank document. The exact size of rectangle you draw doesn't matter at this stage. Then go to the options toolbar and enter the following settings: W:783.00 H:583.00 Rx:5.000 Ry:5.000 px. Why the difference in sizes? These dimensions don't include the width of the border. We are going to give our rectangle a 2px border, which will therefore increase each dimension by 2px.
  3. Set the border width
    Set the fill colour
    Next, we need to adjust that border, and set the colour of our rectangle. With the rectangle selected, go to Object > Fill and Stroke on the menu bar, or press Shift + Ctrl + F, to bring up the Fill and Stroke dialogue. Under the 'Fill' tab, choose the colour of the foreground fill. We are going to use the hex colour #ffe7db, so enter 'ffe7dbff' in the RGBA input. (The final 'ff' hex value sets the alpha transparency level for the fill - in our case, completely opaque). Under the 'Stroke paint' tab we set the border colour. In our case, we want a black border, so we can leave the RGBA input at the default value of 000000ff. Finally, under the 'stroke style' tab, we set the stroke (border) width to be 2.000px.
  4. Set the position of the rectangle
    We now have a rectangle, but it is not in the correct location. Inkscape measures positions from the lower left corner of the document,, so we need to place our rectangle at x=5 and y=10. Choose the selection tool from the toolbar at the left, left-click anywhere inside the rounded rectangle, and enter the position values in the options toolbar.
  5. Next, we create a new layer to hold the drop shadow. Go to Layer > Add Layer... on the menu bar, and create a new layer named 'Shadow' below the current layer. Then select the upper layer (by default called 'Layer 1') from the box at the bottom of the screen, and click the eye icon just to the left to hide this layer and the rounded box we created above. Select the 'shadow' layer again and create another rounded box. Make this one 785px wide, 585px high, with corner radii of 5px, and located at x=10 and y=5. In the 'Fill and Stroke dialogue, set the fill RGBA to '00000081', and the blur slider to '0.6'. On the 'stroke paint' tab, select the 'no paint' icon.
  6. Finally, unhide Layer 1. Congratulations - you can now see how your rounded box will look!
Personal tools
Namespaces

Variants
Actions
Navigation
Joomla! Sites
Toolbox