Self-Imposed CSS Refresher Training

RJM62

Touchdown! Greaser!
Joined
Jun 15, 2007
Messages
13,157
Location
Upstate New York
Display Name

Display name:
Geek on the Hill
Self-Imposed CSS and PHP Refresher Training

Like most people in my business, I've accumulated quite a stockpile of code that I routinely copy, paste, and tweak into new sites. I have a lull in the action at the moment because I just finished a major rewrite of an old client's site (he'd fired me a long time ago, but recently came back), so I decided to build myself a new site completely from scratch, as it were, completely hand-coding it and not using any recycled stuff.

I also decided that I didn't want to use any JavaScript. I used to fix computers, and I found that computers that are malware-infected, have overly-aggressive antivirus or ad-blocking software, or simply aren't feeling well can do strange things to JS-dependent pages. So I prefer not using JS unless I have to.

I decided to build a site where I can give away less-than-wonderful stock photos I've taken (ones that were rejected by the stock photo companies I deal with, and ones that I didn't bother to submit because I knew they'd be rejected), and hope that people click on an ad or two while they're perusing my leftovers.

I'm still working on the code, but I have a mocked-up version of one page online. I'd appreciate comments on the effect that occurs when an image in the gallery is hovered. You can also play with the cart and zip download function if you like, although I'm still tweaking those.

What should happen is that the thumbnail image increases in size and shifts up slightly, and then the image and the accompanying text obscures adjacent images.

I already know that the effect WILL NOT WORK on IE < 10 (the image will resize and the text will obscure the adjacent images, but there will not be a timed transition), and I haven't tested it on mobile browsers because there's no real hover function. I'm pondering different ways to implement it on a future mobile version.

It seems to work well on Firefox and decently on Chrome and Safari. I haven't gotten around to testing it on Opera yet. That'll be later after I run a few errands.

Here's the mocked-up page:

http://www.rjmstock.com/free_stock_photos_railroad.php

The PHP that generates the gallery is:

PHP:
$query="SELECT * FROM stock WHERE page='$page'";
$result=mysql_query($query);

$num = mysql_numrows($result);
$i=0;
while ($i < $num) {
    $filename = mysql_result($result,$i,"file_name");
    $thumb = "Images/stock/thumbs/" . $filename . ".jpg";
    $full_size = "Images/stock/" . $filename . ".jpg";
    $picinfo = getimagesize($full_size);
    $pic_width  = $picinfo [0];
    $pic_height  = $picinfo [1];
    $alt = mysql_result($result,$i,"alt");
    $title = mysql_result($result,$i,"title");
    $caption = $title;
    echo "<li class='cover'><img src=\"" . $thumb . "\" alt=\"" . $alt . "\" border=\"0\">" . PHP_EOL;
    echo "<div id='gallery_text'><p>" . $caption . "</p>\n<p><a href='add_to_cart.php?file=" . $full_size . "'>Add " . $pic_width . " x " . $pic_height . " File to Cart</a></p></div></li>". PHP_EOL;    
    $i++;
}
The relevant CSS is:

Code:
#gallery {
    position: relative;
    display: inline-block;
    margin-left: 0;
    margin-top: 10px;
    padding-top: 20px;
    padding-bottom: 50px;
    background: #080808;
    width:690px;
    min-height: 200px;
    font-size: 10px;
    border: #101010 1px solid;
    border-radius: 10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    -o-border-radius: 10px;
}

#gallery a { color: #06F; text-decoration: none; }

#gallery a:hover { text-decoration: underline }

#gallery ul { background: #080808; }

#gallery li {
    display: inline;
    position: relative;
    clear:none;
    float: left;
    width: 180px;
    padding-right: 10px;
    height: 200px;
    text-align: left;
    z-index: 0;
    background: #080808;
}

#gallery li:hover { z-index: 3 }

#gallery_text {
    background-color: #080808;
    display: inline-block;
    z-index: 10;
    padding: 2px;
}

#gallery img {
    margin-top: 0;
    margin-left: 0;
    border: #000 2px solid;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -o-border-radius: 5px;
    width: 125px;
    z-index: 1;
    position: relative;
    transition: width 250ms linear, margin-top 250ms linear;
    -moz-transition: width 250ms linear, margin-top 250ms linear;
    -webkit-transition: width 250ms linear, margin-top 250ms linear;
    -o-transition: width 250ms linear, margin-top 250ms linear;
    -ms-transition: width 250ms linear, margin-top 250ms linear;
}

