Thứ Ba, 22 tháng 3, 2011

How to Override Inline Styles with Style Sheet

How to Override Inline Styles with Style Sheet

Tags:
There have been a few incidents when I came across wanting to override some inline styles and I always thought this was an impossible thing to do. The other day I stumbled across this article by Natalie Jost, and she actually came across some similar scenarios and came up with a very clever solution.
For example, lets say the html looked like this:
<div class="block">
 <span style="font-weight: bold; color: red;">Hello World</span>
</div>
You can override the child span by using the following css:
.block span[style]{
    font-weight: normal !important;
    color: #000 !important;
}
Unfortunately the down side of this is technique is that it will not work on IE6 and below, but it does work in IE7, IE8, Fire Fox, Safari, and Opera.
For more detailed explanation of this technique please check out Natalie Jost’s Article.

Related Posts

PNG Transparency Fix in IE6

PNG Transparency Fix in IE6

Tags:
As I was exploring different ways to use Transparent PNG files in some of my designs (Check out Smashing Magazine’s PNG post for some great examples), I had to first find out how to make PNG files work in IE6. As we all know, IE 6 does not fully support transparency.

The .htc Fix

Download the .htc file and specify which element/tag you want PNG support on. To learn more here is an online demo and set up instructions.

The Java Script Fix

SuperSleight
This is probably the best Java Script PNG fix for IE6 that I have come across. Please check out www.24ways.org’s tutorial for a guide on how to implement.
Google Code
I stumbled across this Google Code which was pretty straight forward. The downside of this is that script only fixes images named: *-trans.png. Unfortunately, the transparent background image cannot be tiled (repeated) using background-repeat. Nor can it be positioned using background-position.

Or the CSS Fix

I stumble across a simple technique that worked effectively, which uses CSS and conditional tags for IE, no Java Script involved.

Step1 – HTML

We can start out by creating a new html file and place an empty div tag with a class name “vehicles”.
<div class="vehicles"></div>

Step2 – Style Sheet

Next lets create a style sheet called styles.css and add the following:
body {
    background: url(body-bg.jpg); /* Adding base background pattern */
}
.vehicles {
    width: 500px;
    height: 176px;
    background: url(vehicles.png) no-repeat; /* Adding background of the vehicles */
}

Step 3 – IE Style Sheet

Lets create another new style sheet and call this one IE.css.
Now we all know IE hates PNG files, so this is the part where we work the magic.
/* Notice I add the 'html' in front of the class name, I did this so there will no background property conflicts with the other style sheets */
html .vehicles {
    background: none; /* Hide the current background image so you can replace it with the filter*/
    width: 500px; /* Must specify width */
    height: 176px; /* Must specify height */
    filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='vehicles.png');
}

Step 4 – Conditional Comments for IE

This is the final step. Now we will go back to the html file from step 1, and we will call both of the style sheets we just created.
Inside of the <head></head> tags on the top of your file, add the following:
<link rel="stylesheet" href="styles.css" type="text/css" />
<!--[if IE 6]>
<link rel="stylesheet" href="IE.css" type="text/css" />
<![endif]-->
*Notice we have the conditional comments for IE6 on the 2nd line, this is where we tell IE6 to use the IE.css style sheet in addition to our regular style sheet.

Conclusion

These were 2 simple ways I was able to pull off the PNG problem on IE6. The good part about this technique is that it is XHTML compliant and it also reduces page weight.
If you have any suggestions, comments, or know of a better way, please give me a heads up!

Related Posts

Glossy & Beveled Buttons – Photoshop Tutorial

Alice At HeartGlossy & Beveled Buttons – Photoshop Tutorial

Tags: ,
Glossy & Beveled Buttons – Photoshop TutorialA few friends of mine have asked me how I add the beveled effects on my buttons so I decided this is a good tutorial for those who would like to know. I am not a fan of heavy gloss, drop shadows, and bevels, but a light touch of each can make a nice effect to a lot of elements on the web. Let’s get started!
Beveled Button Tutorial - Photoshop

Step 1.
Create New File

Open up your Photoshop, and create a blank new document at the size of 300px by 200px.
Creating a new file

