How to: Anchor the Footer to Bottom of Page (or Header to Top)!

0 comments

Posted on 29th May 2011 by Lindsey in internet |Uncategorized

, anchor footer, , , , , , , , , , , Fixed Footer, fixed footer css, Fixed Header, , , how-to, , , , , , , , , , , , , , , static footer, static header, Templates, , , , , , , , ,

Yesterday I discussed another method of creating a full width header and footer while still keeping your interior content centered. I’m going to expand on this method, and show you how to take the full width footer you’ve created and … Continue reading

How to: Create Full (100%) Width Header/Footer with Centered Content (Updated)

0 comments

Posted on 28th May 2011 by Lindsey in internet |Uncategorized

, , , , , center content full width, , , , , , , full width footer, full width header, , , how-to, , , , , , , , , , , , , , , , , , , , , , , , ,

I originally wrote a tutorial on how to “Create Full Width Header & Footer With Centered Content Using CSS” almost three years ago (yipe!) when I was working on one of the many redesigns of my site. Looking back on … Continue reading

How do you code?

Comments Off

Posted on 23rd February 2009 by Lindsey in internet |Uncategorized

, , , , , , Coding, , , , , , , , , , , , markup, , , , , , , , , , , , , , , , , , ,

When you work on a new web design project and have entered the stage for coding, how do you go about it?

Do you start with the HTML and write the whole HTML page first, then code your CSS then troubleshoot?
Do you write all of your CSS first, then the HTML markup, then troubleshoot?
Or, do you write chunks of HTML first, add in the styles, troubleshoot/test, repeat?

Personally, I have done it just about all three ways – but my most often used method is the 3rd. I start from the top and work down to the bottom from left to right. I will start and code the entire header of a site in HTML first – then write my styles. Check in firefox, and repeat. Then, after the whole page is completed I check in all browsers to trouble shoot compatability issues – which are usually minimal and related to IE6 only – go figure!

So, how about you?

Note: There is a poll embedded within this post, please visit the site to participate in this post’s poll.

How to Use CSS Sprites With Son of Suckerfish Drop Downs

Comments Off

Posted on 22nd June 2008 by Lindsey in internet |Uncategorized

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , son of suckerfish, , , , , , , , , , ,

So recently I was working on a project that required image based navigation AND drop down menus. From the get-go I decided to use CSS Sprites for the tabbed menu for the normal, active and hover styles. I also decided the best way to implement the drop down was to use the “Son of Suckerfish” drop down menus heavily modified from the original code to fit in with the original programming I had done for the menu.

I’ve explained before how to use CSS Sprites for changing images, so I won’t go into too many more details on how to accomplish this, but to recreate this for your own site you will need to create one sprite for your normal tab, hovered and current/active tab. That’s three sets of tabs in one file.


This is what your file should look like after you have finished styling it to your liking (click to enlarge):

CSS Sprite for Navigation with Son of Suckerfish Dropdown

As you can see, for ease of writing the CSS I have exactly line up each navigation style exactly below the “normal” style. The middle is the “hover” images, with the last being our “current/active” tab styles.

Now, the CSS for the sprites is pretty simple – I’ve made a class for each tab that defines the height, width and background position. Next, I added the hover styles for each class, just changing the background position. Finally, to achieve the “current” styles, I added an id to be applied for when that particular link is “active” (ie: you are on one of the pages).

Click here to see the example of the sprite with dropdowns.

The code is pretty long for the CSS so I’m not going to post it directly into this post, so you can check it out here.

As you can see I renamed the primary id for the suckerfish menu to #drops (in example by HTMLdog it’s #nav – which I had already used as a container for my entire tab scheme). From there I pretty much changed everything to fit in with the navigation I had already built (using floats) except for the main “switch” that hides the drop down until it’s hovered over (the negative absolute positioning and the “left:auto” to bring it back). Of course the modification brought some IE6/IE7 issues so when you view source of the HTML you can see the two conditionals I added to fix the problem (mostly margin based).

As you can see combining the two methods is not hard at all and takes a little extra markup and a little extra CSS.

If you have tried this method and used it successfully leave a comment to show you’re awesome work!! If not, and you need some help troubleshooting leave a comment with the problem and we can work it out.

Rounded Corner Boxes With Expandable Heights Using CSS and Images

Comments Off

Posted on 10th June 2008 by Lindsey in internet |Uncategorized

