Categories
CSS

Images overflowing the boundaries of a DIV

A new month brought a new problem. I wanted to set up a staff page for a new site, with a box containing a photo and a profile of the person. The photo was floated to one side of the DIV or the other. I used alternating sides, but that's a matter of taste.

The problem was that if the text profile was too short, the image overflowed the bottom boundary of the div, which had a visible border around it.

Some digging around and experimenting revealed a solution.

The trick is to place <div style="clear:both"></div> just before the end of the DIV to clear the float.

Here's the code I wrote for this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
.silhouette {
  border: 1px solid silver;
  padding:1em;
  margin-bottom:.5em;
}
.silhouette img {
  border: 1px solid lightgrey;
  padding:2px;
  margin-bottom:.5em;
}
.imgleft {
  float:left;
  margin: 0px 10px 10px 0px;
}
.imgright {
  float:right;
  margin: 0px 0px 10px 10px;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<div class="silhouette">
<img src="" class="imgleft" /><p>Duis nec elementum magna. Vivamus malesuada blandit mauris, nec consectetur leo accumsan at. Donec risus enim, porttitor non tristique eu, viverra eu orci. Ut id orci ac elit placerat volutpat. Proin eu nisi ac odio aliquet egestas. Ut vitae justo sed nisi adipiscing suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante.</p>
<div style="clear:both"></div></div>
 
<div class="silhouette">
<img src="" class="imgright" /><p>Proin eu nisi ac odio aliquet egestas. Ut vitae justo sed nisi adipiscing suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante. Duis nec elementum magna. Vivamus malesuada blandit mauris, nec consectetur leo accumsan at. Donec risus enim, porttitor non tristique eu, viverra eu orci. Ut id orci ac elit placerat volutpat. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante. Duis nec elementum magna. Vivamus malesuada blandit mauris, nec consectetur leo accumsan at.  Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante. Duis nec elementum magna. Donec risus enim, porttitor non tristique eu, viverra eu orci.  Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante. Duis nec elementum magna. Ut vitae justo sed nisi adipiscing suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante. </p>
<div style="clear:both"></div></div>
 
<div class="silhouette">
<img src="" class="imgleft" /><p>Vivamus malesuada blandit mauris, nec consectetur leo accumsan at. Duis nec elementum magna. Donec risus enim, porttitor non tristique eu, viverra eu orci. Ut id orci ac elit placerat volutpat. Proin eu nisi ac odio aliquet egestas. Ut vitae justo sed nisi adipiscing suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante.</p>
<div style="clear:both"></div></div>
 
<div class="silhouette">
<img src="" class="imgright" /><p>Ut id orci ac elit placerat volutpat. Proin eu nisi ac odio aliquet egestas. Ut vitae justo sed nisi adipiscing suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante.</p>
<div style="clear:both"></div></div>

And the final result:

Note that the image files are not actually shown.

Duis nec elementum magna. Vivamus malesuada blandit mauris, nec consectetur leo accumsan at. Donec risus enim, porttitor non tristique eu, viverra eu orci. Ut id orci ac elit placerat volutpat. Proin eu nisi ac odio aliquet egestas. Ut vitae justo sed nisi adipiscing suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante.

[ad]

Proin eu nisi ac odio aliquet egestas. Ut vitae justo sed nisi adipiscing suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante. Duis nec elementum magna. Vivamus malesuada blandit mauris, nec consectetur leo accumsan at. Donec risus enim, porttitor non tristique eu, viverra eu orci. Ut id orci ac elit placerat volutpat. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante. Duis nec elementum magna. Vivamus malesuada blandit mauris, nec consectetur leo accumsan at. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante. Duis nec elementum magna. Donec risus enim, porttitor non tristique eu, viverra eu orci. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante. Duis nec elementum magna. Ut vitae justo sed nisi adipiscing suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante.

Vivamus malesuada blandit mauris, nec consectetur leo accumsan at. Duis nec elementum magna. Donec risus enim, porttitor non tristique eu, viverra eu orci. Ut id orci ac elit placerat volutpat. Proin eu nisi ac odio aliquet egestas. Ut vitae justo sed nisi adipiscing suscipit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas augue odio, rutrum bibendum convallis eu, gravida non ante.

Ut id orci ac elit placerat volutpat. Proin eu nisi ac odio aliquet egestas. Ut vitae justo sed nisi adipiscing suscipit.

Categories
Web Development

Getting a website online – for neophytes

You want a website, but haven't a clue how to go about it.  That's OK, everyone who knows how to do it once had to do it for the first time.

Here's a quick guide to getting a website up for very little money, very little work and very quickly.  My solution involves using the free and popular WordPress blogging platform to host your site, and this is a great way to get your first website up and running quickly.

Registering a Domain Name

First, you need to pick a registrar.  That's the company that actually hooks you up with the great registrar of domain names at the heart of the Internet.  Don't worry about the technical details, you really don't need to know unless you want to.  Personally, I don't register my domains where I host my websites.  Too many people lose their domain names in a dispute with a web host when it turns out the web hosting company has control or even technically owns the domain, much to the dismay of the unsuspecting customer.

I use www.easydns.com in to register domains.  It's $20-25/year to register the domain and I've always had good service from them.  If you want to let me have a new affiliate points for pointing you to them use this link to EasyDNS it's your call, I won't beg.

To pick your domain name, go to www.easywhois.com and try out a few names to see if the domain you want is available.  I use that site because they commit to not frontrunning, which is a dirty little trick where a site will offer to do the lookup for you, then slap a 5 day hold on the domain and tell you it's taken, but they can sell it to you – at a price.

When you register your domain name, you'll be asked for the Registrant – that's the legal owner – probably you, as well as Admin, Technical and Billing contacts.  Probably all those people will be you but be sure to keep the info and password in a safe place.  And set a tickler to renew the domain annually.  If you change your email and the reminders don't get to you, you'll lose the domain, which is bad.

Incidentally, you can get a domain registration a little cheaper, but I'm happy to pay an extra $6-7 per year for a registrar who has a good reputation and to avoid registering my domain names where I host my sites.

Setting up your Website

WordPress.com offers two attractive options to host your blog.  If you want to use WordPress to host your site it's free.  But you can also pay them USD$10/year to attach your domain name to their WordPress servers so your domain name is what people go to, not www.wordpress.com.

Either way, you pick one of their WordPress templates.  The template controls the visual appearance of your website.

The downside of using wordpress.com to host your site is that you have to pick one of their templates and there's only minimal customizing possible.  The upside is that they to all the updates automatically – you don't need to worry about maintenance – and it's dirt cheap.

WordPress deals with static content in pages and more chronological content like blogging in posts.  For a resume website you'd want to forget about posts and put up static pages with your resume and contact information.

You can go to WordPress at any time and try them out free.  Join for free and set up http://yourname.wordpress.com.  Experiment with the templates and pick one you like.  There's lots of very good how-to info at http://codex.wordpress.org.  They don't charge for their basic blogging service, but paying the $10 lets you attach your domain name to it, which is a really good idea.

Down the Road

At some point in the future, you can get a hosting plan (roughly $100-$120/year) and use an open source content management system like Joomla to create a more complicated website, but if it's just a resume you'll likely find WordPress all you need and you can't beat the price.

Categories
Graphics

Fading out the edge of a photo in Fireworks

This is a great technique to use when creating banners and header graphics;

http://www.learnwebdesignonline.com/introfireworks/gradient-masking.htm

Categories
MySQL PHP Snippet

Quick and Dirty: List records in a table using PHP and MySQL

This code lists reads a dataset from the database and lists all attributes in a table. 

This code sample is deliberately quite basic, though CSS is used (through the $bgcolour variable) to create alternating background colours for the rows.

The code assumes you have already connected to a database.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
echo "<table border='0'>";
// capture the data
$dataset = mysql_query("SELECT * FROM tablename");
// now process the dataset, one row at a time
while ($row = mysql_fetch_assoc($dataset)) {
  // create a variable for each attribute in the record
  //  - variables are easier to use when building the table 
  foreach($row as $var => $value) {
    $$var = $value;
  }
  // set the alternating background colour for the row
  $bgcolour = (!isset($bgcolour) || $bgcolour == "#F0F7FF") ? "#FFFFFF" : "#F0F7FF";
  // build the rows, placing the variables in <td> elements as appropriate
  echo "\n<tr style="background-color:$bgcolour;">";
  echo "\n<td style="font-size:80%;">$attribute</td>";
  echo "\n</tr>";
} // end while
echo "</table>";
Categories
PHP

Calculating a fiscal year in PHP

This code is a straight cut and paste from a comment the php.net page on the strftime() function, credit is due to lamb dot dan at gmail dot com.

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
30
31
32
<?php
/*
*    This function figures out what fiscal year a specified date is in.
*    $inputDate - the date you wish to find the fiscal year for. (12/4/08)
*    $fyStartDate - the month and day your fiscal year starts. (7/1)
*    $fyEndDate - the month and day your fiscal year ends. (6/30)
*    $fy - returns the correct fiscal year
*/
function calculateFiscalYearForDate($inputDate, $fyStart, $fyEnd){
    $date = strtotime($inputDate);
    $inputyear = strftime('%Y',$date);
 
    $fystartdate = strtotime($fyStart.$inputyear);
    $fyenddate = strtotime($fyEnd.$inputyear);
 
    if($date < $fyenddate){
        $fy = intval($inputyear);
    }else{
        $fy = intval(intval($inputyear) + 1);
    }
 
    return $fy;
 
}
 
// my fiscal year starts on July,1 and ends on June 30, so...
echo calculateFiscalYearForDate("5/15/08","7/1","6/30");
// returns 2008
 
echo calculateFiscalYearForDate("12/1/08","7/1","6/30");
// returns 2009
?>