Step 2.
Creating the Rounded Rectangle

Go to your Photoshop Tool Panel/Pallet and select the Rounded Rectangle Tool. Draw a rounded rectangle (Width: 160px / Height: 40px). A good tip is to always name your layers, let’s name this layer “Button Base”. If you keep your layers organized, it will save time in the long run and will be less of a head ache to make edits later on.
Creating a rounded rectangle
*Note if you are not sure how big your rounded rectangle is, on the top of the menu, go to Windows, then click on Info. You will now see a new box on the right hand side, make sure the Info tab is open, and on the bottom left corner, you will see your width and height specs. You can use this guide as your making your rounded rectangle.
First select the button layer, then on the bottom of the layer palette, you will see an “F” Icon, click on that and choose Blending Options…
Adding style to your layer
We will start by adding a nice red gradient to it. My theory on aesthetic gradients, is that each tone should not be drastically different in the color family. So for example, instead of going from a very light red to a very dark red, we should just slightly change the tone of the color. Click on the Gradient Overlay check box and click on the gradient panel. I chose these 2 color codes: #e61212 and # ca0101 as my gradient. Lets also stretch the scale to 150%.
Adding gradient to your layer
Let’s now add a hint of inner shadow. Click on the Inner Shadow check box and make your Opacity to 25%, Distance to 0px, and Size to 10px.
Adding inner shadow to your layer
Lets now click OK and move on to the next step.

Step 3.
Adding the Bevel Effect

On your keyboard, hold down ‘Ctrl’ and with your mouse, click on the rounded rectangle layer once (You have to click on the Vector Mask Thumbnail which is the middle thumbnail on that layer next to the chain icon). When selected properly, you will see dotted lines around the rounded rectangle.
Adding bevel to layer
Now while the rounded rectangle is selected, go to the top menu and go to Select -> Modify -> Contract… You will then be prompted to specify the contracting size.
Make the Contract by 1px. (What this does is, it allows you to subtract 1px pixels from your current selection.)
Now you should still see the dotted lines around your rounded rectangle, with that selected, with your keyboard, hold down ‘Ctrl’ + ‘Shift’ + ‘N’ all at once. (This is a short cut for creating a new layer) It will then prompt you to name this layer, lets name it Bevel. After the layer is created, with your keyboard type ‘Ctrl’ + ‘Delete’. (This is a short cut for filling this layer with your selected background color). Once that layer is filled lets now change the Fill to 0%.
Adding fill to your layer
Now let’s double click on the “Bevel” layer we just created and add a Stroke. Make the stroke size to 1px, position it to the Inside and make the fill color white.
Adding stroke to your layer
By now you should have something like this.
Example of Button
We will now add a mask to it and tone down the bevel. With the “Bevel” layer selected, on your keyboard, hold down ‘Ctrl’ + ‘G’ (This is a short cut for creating folder groups). You now have the “Bevel” layer inside of a folder, lets call this folder “Bevel Mask”.
Next you will select the masking tool (on the bottom of the layers palette, you will see a square icon with a circle in the middle). Once the mask has been added, on your keyboard type the key ‘G; (Short cut for the Gradient Tool), and on the top left corner of your window, you will now see a gradient tool, select that and be sure its selected to the Black to White gradient. Now place your mouse starting on the bottom of your rounded rectangle, and drag your mouse up to the top of your rounded rectangle. (Tip: When using the gradient tool, if you hold the ‘Shift’ key on your keyboard, you will be able to drag on a straight line). Now you should have something like this.
Adding mask to your layer
Your almost done! Now with the “Bevel Mask” folder selected, tone down your opacity to about 50%.
Turn down opacity of layer
From this point on its pretty self explanatory, just add your text and you can also add some gloss or reflection.

Step 4.
Adding the Gloss to Your Button