, , , , , , , , , , , , , , , , , , , , , , , , , , , Rounded Corners, , , , , , , , , , , , ,

Rounded corners are a great design element to escape from the blocky/boxiness a lot of web designers fall victim to. I remember the first time I created my own rounded corner box using Photoshop and HTML/CSS. What a thrill A lot of people shy away from it because it SEEMS a lot more difficult than it really is.

I’m going to show two ways to create this effect using Photoshop (or the graphic editor of your choice) and HTML/CSS. There are other ways to create this effect using just CSS – but I really am not a big fan of it because it creates a lot more empty divs than this method. Yes if images are off you will lose this effect – but I’m willing to sacrifice that.

Like I said I’m going to demonstrate two ways to accomplish this. The first is using just a flat rounded corner image with no other effects. The second will have a box with a drop shadow, border and gradient. So let’s start easy!

First open up Photoshop, and create a new document with a size of 200x200px.

For this example you don’t really need to have a background color (ie: you can use a transparent gif), but for the sake of this example I’m going to use a white background fill.

Next, select your rounded rectangle tool and draw the shape out to fill most of the box. My shape radius option is set to just 5px, but you can choose whichever best fits for your design. The concept is the same no matter how rounded your corners are.

I’ve chosen one of my favorite colors for the shape’s fill – #ff008a – a nice bright magenty-pink

Now, hold down CTRL while clicking on your shape layer. Your shape should now be selected:

Select the shape

Now that you have the whole shape selected let’s remove any excess background you might have. From the top menu choose “Image” and then choose “Crop”. This will take your image down to just the shape. You will see a tiny bit of the background peeking from the corners where it rounds.

Cropped Shape

Make sure your shape is still selected (CTRL + CLICK shape layer). Now, choose the Rectangular Marquee Tool (keyboard: M). Now, while holding down the ALT key* (while holding ALT and using the rectangular marquee tool parts of your selection that are already selected will be deselected) select right after the TOP rounded corners end deselect the bottom half. It may be helpful if you zoom in a bit.

Here is what your selection should look like:

Top selection

Great, now crop that image the same way we did to the original shape – find “Image” on the top menu, and then select “Crop” from its dropdown.

There you have it. All we need to make our rounded corner box! I’ll explain:

First, CTRL + ALT + SHIFT + S to “Save for Web…”. Save your image as top.gif.

Now, press CTRL + SHIFT + E to flatten your image. You will be left with one layer. Next press CTRL + T to transform.

***TIP*** if your final layer is “locked” double click the lock next to the layer name and when the dialog pops up called “New Layer” press ok, THEN press CTRL + T.

Right click on your image and from the drop down select “Flip Vertical”. This will give you the bottom to your box. CTRL + SHIFT + ALT + S to save, naming it bottom.gif.

Great. Now that we have our images we can start the code.

Our HTML will look like this (I’m using divs for this example, but theoretically this can be applied to most if not all block level elements).

class="wrap">
class="mybox">

My box text
This is my rounded box, isn't it so cool! I love my rounded corner box, it's SO pretty! And it's expands it's height to fit in as much text as I want to throw in it! How awesome!

class="endbox">

**NOTE** : The “wrap” class is really for demo purposes. Because I am using floats for this example unless the parent element has a width the bottom of the box will float next to it. You won’t need to wrap each rounded box in this if you have them in a sidebar/part of your page of some sort with a set width close the the width of your box.

If you want to remove the wrap class and have the same effect in an area with no container width switch the “float:left” in “mybox” and “endbox” to “display:block;”. I recommend using floats contained within a set width parent though to prevent compatibility issues!

That’s it for the HTML, now the CSS. You will need to know several things before starting –

1) The WIDTH and HEIGHT of your rounded corner images AFTER cropping. If you are not sure open the file up in Photoshop and right click the title bar of the image and select “Image Size” and you will see the dimensions. You can also open up the folder where you have saved the image and hover over the image and the popup in Windows will show you the width/height.
2) The location of your image.

.wrap {
        width:200px;
        float:left;
        }

.mybox {
        float:left;
        padding:10px;
         /*Your width is 190px minus 20px for your left and right padding totally to 170px*/
        width:170px;
        /*the url to your top rounded corner image*/
        background:#ff008a url(top.gif) no-repeat;
        font:12px 'trebuchet ms', arial, verdana, sans-serif;
        color:#fff;
        }