.cover {
    transition-property: z-index;
    transition-duration: 250ms;
    transition-delay: 25ms;
    transition-timing-function: linear;
    -moz-transition-property: z-index;
    -moz-transition-duration: 250ms;
    -moz-transition-delay: 25ms;
    -moz-transition-timing-function: linear;
    -webkit-transition-property: z-index;
    -webkit-transition-duration: 250ms;
    -webkit-transition-delay: 25ms;
    -webkit-transition-timing-function: linear;
    -o-transition-property: z-index;
    -o-transition-duration: 250ms;
    -o-transition-delay: 25ms;
    -o-transition-timing-function: linear;
}

#gallery img:hover {
    margin-top: -20px;
    border: #000 2px solid;
    position: relative;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -o-border-radius: 5px;
    height: auto;
    width: 250px;
}
The CSS, especially, will need a lot of tightening up. For example, for whatever reason, using the shorthand for the .cover class doesn't seem to work, and I'm also pretty sure that there are some unnecessary values in there from my playing around.

Comments appreciated.

Thanks.

-Rich
 
Last edited:
By the way -- on the final version, I plan on planting the cart on the bottom of every page, right under the gallery, and refreshing back to the sending page after items are added.

But I have to work out a few conflicts with the session variables because putting the cart on the bottom of the gallery pages wasn't the plan I had in mind when I coded the cart. Easy stuff to fix, but I wanted to get the effects working right first.

-Rich
 
Looks very nice Rich. CSS is something I wish I had the time to really dig into. Well I suppose I have the time, it's just using it more wisely. ;)
 
I set the opacity of the text background to 80 percent. I think that's a little more visually interesting.

-Rich
 
Very nice looking Rich. I really like the effect! Have you experimented w/ JQuery? I switched from using CSS to handle things like this to using JQuery and it's made it a lot quicker to code (and more reliable across different browsers).

Not a criticism, just a question! But hey, especially in webdev, "If it ain't broke, dont fix it" really applies. Good looking work!
 
Very nice looking Rich. I really like the effect! Have you experimented w/ JQuery? I switched from using CSS to handle things like this to using JQuery and it's made it a lot quicker to code (and more reliable across different browsers).

Not a criticism, just a question! But hey, especially in webdev, "If it ain't broke, dont fix it" really applies. Good looking work!

Thanks. I appreciate that.

I've used jQuery a bit and plan to use it more. But to an extent it would have defeated the purpose of this project, which was more to brush up on my basic CSS and PHP skills than to actually get the site going.

It kind of struck me that I needed brushing up when I was doing a rebuild for a returning client, and I couldn't find a PHP script I wanted to use; so I decided to re-code it, and I kept making all kinds of idiotic mistakes.

As for the CSS part, design has always been my weakest skill. I used to have a partner who was a true artist on the design end, and I relied on his talent. When he passed away, I struggled with it; and I'm just now getting to the point where I'm starting to feel competent at the design aspect of the job.

I'm a bit late getting around to that: I'm semi-retired now. Better late than never, though.

Thanks again.

-Rich
 
Thanks. I appreciate that.

I've used jQuery a bit and plan to use it more. But to an extent it would have defeated the purpose of this project, which was more to brush up on my basic CSS and PHP skills than to actually get the site going.

It kind of struck me that I needed brushing up when I was doing a rebuild for a returning client, and I couldn't find a PHP script I wanted to use; so I decided to re-code it, and I kept making all kinds of idiotic mistakes.

As for the CSS part, design has always been my weakest skill. I used to have a partner who was a true artist on the design end, and I relied on his talent. When he passed away, I struggled with it; and I'm just now getting to the point where I'm starting to feel competent at the design aspect of the job.

I'm a bit late getting around to that: I'm semi-retired now. Better late than never, though.

Thanks again.

-Rich

Haha trust me, I understand being design-edly challenged :)
 
I think I have most of the bugs well-stomped. They were mainly path errors caused by changes I made since I started the site. It's rendering the way I want it to now, and all of the functions seem to be working.

Some things I changed:

1. Border colors on the images.
2. Added placeholder code for future banner ads.
3. Put the cart on the bottom of the gallery page, once items are selected.
4. Added a link to a dedicated cart page on the left.
5. Styled the function pages like the rest of the site, and added a cheesy progress indicator.
6. Built the contact form and the spam-filtering script.
7. Changed the font.

http://www.rjmstock.com/free_stock_photos_railroad.php

If you're really bored, please try to add and remove some pictures to the cart, empty it, download some pictures, whatever, and let me know if you come across any errors or weirdness that I missed. It all seems to be working for me...

Thanks,

Rich
 
Last edited:
Touché sir, touché.

I like CSS, have no problems with it. Combined with javascript, it's pretty neat stuff. Though I prefer to stay away from web development these days. A graphics guy can hand me an image mock up of a site and I can program it in a couple of hours with nice, neat CSS. My problem is, making that image file. Most of my original designs end up like this.

http://www.timecube.com/
 