Go to your Photoshop Tool palette and choose the Rectangular Marquee Tool. Make a selection on the rounded rectangle’s upper half.
Creating a glossy effect
We will create a new layer which we will name it “Gloss” (to create a new layer, on your keyboard, hold ‘Ctrl’ + ‘Shift’ + ‘N’)
Now on your keyboard hit ‘G’ (Short cut for the Gradient tool) and select the Forground to Transparent Gradient. It should be a Transparent gradient to white (If the 2ndary color is not white, click out of the popup, and on your Tool Palette, make sure your foreground color is white).
Creating a glossy effect
Click your mouse starting at the top of the canvas, and by holding the ‘Shift’ key on your keyboard, drag your mouse downwards to the bottom of the button. If the gradient was too heavy, you can always tone it down by lowering the opacity on that layer.
Beveled Button Tutorial - Photoshop
*Note In addition, I added a reflection and a light shadow to this button. Now its your turn, let your creativity take it from here!
Hope that made sense! If you have any questions or got lost somewhere in between my steps, feel free to ask me anytime.

Related Posts

Liquid & Color Adjustable CSS Buttons

Liquid & Color Adjustable CSS Buttons

Tags:
When working on a large site with multiple buttons, it can be quite tedious to make all the buttons in Photoshop. Making future adjustments on the verbiage and colors can be also be time consuming.
By having dynamic buttons, this scenario is much easier to handle, and by having liquid and color adjustable buttons with CSS, we are able to change the verbiage and colors in a flash.

Step 1.
Create a Transparent Button

We will first start off from the button made in my previous tutorial. If you already know how to create buttons in Photoshop, you can just skim through this step.
(If you haven’t checked out my Glossy and Beveled Buttons Tutorial yet, now is a good time. Or if you’re lazy or in a rush, you can download the PSD file here.)
  1. We will first open up the file and ditch unnecessary layers like the reflection, shadow, and text. Next, select the “Button Base” layer and let’s turn down the Fill to 0% (Top right corner on the layer palette.) Also in your ‘effects’ get rid of the red gradient Overlay.
    Clean up Buttons
  2. Now we need to select the shape of our “Button Base” layer by clicking on the “Vector Mask Thumbnail” (the thumbnail on the right of the chain icon) while holding the ‘Ctrl’ Key on your keyboard. With the selection highlighted, lets create a new layer (‘Ctrl‘ + ‘Shift’ + ‘N’) and name it “Gradient Fade”. Fill it with a ‘Transparent to Black’ gradient. Tone down the gradient by making the Opacity to 50%. (Now you should have a light grey/gradient button).
  3. Select the shape of our “Button Base” layer again, and from here we need to invert the selection (‘Ctrl’ + ‘Shift’ + ‘I’). If you did this correct you should see a dotted line around the button and also around the canvas. With the inverse selection still selected, let’s now create a new layer named “Mask” and fill it with a white background.
    Mask the button
  4. Hide and turn off the visibility on the “Background” layer so now should have a transparent background. Now crop the button to 160px by 40px.
    Hide background and crop

Step 2.
Slice Buttons

At this point, we now have to slice our button into 3 pieces.
Slice A – Should be the left side of the button, save this image as btn_left.png
Slice B – Should be the center piece that stretches, save this image as btn_stretch.png
Slice C – Should be the right side of the button, save this image as btn_right.png
Slice button in 3 pieces

Step 3.
HTML / CSS

The HTML
<div class="btn"><a href="#">Add to Cart</a><span></span></div>
The CSS
body {
 margin: 0;
 padding: 10px;
 font-family: Verdana, Arial, Helvetica, sans-serif;
 font-size: 14px;
}
.btn {
 float: left;
 clear: both;
 background: url(images/btn_left.png) no-repeat;
 padding: 0 0 0 10px;
 margin: 5px 0;
}
.btn a{
 float: left;
 height: 40px;
 background: url(images/btn_stretch.png) repeat-x left top;
 line-height: 40px;
 padding: 0 10px;
 color: #fff;
 font-size: 1em;
 text-decoration: none;
}
.btn span {
 background: url(images/btn_right.png) no-repeat;
 float: left;
 width: 10px;
 height: 40px;
}
The beauty of this technique comes into play after all of this is done. Now that the button is liquid and transparent, to adjust colors of our buttons, now all we have to do is add a colored background to them.
.btn_addtocart { background-color: green; }
.btn_checkout { background-color: red; }
.btn_learnmore { background-color: orange; }
This is how you would implement these styles in our html.
<div class="btn btn_addtocart"><a href="#">Add to Cart</a><span></span></div>
<div class="btn btn_checkout"><a href="#">Check Out</a><span></span></div>
<div class="btn btn_learnmore"><a href="#">Learn More</a><span></span></div>