.endbox {
        float:left;
        width:190px;
        height:6px;
        /*url to the bottom rounded corner*/
        background:transparent url(bottom.gif) no-repeat; 
        }

Great, that’s IT! Like I said before the “wrap” class is necessary only if you aren’t putting this within another div that doesn’t have a width set. This works cross browser FF, IE6/IE7, Safari and Opera.

See Rounded Box Using CSS

Now For the “harder” method. It’s actually not much harder. You will need three images instead of two – but it’s the same principle.

I’ll quickly explain how to make our image in Photoshop. First, start just like our previous image create a new image at a size of 200x200px. This time though be careful to make your rounded rectangle shape slightly smaller then the previous version – remember you will need to leave enough space around the image for your surrounding shadow. If you find later on that you’ve run out of space for your shadow then right click the title bar and from the drop down select “Canvas Size”. Add space to the height and width as needed to fit in your shadowing.

Ok, next step is to make our box a little prettier – double click the shape layer to bring up the layer styles dialog. First add a border. For this example I placed a border of 2px, color:#035873 and opacity of 39%. Next let’s add a gradient that repeats down the length of the box.

These are the following options for your gradient:

Gradient

Finally, lets add our shadow. First CTRL + Click the shape layer to select it. Next, create a new layer (CTRL + SHIFT + N). Move this layer BELOW the shape layer. Make sure your selection is still intact. If not CTRL + Click the shape layer to reselect.

Now, make sure your on the new layer you have created. Fill with black. The next step depends on how much shadow you want. But here is what I did: on the top menu click on the “Filter” menu and from the drop down select the “Blur” option, from that slideout choose “Gaussian Blur…” finally on the window that pops up put in a radius of 4.3.

You should now have a rounded box that looks like this:

Rounded corner with shadow

Now, for cutting out the slices for this box you will have to select outside of the main rounded box area. For this the best option is to use the rectangular marquee tool (keyboard: M).

Select the top part of your box and make sure your selection is large enough that it goes just slightly beyond your shadow. If you cut too close your shadow will cut off abruptly and you will lose the whole effect.

So your first selection should look like this:

Selection One

See how my selection reaches outside of the shadow? This is very important. Next, go to “Image” on the top menu and then select “Crop”. Save this image.

Next, press CTRL + ALT + Z to take a step back to before you cropped. Make sure your Rectangular Marquee Tool is still selected. Now hold down SHIFT and press the down arrow to move your selection all the way to the bottom. (Let go of SHIFT if the selection goes to far and adjust up/down as needed).

Selections Two

Repeat the steps to crop, save and take a step back (CTRL + ALT + Z).

Grab your “Single Row Marquee Tool” (click the Rectangular Marquee Tool so the slideout pops out and scroll down to the 3rd tool). Just click anywhere in the middle of your box. You see a single 1px high selection for the width of your box.

Selection three

Now repeat the Crop and Save.

Great! Now you have the three images you will need to complete this effect. Now it’s time for the HTML:

class="wrap">
class="top">
class="box">

My box text
This is my rounded box, isn't it so cool! I love my rounded corner box, it's SO pretty! And it's expands it's height to fit in as much text as I want to throw in it! How awesome!

class="bottom">

Again, the wrap isn’t needed if you have it placed within another div in a sidebar-like situation.

And the CSS:

.wrap {
        width:200px;
        float:left;
        }

.top, .bottom {
        float:left;
        width:200px;
        height:23px;
        /*url to the bottom rounded corner*/
        background:transparent url(rounded-shadow-btm.gif) no-repeat; 
        }

.top {
        /*url to the top rounded corner*/
        background:transparent url(rounded-shadow-top.gif) no-repeat 
        }

.box {
        float:left;
        padding:15px;
        /*Your width is 200px minus 20px for your left and right padding totally to 180px*/
        width:170px;
        /*the url to your text background*/
        background:transparent url(rounded-shadow-bg.gif) repeat-y;
        font:12px 'trebuchet ms', arial, verdana, sans-serif;
        color:#fff;
        }

Works in all browsers!

See Rounded Box With Shadows Using CSS & Images

And there you have it. Two simple ways to have rounded corners using images and CSS!

***TIP*** – For my examples I am NOT using a CSS reset method. So your results may vary. If this is the case (and usually it is with IE6 – big surprise!) you will have to adjust the margins and/or paddings. I’m not going to tell you how to solve this problem should you run into it, because solving your own problems is 99% of how you learn CSS and get your experience. But you now have the general principles and should be easily able to integrate this!

