Such as the edges around the element of this post, it may be desirable for a website designer to create an element with the same effect with rounded edges all around. This is easy in an element that has a fixed height: one background image for the entire element. It becomes a little more difficult when you don’t know the height of the element though.
The problem is that a background image in CSS2 cannot be stretched and you can’t use two backgrounds for the same element. So to work around this problem we will use two elements. The first DIV will have a bottom padding of 10px. The second DIV will have a top padding of 10px. This will leave room for the two background images we will place in each element. One positioned at the top of the element and the other positioned at the bottom of the element.
The HTML code
<div class="content1"> <div class="content2"> Page content here </div> </div>
The CSS code
.content1 { padding: 0 0 10px; background: #323131 url('/images/corners-bot.png') no-repeat 0% 100%; width: 610px; } .content2 { padding: 10px 0 0; background: #323131 url('/images/corners-top.png') no-repeat 0% 0%; }
I used the CLASS attribute for this example because these elements appear more than once on our blog index page. If the code is guaranteed to be used only once it is recommended to use the ID attribute.
The background line of code is broken down into:
- #323131: the background color of the element
- url(‘/images/corners-top.png’): the URL of the first image we create for the top corners
- no-repeat: specifies that the image will not be tiled
- 0%: the starting position of the background image on the x-axis (left-right)
- 0%: the starting position of the background image on the y-axis (up-down)
Using 0% 100% on the second element background line will position the background at the very bottom of the element.
The only thing left is to create the image. I used Photoshop and it is a fairly straight-forward process.
The Photoshop steps
- Create a new document 15 pixels high and the width of your element wide. In our example, it would be 610px.
- Select the rounded rectangle tool
- Set the radius for the tool to 8px

- Draw a rounded rectangle that starts at the bottom edge of the image and extends far beyond the top of the image.

- Right click on the image and select “Make selection”. Use the default of 0px.

- Click on Select then Inverse. This should create a selection that will be our bottom corners.

- With the primary color block set to your pages background, fill the selection with CMD+DEL (ALT+BACKSPACE on PC).
You can go through the same steps for the top corners. Alternatively, you could press CMD+T (ALT+T on PC), right click and select “Flip Vertical” and move it into position.
post categories
- AJAX (2)
- css (2)
- freelance website design (16)
- graphics (4)
- javascript (4)
- photoshop (1)
- php/mysql (5)
- portfolio (2)
- resources (4)
- site info (2)
- social networking (1)
- tools (1)
- tutorials (8)
Limited time offer
As a limited time offer - thanks to a deal with Host Gator - Wildreason Productions is able to provide a basic 2-3 page webpage with a blog and custom logo for free. All you have to do is host your website at Host Gator as a new customer. Click here to signup or get more information about a free website!February 2012 M T W T F S S « Apr 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Tags
16x16 icon ajax backgrounds convert decimal convert fraction css css layout tutorial decimal to fraction desktop background dynamic width error reporting favicon favicon generator fixed width css fixed width layout fraction common denominator free backgrounds free favicon freelance website design graphics high resolution backgrounds image hover effect image rollover image transition invalid argument supplied foreach javascript javascript image transition liquid layout mootools mootools hover mootools transition effect networking online tool PHP png quote generator quotes resources runtime error simplify fraction social icon social networking tutorial wallpaper website designers