Step 4.
Cross Browser Testing

Now we all know IE is a pain. Refer to my previous PNG Transparency Fix in IE6 tutorial, and use the SuperSlight Javascript technique for this example. Here’s the direct link to www.24ways.org’s IE6 Fix tutorial

Conclusion

This idea dawned on me after I was continuously creating multiple image buttons on one of my client’s sites. As you can see, with a quick switch in the style sheet, I am able to adjust all buttons across the site.
I feel this technique still has some refining to do and has room for improvement, so I’m looking forward to anyone that has a better way or can add on to this to make this a better strategy.

Related Posts

Cropping Backgrounds of Vehicles

Cropping Backgrounds of Vehicles

Tags: ,
Since I work in the automotive industry, cropping out background of trucks and SUVs is almost a daily task. Some times getting the shadow and reflection of the vehicles can be hard to crop, but this technique will surely make it an ease for you.

Final Image Preview

Photoshop Cropping Background Tutorial - Final Image
Lets get started!

Step 1.

Open up the original image in Photoshop, we will start by duplicating this image (Ctrl + J). As I have advised before, always name your layers.
Photoshop Cropping Background Tutorial - Duplicate Image

Step 2.

Go to your Photoshop tools palette, and select the Pen Tool. If you are not familiar with how to use this tool, here is a good tutorial to get your started. (If you are new to using this tool, it can be a bit rough to get used to how it works, but after you get it down, it’s very useful).
Let’s trace around the entire vehicle without the background or shadow.
*Tip: When you are using the pen tool to trace around objects, turn the Fill property to 0% (Located at the top right corner of your layers palette). When tracing, zoom in so you can catch the details. Holding the space bar while scrolling up and down on your mouse allows you to zoom in and out of an object. Holding the space bar can also allow you to move your canvas around easier similar to the ‘hand tool’.
Photoshop Cropping Background Tutorial - Trace Image

Step 3.

Once you have the shape of the vehicle completed, let’s make a selection of this shape. To make a selection from a shape, hold the Ctrl key on your keyboard and with your mouse, click on the vector mask thumbnail. If you did this correct, you will have dotted lines around your shape, from here, we will select the ‘Base’ layer and duplicate that selection area (Ctrl + J). Let’s name this new layer as ‘Vehicle’
Photoshop Cropping Background Tutorial - Mask Image

Step. 4

Let’s now carry over the natural shadow that the vehicle had. Go back to the ‘Base’ layer and on your Photoshop tools palette, select the Lasso Tool. With the lasso tool, let’s draw a circle around the reflection and shadow of the vehicle. After the selection is made (be sure you are on the ‘Base’ layer), on your top menu, go to Select -> Feather (Ctrl + Alt + D) and make the feather radius to 50px. Let’s now duplicate this selection (Ctrl + J). Name this layer ‘Shadow’.
Photoshop Cropping Background Tutorial - Select Shadow of Image

Step. 5

From this point, let’s turn off the visibility of the ‘Base’ layer. Create a new layer (Ctrl + Shift + N), and name this layer ‘Green Screen’. Fill it with red for now (this is just so you can see the background differences).
Photoshop Cropping Background Tutorial - Duplicate and Feather

Step 6.