And if you can’t, post any questions in the comments or email me and I will try my best to help you out.

Create Full Width Header & Footer With Centered Content Using CSS

Comments Off

Posted on 7th June 2008 by Lindsey in internet |Uncategorized

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

There are probably a million different ways to do this, but I’m going to show the way that I have preferred to do it, combined with my favorite centering position method.

So the simple way to do this is as follows:

HTML:


id="headerbg">

YOUR TEXT

id="container">
class="left">

This is content that goes on the left!

class="right">

Here is my right column!

class="clear">
id="footer">

HEY HERE IS MY FULL WIDTH FOOTER

Simple right? And here is the CSS:


/*Simple CSS reset for items we will use JUST for this example.
Please use full reset when designing!
Reseting the margin and padding is important for the body tag so the
header and footer will hug the whole screen.*/

h1, p, body, html {
        margin:0;
        padding:0;}

/*Just visual styles*/
body {
        background:#000;
        font:12px verdana, sans-serif;
        color:#000;
        }

/*Our full length header.
We align the text center so it shows up in the middle.
If you prefer you could right or left align it.*/       
#headerbg {
        background:#cccc66;
        text-align:center;
        padding:20px;
        }

/*Center Content*/  
#container {
        position:relative;
        margin:0 auto;
        width:800px;
        }

/*Full width footer*/
#footer {
        background:#cccc66;
        padding:10px;
        text-align:center;
        }

/*These are just styles used for the example for the content.*/     
.left {
        float:left;
        width:500px;
        background:#ccff66;
        }

.right {
        float:left;
        width:200px;
        clear:right;
        background:#66ff33;
        }

.left p, .right p {
        padding:10px;
        }

/*If you are going to use floats then you will NEED to clear the
footer so it doesn't bunch the content up*/
.clear {clear:both;}

See Example

But wait, theres more. Often I have several things going on in my header, like a logo, and some links. I’ve actually used this on the redesigned CSSgirl, and right now you all are going to get a sneak peek of the homepage of the design in static format so I can illustrate this.

It’s basically the same as the above example except two critical things:

1. In our HTML the header is going to be an empty div. You will need also to define a height for your background.
2. We will use a negative top margin to pull the centered content on top of the full width header.

This is a really easy way to use patterned/repeated background patterns in your header that expand the entire width of the site.

So, here is how those things will change:

/*Our full length header. */        
#headerbg {
        background:#cccc66;
        height:90px;
        }

/*Center Content*/
#container {
        position:relative;
        margin:0 auto;
        width:800px;
        margin-top:-90px;
        }

Now you can position and float things ON TOP of the full length header.

