top left corner image top right corner image

Latest Articles

Photoshop Tutorial: Elegant Newsbox

Today we're going to build an interactive news box. Courtnie will show you how to code the box, and Roger will show you how to use the scripts to make it shrink and grow when the article is clicked on.

To get started draw yourself a rectangle using the rectangle shape tool - it doesn't matter what the color is. Double click the new shape layer and click on gradient overlay. Click on the gradient bar shown in the window and then on the left color swatch underneath the gradient in the new window - set this to f3f3f3 click on the swatch at the other end of the gradient and set it to ffffff. Now drag the grey color swatch toward the white one till there is only a little white at the top of the box. Now click on stroke, click on the color swatch, and enter the color value e0e0e0; set the stroke size to 1 and the position to inside, then hit OK.

Now draw a second, slightly smaller rectangle inside the first, but make it a bit shorter so that there is room for our Latest Tutorials bar above it. Click on the color swatch of this new shape layer and set it to ffffff. Apply the exact same stroke settings as before to this new layer. Make sure this layer is above the first one and line it up over the other rectangle and ensure that you have an even border on the left, right, and bottom.

Now for the Latest Tutorials Bar. Select the rounded corner shape tool from the shape drop downs on your toolbar and draw a long thin rounded rectangle above the white box. Apply the same gradient settings to this bar but reverse them so that the grey is at the top and the white is at the bottom.

There's your news box... now Courtnie is going to show you how to code this box using HTML and CSS.

Coding your Newsbox in HTML and CSS

Before we begin to code our Newsbox we need to cut the image into smaller pieces. This is so the box can grow to any size without having to make new images every time.

I have cut Andrea's box into seven small pieces:

Top left corner
Top right corner
Top background
Side background
Bottom left corner
Bottom right corner
Bottom background

The images should not be very big. Just crop the corners out as close as you can. As for the backgrounds, the side background only needs to be one pixel in height while the top and bottom backgrounds need to be 1 pixel in width.

Here is the markup for your Newsbox it will be repeated below in Roger's article with the added functionality:

<div style="width: 460px; padding: 0; margin: 0;">
<div style="background: url(top-bg.gif) repeat-x; width: 430px; height: 25px;">
<img src="top-left.gif" alt="top left corner image" style="float: left; width: 15px; height: 25px;">
<img src="top-right.gif" alt="top right corner image" style="float: right; width: 15px; height: 25px;">
<p style="font: bold 15px arial, sans-serif; color: #828282; padding: 4px 0 0 20px; margin: 0;">Latest Tutorials</p>
<div style="clear: both; line-height: 0;"></div>
</div>

<div style="width: 430px; background: url(side-bg.gif) top left repeat-y; padding: 0; margin: 0;">
<div style="background: url(side-bg.gif) top right repeat-y; padding: 10px 20px;">

<!-- ROGER'S CODE WILL APPEAR HERE -->

</div>
</div>

<div style="background: url(bottom-bg.gif) repeat-x; width: 430px; height: 5px;">
<img src="bottom-left.gif" alt="bottom left corner image" style="float: left; width: 6px; height: 5px;">
<img src="bottom-right.gif" alt="bottom right corner image" style="float: right; width: 6px; height: 5px;">
<div style="clear: both; line-height: 0;"></div>
</div>

</div>

Roger will now show you how to make your Newsbox work!

Adding functionality to your Newsbox

Let's take the cool Newsbox that Andrea designed and Courtnie coded and apply some functionality to the news items. We will make it so that the news titles are clickable title bars that will expand and collapse your full news content.

First, we will need you to download the following javascript package containing 3 javascript libraries:

Download Newsbox Library (newsbox.js, prototype.js and effects.js)

After you have downloaded this library, extract the contents to the same folder that your html document is in.

The HTML <HEAD>
Paste the following code into the HEAD of your HTML Document.

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="effects.js"></script>
<script type="text/javascript" src="newsbox.js"></script>
<style type="text/css">
.newsContent { padding: 10px; margin: 0px; }
.newsItem { padding: 0px; margin: 0px; }
.newsItem a, .newsItem a:visited { display: block; text-decoration: underline; cursor: pointer!important; cursor: hand; padding: 3px; }
</style>

The Newsbox Template
Now, Here is the code provided by Courtnie along with the functionality I have added.

<div style="width: 460px; padding: 0; margin: 0;">
<div style="background: url(top-bg.gif) repeat-x; width: 430px; height: 25px;">
<img src="top-left.gif" alt="top left corner image" style="float: left; width: 15px; height: 25px;">
<img src="top-right.gif" alt="top right corner image" style="float: right; width: 15px; height: 25px;">
<p style="font: bold 15px arial, sans-serif; color: #828282; padding: 4px 0 0 20px; margin: 0;">Latest Tutorials</p>
<div style="clear: both; line-height: 0;"></div>
</div>

<div style="width: 430px; background: url(side-bg.gif) top left repeat-y; padding: 0; margin: 0;">
<div style="background: url(side-bg.gif) top right repeat-y; padding: 10px 20px;">

<!-- ROGER'S NEWSBOX CODE STARTS HERE -->
<div id="newsBox">

<!-- NEWS ITEMS GO HERE -->

</div>
<!-- ROGER'S CODE ENDS HERE-->

</div>
</div>

<div style="background: url(bottom-bg.gif) repeat-x; width: 430px; height: 5px;">
<img src="bottom-left.gif" alt="bottom left corner image" style="float: left; width: 6px; height: 5px;">
<img src="bottom-right.gif" alt="bottom right corner image" style="float: right; width: 6px; height: 5px;">
<div style="clear: both; line-height: 0;"></div>
</div>

</div>

The Newsbox Item
The following code will present your news item within the newsbox. Copy and paste this code as many times as you have articles below the comment 'NEWS ITEMS GO HERE'.

<div class="newsItem">
<a class="newsTitle">ARTICLE TITLE GOES HERE!</a>
<div style="display:none;">
<div class="newsContent">
  PUT THE HTML FOR YOUR ARTICLE CONTENT HERE
</div>
</div>
</div>

The Newsbox Library

Lastly, in order to get your newsbox collapsing and expanding, you will need to include the following just before the closing BODY tag.

<script type="text/javascript">newsBox = new newsBox({'bg':'#f7f7f7','fg':'#000000','link':'#0000cc','altbg':'#ffffff','altfg':'#000000'
,'altlink':'#0000cc'});</script>

In the above code, there are several settings available for background color, font color, and link color. The first 3 settings (bg,fg,link) affect the odd rows and the last 3 settings (altbg,altfg,altlink) affect the even or alternating rows.

Just enter in new RGB hexadecimal codes to modify the look and feel of your Newsbox. That's it! Happy Coding!

Download all of the files from this tutorial for a fully functional Newsbox! »
(newsbox.js, prototype.js, effects.js, newsbox.html, and all images)

bottom left corner image bottom right corner image