Its now time to blend our ‘shadow’ layer with the ‘green screen’ layer. Select the shadow layer, and on top of your layers palette, use the blending mode drop down and select ‘Linear Burn’.
Photoshop Cropping Background Tutorial - Add Blending Mode
Finally, we need to make the windows more realistic by making them see through. This is a tricky step so read carefully.
We will first start by tracing around the windows using the pen tool. You will end up with 3 layers in my example. To combine them all into one layer, highlight all 3 layers, and we will now merge them (Ctrl + E).
Photoshop Cropping Background Tutorial - Trace Windows
Let’s select our merged layer by holding Ctrl and with your mouse, clicking on the layer. Next, we will select the inverse selection (Ctrl + Shift + I).
Photoshop Cropping Background Tutorial - Inverse Selection
Then while the inverse selection is selected, we will mask the ‘Vehicle’ layer.
Photoshop Cropping Background Tutorial - Mask Window
After the vehicle layer has been masked, we will select the shape of the mask we just added by holding the Ctrl key and with your mouse clicking on the ‘Layer Mask Thumbnail’
Photoshop Cropping Background Tutorial - Mask Window
Now, we need to select the inverse selection again (Ctrl + Shift + I). At this point you should be back with the selection (dotted lines) just around where the windows are.
With the window area still selected, go to your Photoshop tools palette and select the brush tool. Go to the Brush Pre Set Picker at the top left corner (by the top menu), and choose the Soft Round 100px Brush and also tone the brush opacity down to 50%.
At this time, you should now check on the bottom of your Photoshop palette to be sure that you have the foreground color set to white. Now brush the outer areas of the window lightly.
Photoshop Cropping Background Tutorial - Mask Window
Your finally done! Now you can add some back drops in there for the final touch-ups.

Final Image Preview

Photoshop Cropping Background Tutorial - Final Image
Have any comments or questions? Feel free to let me know.

Related Posts

Cross Browser CSS Fixes, Tools, and Hacks

Cross Browser CSS Fixes, Tools, and Hacks

Tags:
As designers and developers we are all responsible for the product we produce, and cross browser testing is a must in our line of work. Although the W3C statistics show about 7 browsers that people tend to use most, in my opinion, two of them are the most important and should be given special attention to perfecting (Firefox and Internet Explorer).
Below are some commonly used browsers, tools, solutions, and hacks to overcome your daily issues.

Commonly Used Browsers

Want to find more? Checkout Smashing Magazine’s article.

Cross Browsing Tools

Sometimes its not possible to have a running browser with multiple versions (example: IE7 + IE6 on Same PC) so its useful to have standalone browsers to help you debug and test. Here are some tools below that may be helpful for you.
Want to find more? Checkout Smashing Magazine’s article.

Great Articles For Your Everyday CSS Fix

CSS Hacks

I hesitate sharing these hacks, because most beginners have tendencies to want to hack everything up, which leads to a nightmare in the long run. I have come a cross a few of them which I would like to share, but please use them wisely. With good XHTML/CSS structure, hacks are not needed. If all else fails, go ahead and check some of the options below.
IE Conditional Tags
<!--[if IE ]>
  <link href="iecss.css" rel="stylesheet" type="text/css">
<![endif]-->
Checkout Site Point’s Article on conditional tags for IE
IE 6 Hack
*html .classname {}
IE 6 ‘!important’ Hack
.classname {
float: left;
margin: 200px !important; /*--The !important; hack tells IE6 to skip this line.--*/
margin: 220px;
}
IE 7 Hack
*+html .classname {}
Safari Hack
html:lang(en)>body  .classname {}
Opera 7 Hack
@media all and (min-width: 0px){
.classname {}
}

CSS Hack Resources

Conclusion

As you can see, testing and making your design work in all browsers can be a pain at times, but the more you get the hang of this the smoother your work flow will be. If you have any other solutions, tools, or tricks of your own, I would love to hear about it!

Related Posts

Embedding & Styling XHTML YouTube Code

Embedding & Styling XHTML YouTube Code

Tags:
Just recently I added a couple videos under the “Artist Spotlight” posts but ran into a few invalid XHTM errors. Not only did I get the errors but I also had to style the player with CSS. I’m sure some of you may have come across similar incidents, so I thought it may be helpful to share my solution.
Original YouTube Embed Code
This is what you will get from the embed code given by YouTube.
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/gtNlQodFMi8&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/gtNlQodFMi8&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>
Which triggered these errors.

The Solution

My goal was to make the embed source valid XHTML and to allow easy styling with CSS.
Valid XHTML Youtube Embed Code
<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/gtNlQodFMi8">
 <param name="movie" value="http://www.youtube.com/v/gtNlQodFMi8" />