See the main page of the all new CSSgirl in static HTML format for examples (full length header and footer). (And no this isn’t the 100% final version

CSS Sprites – Easily Use CSS To Replace Images

Comments Off

Posted on 28th May 2008 by Lindsey in internet |Uncategorized

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

If you’re not using CSS Sprites (also known as the CSS Image Replacement Method) you should be. Many coders seem to fear this easy and basic way to use images with CSS and I’m not sure why.

The benefits of CSS Sprites are plentiful, but you (and your visitors) will benefit from this method ten-fold. For the coder it’s less slicing and cropping of images, and for the user it rids us of that annoying image loading flash when you use CSS to replace background images.

I’ll take you through some quick steps to get started with CSS Sprites.

First, fire up Photoshop (or your graphic editor of choice).

For this example we will start easy and make a background (and hover state) for one tab.

First Create a new document (CTRL + N) width a width of 100px and a height of 50px. Than fill in the background with the color of your choice. I’m using black (#000000).

Next, click on the shape tool and select the rounded rectangle (SHIFT + U). Drag the shape until you get a nice looking tab. Double click the shape’s color box and choose a color for your tab. I’ve chosen red (#ff0000). Now, choose the move arrow and drag the shape so the bottom half of the rounded rectangle is outside of the viewing box so it looks like this:

CSS Sprites - Tab

Now, let’s make sure our tab is centered in the box. Select all (CTRL + A) and make sure the tab’s layer is selected. Click on the arrow (move) tool again. Now on the top tool bar click the “Align horizontal centers” icon (see image below):

CSS Sprites - Horizontal Align

Now, we can style our tab a bit. I’ve added an inner shadow to give the tab some depth (double click shape layer to have layer styles dialog appear):

CSS Sprites - Inner Shadow - Tab

Great. Now, the next step is up to you. You can leave the tab blank and have text overlay it through the HTML, or you can use a stylized text. I’ve chosen to use a font that isn’t available through CSS/HTML so I’ve added that to image. (To make sure your font is centered repeat the step above and “align horizontal centers”):

CSS Sprites - Tab

Great, so we have our first tab. Now we need to create our hover state for this tab. Duplicate your tab by right-clicking the title bar and selecting “Duplicate”.

Now on the duplicated tab I’ve changed the background color to a light blue (#00a8ff) (double click shape color box again to have color dialog appear).

Now, back to the original red tab I am now going to merge the two tabs together. For this example I am going to place the two tabs side by side, but that’s a preference left up to you. You can also stack the images on top of each other – or put them in any order you prefer.

So, right click on your original tab’s title bar and select “Canvas Size…” from the drop down. Click the LEFT arrow, and change the width to 200px (increase your canvas size by the width -or height if you are stacking) of your tabs).

CSS Sprites - Canvas Size - Tab

Now, to the right of your image you will have an extra 100px. Now, go back to your hover state image. Select all three layers and press CTRL + G. This will group all three layers into a folder. Now select the move tool (black arrow) and drag the image into the first image. Now adjust the grouped layer so it sits EXACTLY next to the original with the same height and width (you won’t see any of the transparent background if you do this correctly).

You should then have an image that looks similar to this:
CSS Sprites - Two tabs

And that’s it for the photoshop work!

Now, fire up your text editor.

Here is the HTML:

Home

And here is the CSS:


  a.home {
        background:url(tabs.gif) no-repeat;
        float:left;
        text-indent:-9999px;
        height:50px;
        width:100px;
        }

a.home:hover {
        background-position: -100px 0;
        }

Also if you want to use this as your “current” style (highlight the current page) you can add that class to the CSS so it would look like this:

a.home:hover, a.active {
        background-position:-100px 0;
        }
        

See the demo.

Not so hard right?? Check out the HTML and CSS for CSSgirl and you will see that for my main nav “images” I am using CSS Sprites. For this site though I used one large image that contained all the images for both the original nav and the hover states. So my HTML looks like this:

And my CSS looks like this:

#navi {
        float:left;
        width:520px;
        height:48px;
        }

#navi a:hover {border:none;}

#navi a {
        background:url(images/navigation.gif);
        height:48px;
        display:block;
        float:left;
        text-indent:-9999px;
        }

#navi a.home {
        background-position:0 0;
        width:94px;
        }

#navi a:hover.home {
        background-position:-425px 0;
        }       

#navi a.about {
        background-position:-95px 0;
        width:91px;
        }

#navi a:hover.about {
        background-position:-520px 0;
        }       

#navi a.portfolio {
        background-position:-186px;
        width:128px;
        }

#navi a:hover.portfolio {
        background-position:-611px;     
        }

#navi a.contact {
        background-position:-314px;
        width:107px;
        }

#navi a:hover.contact {
        background-position:-739px;
        }

#navi a.free {
        background-position:-852px;
        width:98px;
        }

#navi a:hover.free     {
        background-position:-953px;
        }

Get out there and try it! Show me how it turns out. I’d love to see what you guys can do with this.

Using IE Conditionals For Cross Browser Compatibility

Comments Off

Posted on 27th May 2008 by Lindsey in internet |Uncategorized

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

What’s worse than spending a week coding a brand new design to realize that your site looks like a bloody mess in IE6? Luckily we have a valid way to fix these problems without having to use hacks in our CSS and destroy the completed design that looks good in all other browsers.

IE Conditionals are an easy and awesome (and valid!!) way to insert any IE specific styles* into your code. You can specify styles for just IE6, just IE7 or for both. Not only that you can specifiy styles to affect all versions of IE below any version number. (*actually these conditionals can be used for anything that you want to display to IE specifically)

For example, say you have some margin adjustments to make that effect only IE6, in the head of your HMTL document you could put this:


Or, say you need it to affect IE6 and all previous versions:




The above code tells the browser to apply these styles to IE6 and any version LESS THAN it.

You can also use the and/or syntax (& / |) if you need the styles just applied to certain versions:




You can also use the & symbol to combine styles for one browser ex: [if (IE 6) & (IE 5)].

If you have a substantial amount of styles (or aren’t using a templating system where the header is isolated) I recommend using the conditional to link to a seperate IE stylesheet:





See more examples and the complete variable list over at Microsoft’s Developer Network.

Give Images Polaroid Style Treatmeant

Comments Off

Posted on 20th May 2008 by Lindsey in internet |Uncategorized

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

I’m a big fan of polaroid’s. I love the fact that you can snap a photo and the camera will spit out a photo for you instantly. I love the style so much in the new version of CSSgirl (to be released within the next two weeks!!!) has incorporated their style in the new design. I thought I’d share how I went about creating the image and the HTML/CSS behind it!

First, you will need to decide what size you want your polaroid images to be. I’ve decided on a simple 100×100 space for the actual image. If you want your images bigger/smaller just increase your polaroid size as needed. Create a New Document (CTRL + N) with a height and width of 100px.

Next, fill the entire document with black.

Now, right click on the title bar of the document so the drop down appears and select “Canvas Size”. A window will pop up – first click on the arrow that points up. Now for height fill in 130.

canvas-size.jpg

Your document will add the 30 pixels to the bottom of the image. Next, right-click the title bar again and select “Canvas Size” again. This time just fill in the width as 120 and click “OK”.

canvas-size2.jpg

Ok, once more! When the Canvas Size window is opened this time click the bottom arrow, and fill in 140 for the height. You will now have 10px added to the top of the image.

canvas-size3.jpg

Next, on your layers palette CTRL + Click Layer 1, which will have just your black square on it. When you do this the black square will become selected.

select-black.jpg

Now, press CTRL + SHIFT + I. This will inverse your selection so instead of your black square being selected the area surrounding it will become selected. Now, press CTRL + SHIFT + N. This will create a new layer, which we will use the paint bucket and fill with white.

fill-white.jpg

Great! So we are almost done. I like my polaroid images to have a little bit of “realistic” feel to them, so I’m going to add some shadowing. You will need to drag Layer 2 (our white layer) beneath Layer 1 (black fill).

move-layer2.jpg

Next, double click on Layer 1, the black fill layer so that the layer styles window pops up. Choose “Outer Glow” and set the blend mode to “Multiply”. Then click on the color box and change it to black (#000000). Take the Opacity down to about 30%, than click ok. It’s a very subtle change, but I think it gives it a better look.
layer-styles.jpg

One last step – first, I create another new layer CTRL + SHIFT + N. Then I moved the new layer beneath the layers that we already had. Next, fill that layer with whatever background color you’re polaroid style images will be resting on. I’m using a white background. Now, right click the title bar and choose “Canvas Size”. Add 10px to both the height and width – you will end up with a width of 130 and a height of 150.

Now, double click layer 2 (the white frame layer). Your layer styles window will pop up. Next, click on “drop shadow”. Take the opacity down to 30% and change the angle to 85 degrees. Next change the distance to 2px and the size to 4px. If you are using a background color other than white you will need to adjust these things as neccessary.

dropshadow.jpg

Next, click on stroke. Make sure the size is only 1px. Now click the color box and change the value to “#f8f7f7″.

Ok, so if you want to do some extra shadowing or styles you can have at it. Once you have it looking the way you want, save the images (CTRL + SHIFT + ALT + S). Save it as a .gif.

You can also download the .psd or .gif file.

So here is our finished product:

polaroid.gif

Now we need to write the CSS/HTML to have the images we choose use this background. It’s very simple. Choose the 100x100px image you would like to have use the polaroid style.

Here is the CSS:

img.polaroid {
        padding:10px 10px 30px 10px;
        background:#fff url(polaroid.gif) no-repeat;
        }

And the HTML:

class="kids.jpg" alt="My three babies!" />

Here is how it will look:

We can also go a bit fancier by adding a caption to the polariod by changing up our CSS/HTML a little:

.polaroid {
        width:130px;
        height:150px;
        background:url(polaroid.gif) no-repeat;
        color:#000;
        font:11px 'trebuchet ms', arial, sans-serif;
        }

.polaroid img {
        padding:15px 15px 0 15px;
        }                

.polaroid p {
        margin:0;
        padding:0;
        margin:0 15px 0 15px;
        }

And the HTML:

class="polaroid"> src="kids.jpg" alt="My babies!" />
My babies on Easter 2008.

And the result:

My babies!

Easter 2008.

What’s really great about this is that with just those few simple styles you can use this style on a whole gallery. Or for anything. For example on iheartswitch.com for the archives section I used a similar method to have the archive image and short description appear.

Style Your Code Samples Without Excessive Markup

Comments Off

Posted on 18th May 2008 by Lindsey in internet |Uncategorized

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

I’ve noticed a lot of sites have a very complicated way of styling the code samples they provide, using multiple span classes and/or inline styles and many, many
s. Other times the site just wraps the code in a attribute and doesn’t highlight the different syntaxes.

I’ve written some simple CSS styles to fix this problem. So if you are interested in having your code display as if it was in a text editor with syntax highlighting here is an easy way to do it.

The first example is a sample of CSS code and how it can look when you apply these styles (***This is not the actual styles, just an EXAMPLE):

/*Center Content Depending on screen size/resolution*/
#container {
        position:relative;
        width:800px;
        margin:0 auto;
        }