I like CSS, have no problems with it. Combined with javascript, it's pretty neat stuff. Though I prefer to stay away from web development these days. A graphics guy can hand me an image mock up of a site and I can program it in a couple of hours with nice, neat CSS. My problem is, making that image file. Most of my original designs end up like this.

http://www.timecube.com/

Yikes!

Since Steve passed away, I've been forced to develop a more artistic eye. But doing the stock photography helped a lot, too. I learned a lot from the people on the various stock photo boards.

Learning to use about 10 percent of Photoshop's capabilities and about 25 percent of Fireworks' has helped immeasurably, too. Those programs are amazing.

-Rich
 
Yikes!

Since Steve passed away, I've been forced to develop a more artistic eye. But doing the stock photography helped a lot, too. I learned a lot from the people on the various stock photo boards.

Learning to use about 10 percent of Photoshop's capabilities and about 25 percent of Fireworks' has helped immeasurably, too. Those programs are amazing.

-Rich
'
All I know how to do with Fireworks is use the Slice tool :D

I do mess around with GIMP, but mostly for making backgrounds transparent, creating icons etc.. never mocking up a site. Luckily, these days I have a marketing department with graphic designers on hand, I send them the markup, they send it back all pretty and compliant.
 
Well, I've been too busy to edit all the files I want to upload and create all the different category pages I wanted to have, so I decided to make the site live with what I have ready. I rather like how it came out:

http://www.rjmstock.com/

I'll add the ads in a couple of days.

-Rich

EDIT: I added the ads. Please don't click them.
 
Last edited:
Well, I've been too busy to edit all the files I want to upload and create all the different category pages I wanted to have, so I decided to make the site live with what I have ready. I rather like how it came out:

http://www.rjmstock.com/

I'll add the ads in a couple of days.

-Rich

I like the dead bugs on the zapper photo?

Might I make one small suggestion? I had to add to cart, download a zip file, unzip it then open in an image viewer just to see the picture. Adding a lightbox type script to get a medium photo instead of just a tumbnail would have helped usability. I do like the cart to zip file feature, but some places who might find the photos useful have corporate firewalls that insta-reject zip files, so maybe a direct link to the image? Ok maybe that was 2 unsolicited suggestions... :D
 
I like the dead bugs on the zapper photo?

Might I make one small suggestion? I had to add to cart, download a zip file, unzip it then open in an image viewer just to see the picture. Adding a lightbox type script to get a medium photo instead of just a tumbnail would have helped usability. I do like the cart to zip file feature, but some places who might find the photos useful have corporate firewalls that insta-reject zip files, so maybe a direct link to the image? Ok maybe that was 2 unsolicited suggestions... :D

Thanks Bart. I think both are good ideas.

I'm going to try to come up with a pure-CSS lightbox, although I'm not sure how realistic that is unless I want to preload all the images and do it on a hover, or something like that. I'll probably wind up using CSS and JS.

-Rich
 
Might I make one small suggestion? I had to add to cart, download a zip file, unzip it then open in an image viewer just to see the picture. Adding a lightbox type script to get a medium photo instead of just a tumbnail would have helped usability. I do like the cart to zip file feature, but some places who might find the photos useful have corporate firewalls that insta-reject zip files, so maybe a direct link to the image? Ok maybe that was 2 unsolicited suggestions... :D

I did succeed in building a pure-CSS lightbox, but it required that I preload all the images -- quite a waste of bandwidth to avoid a bit of JS.

Once I resigned myself to using JS for the lightbox, I just used Orangoo's greybox script. It's a polite little piece of JS that has never misbehaved, in my experience, and it's better than anything I likely would have come up.

So that's been implemented. I left my CSS thumbnail resizing effect in place, as well; so hovering doubles the size of the thumbnail, and clicking the thumbnail opens a watermarked, 600px width image.

http://www.rjmstock.com/ (Please don't click any ads.)

Now as far as the direct links...

This is an ad-monetized site. I'm giving the pictures away, but I want people to at least see the ads. So I want the only way to get the 1024px pictures to be via the site. I also don't want the 1024px pictures available through Google (or any other) image search.

I think the best way to accomplish both objectives while still allowing a non-zip download would be to deny access to the directory containing the 1024px images to all except localhost, and then have the "direct" links actually call a little PHP script, which in turn would grab the individual image. Bypassing the script would 403 the request.

I also could have the server email the files as attachments if a user doesn't want the ZIP... but that would be really obnoxious. I'll probably go with the php script grabbing the image.

-Rich
 
Last edited:
As a satisfying little bit of irony...

All three of the anal-retentive stock companies I deal with advertise through Adsense, and all of their ads have been appearing on my site. I may just wind up making more money on the pictures that they reject than the ones that they accept. :tongue:
 
Back
Top