</object>
*Note – All you have to do is change the video ID in two places. In this example, “gtNlQodFMi8″ is the video ID.

Styling YouTube Video with CSS

Now on top of the embed code validating in XHTML, I also wanted to add a light touch of styles to make it consistent with my layout (Center aligning, padding, and border).

Step 1.

Let’s add a class name “flashvideo” to the object.
XHTML
<object class="flashvideo" type="application/x-shockwave-flash" data="http://www.youtube.com/v/gtNlQodFMi8">
 <param name="movie" value="http://www.youtube.com/v/gtNlQodFMi8" />
</object>
Add the width and height properties to our new class. Note that we left the width to 100% to make it liquid.
CSS
object.flashvideo {
 width: 100%;
 height:350px;
}

Step 2.

Now we will wrap the flash object within another class, let’s call this “flashunit”.
XHTML
<div class="flashunit">
<object class="flashvideo" type="application/x-shockwave-flash" data="http://www.youtube.com/v/gtNlQodFMi8">
 <param name="movie" value="http://www.youtube.com/v/gtNlQodFMi8" />
</object>
</div>
This parent class is where we will add our center alignment, padding, border, and fixed width.
CSS
.flashunit {
 padding: 4px;
 background: #fff;
 border: 4px solid #ddd;
 margin: 10px auto;
 width: 575px;
}

Step 3.

We will now add the title of the video and a description for it.
XHTML
<div class="flashunit">
<h2><a href="http://www.youtube.com/watch?v=gtNlQodFMi8">SonGodSuns - Minors Into Fire</a></h2>
<object class="flashvideo" type="application/x-shockwave-flash" data="http://www.youtube.com/v/gtNlQodFMi8">
 <param name="movie" value="http://www.youtube.com/v/gtNlQodFMi8" />
</object>
<p>Music video for SonGodSuns (2Mex of the Visionaries) directed by Gregory "G.Bone" Everett Ultra Wave Media. </p>
</div>
CSS
.flashunit h2 {
 font: 18px normal Arial, Helvetica, sans-serif;
 border: 1px solid #ddd;
 background: #f0f0f0;
 margin: 0;
 padding: 10px;
 color: #111;
 text-align: center;
}
.flashunit p {
 font: 12px normal Arial, Helvetica, sans-serif;
 padding: 10px;
 margin: 0;
 border: 1px solid #ddd;
 background: #f0f0f0;
}

Final Output

The following video is what you will get at the end.

SonGodSuns – Minors Into Fire

Music video for SonGodSuns (2Mex of the Visionaries) directed by Gregory “G.Bone” Everett Ultra Wave Media.
Complete Source Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Embedding &amp; Styling XHTML YouTube Code</title>

<style type="text/css">
.flashunit {
 padding: 4px;
 background: #fff;
 border: 4px solid #ddd;
 margin: 10px auto;
 width: 575px;
}
.flashunit h2 {
 font: 18px normal Arial, Helvetica, sans-serif;
 border: 1px solid #ddd;
 background: #f0f0f0;
 margin: 0;
 padding: 10px;
 color: #111;
 text-align: center;
}
.flashunit p {
 font: 12px normal Arial, Helvetica, sans-serif;
 padding: 10px;
 margin: 0;
 border: 1px solid #ddd;
 background: #f0f0f0;
}
object.flashvideo {
 width: 100%;
 height:350px;
}
</style>

</head>
<body>

<div class="flashunit">
<h2><a href="http://www.youtube.com/watch?v=gtNlQodFMi8">SonGodSuns - Minors Into Fire</a></h2>
<object class="flashvideo" type="application/x-shockwave-flash" data="http://www.youtube.com/v/gtNlQodFMi8">
 <param name="movie" value="http://www.youtube.com/v/gtNlQodFMi8" />
</object>
<p>Music video for SonGodSuns (2Mex of the Visionaries) directed by Gregory "G.Bone" Everett Ultra Wave Media. </p>
</div>

</body>
</html>
Hope this tutorial was helpful for some of you. Feel free to let me know if you have any questions or have any comments!