/* LOGO, Searchbox, Product Links*/
#header {
        float:left;
        width:800px;
        clear:both;
        background:url(images/top-border.gif) bottom left no-repeat;
        padding-bottom:25px;
        }

#header h1#logo {
        float:left;
        width:195px;
        height:65px;
        }
        

By wrapping the code in a div I assigned the class “css” to and using strong and ems within I have a nice stylized version of my code.

Here is an example with xhtml:


    class="sitenav">
  • href="product.html" class="first">
  • Registry
  • href="product.html">
  • Innovative Community
  • href="product.html">
  • About Innovative Baby
  • href="product.html">
  • My Account
  • href="product.html" class="last">
  • Help
  • class="email">href="product.html">
  • email this to a friend
    id="left">
    class="shop-by"> src="images/shop-by-brand.gif" alt="Shop By Brand" />
    action="product.html" method="get">

    Nice right? Here is the CSS that controls how the examples above look:

    .entry .css, .entry .xhtml {
            border:1px dashed #ccc;
            float:left;
            padding:5px;
            font:12px 'courier mono", georgia, serif;
            display:block;
            margin:10px 0;
            clear:both;
            /*If you have a long line of code and don't want to to make the box expand outside
            of the elemnt you are putting your code in, set a width here and set the overflow to scroll
                       width:450px;
                   overflow:scroll;
            */
            }
    
    .entry .css em, .entry .xhtml em {
            color:#666;
            text-transform:uppercase;
            font:10px 'trebuchet ms', arial, sans-serif;
            }
    
    .entry .css strong {
            color:#AF0038;
            }
    
    .entry .css code strong {
            color:#4F4F4F;
            }
    
    .entry .css code em, entry .xhtml code em {
            text-transform:none;
            font:inherit;
            color:#FF6FB8;
            }
    
    .entry .xhtml code strong {
            color:#1DA4EF;
            }
    
    .entry .xhtml code em {
            color:#FFB93F;
            }
    
    .entry .xhtml code tt {
            color:#3F61FF;
            font-weight:normal;
            }
    

    And here is the markup for the CSS example:

    class="css">
    /*Center Content Depending on screen size/resolution*/
        #container {
            position:relative;
            width:800px;
            margin:0 auto;
            }
    
    /* LOGO, Searchbox, Product Links*/
    #header {
            float:left;
            width:800px;
            clear:both;
            background:url(images/top-border.gif)
    bottom left no-repeat;
            padding-bottom:25px;
            }
    
    #header h1#logo {
            float:left;
            width:195px;
            height:65px;
            }
    

    Not too bad right? We lose all the cluttery span classes,
    and inline styles.

    Some things to remember when using this process:

    1. To have the comments styled and avoid using a span, what I have done is left comments outside of the tags and wrap them in a em. So if you have a comment in the middle of your code sample you will need to end the before the comment and restart it after.

    2. If you have code samples that have long lines of code, either make sure you make a line return to shorten the width and drop it to the next line OR set a width in the CSS for the

    s that surround the sample to your max width, and set the overflow property to scroll.

    I’ve created two different samples for you to check out. Feel free to download (right click “save as”) the pages and use the styles as you wish! Also, this isn’t just limited to CSS and XHTML, you can easily do this with PHP, ASP, Javacript – you name it.

    CSS girl sample (the styles I’ve used here) | Dark theme