Productivedreams.com ProductiveDreams - Everything that web designers need, owned by Gopal Raju

A blog to keep you updated on the latest design trends.
RSS

Posts Tagged ‘CSS’

A simple CSS based usability tip for search buttons

This is a small tip to improve the usability of search fields. I realized the need of this while working on a recent project and thought it was good enough to share with my readers :)

Do you have the habit of hitting the search button multiple times even before it loads the search results? Well… I used to do that and so do many other users. Clicking the search button multiple times results in additional server requests and slows down the page’s loading time.

Why do users click again?

Because they are users! They aren’t developers who understand what happens in the back end.

Its our job as developers/designers to let the user know that the results are being loaded and to ask them to wait until it loads.

How do I do it with just CSS?

Its pretty simple. Click and hold the search button below and see.

(more…)

10 CSS properties that ‘were’ impossible to implement in IE6

Personally I hate IE6, and never wanted to support it. Unfortunately, a percentage of internet users still use IE6. Sometimes even customers get insistent about how their page should look in IE6. Anyways, let’s hope IE dies soon!

10 IE6 CSS Hacks

This post is about 10 commonly used css properties that were impossible to implement in IE6. While redesigning ProductiveDreams, I came across a few css compatibility issues with IE6 and had to spend hours searching the solution for each issue.

So I just thought of putting them together to save your time. These css hacks (I would rather call them ’solutions’ since, not all of them are purely css based) solves the major compatibility issues in IE6.

1. Rounded or Curved Corners

As you would know, all modern browsers support border radius. Curved corner is something that was merely impossible to achieve in IE6. Recently I came across an htc file (especially for IE) developed by Remiz from HTMLRemix.com, which solves this issue.

The first thing to do while using htc is to add the correct MIME type for htc behavior on your server. This is REALLY important before you proceed. The following are steps:

1. Go to your cpanel and click the MIME Types link
2. Under MIME Type, add text/x-component
3. Under Extensions, add htc
4. Restart Apache Web server

For more details on how to add MIME type visit Microsoft Support

All you need to do is download the htc from HTMLremix or Alternate Link and include the following code in your CSS.

CSS
1
2
.div_class_name{
3
behavior:url(border-radius.htc);
4
}
5

Jquery Alternative: jQuery Corner a jQuery plugin that creates crossbrowser compatible rounded corners!

2. The popular PNG transparency issue

Every designer would have faced this issue, obviously! Though there are a number of javascript based solutions, I couldn't find anything that supports background position. As far as I know all JS based solutions end up with the same result. This is something that worked flawlessly for me. All other solutions are based on this filter.

CSS
1
2
.class_name{
3
_background:none;
4
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src='image_name.png', sizingMethod='scale');
5
}
6

HTC Alternative:If the solution above doesn't work for you, you may try this htc alternate.

Known Issues:
1. Doesn't support CSS Sprites: If you are using sprites, then just forget this hack. Background positions doesn't work with PNG hacks .

If you need background-position support for PNG, then go for DD_belated

The best solution is to use a .gif or png-8. Check out the best way to do this without using hacks!

3. Opacity

This is pretty much straight forward and easy to achieve compared to the other hacks.

CSS
1
2
.opacity_div {
3
  filter: alpha(opacity = 50);
4
}
5

4. Fixed position

All browsers support the css property 'position:fixed', but not IE6. I had to find a solution for this since the social icons in this blog are having a fixed position.

CSS
1
2
* html .fixed_div{ 
3
position: absolute; /* position fixed for IE6 */ 
4
top: expression(104+((e=document.documentElement.scrollTop)?e:document.body.scrollTop)+'px'); 
5
left: expression(15+((e=document.documentElement.scrollLeft)?e:document.body.scrollLeft)+'px'); 
6
} 
7

Just change the top(104) and left(15) values, to position the element.

This method works very well, but you would notice a jerk while scrolling the page. So here goes a fix for that.

CSS
1
2
* html { 
3
background-image: url(image.jpg); 
4
} 
5

All you need is a 1px x 1px image. This might sound weird but it works!

5. Min-width & Max-width

This is simple as well and was already posted on ProductiveDreams

Min-width:
CSS
1
2
.div_class_name{
3
width: expression(document.body.clientWidth < 1000? "1000px" : "auto");
4
}
5
Max-width:
CSS
1
2
.div_class_name{
3
width: expression(document.body.clientWidth > 1000? "1000px" : "auto");
4
}
5

Jquery Alternative: This is an alternative solution for the hack above. JQminmax is a cool plugin which allows you to set minimum and maximum values for both width and height.

6. Hover for non anchor elements

Unfortunately, IE6 supports :hover, only for anchor tags. That means css based dropdowns would not work in IE6. CSShover.htc is the best solution for this. You may download the htc file from xs4all.nl

CSS
1
2
body { 
3
behavior: url("csshover3.htc"); 
4
} 
5

As I mentioned previously, don't forget to add the correct MIME type for htc behavior on your server. This is the key.

7. Min-height & Max-height

Minimum height:

This is not really a hack since it uses valid css.

CSS
1
2
.div_class_name{
3
min-height: 140px;
4
height: auto !important;
5
height: 140px;
6
}
7
Maximum height:
CSS
1
2
.div_class_name{
3
 height: expression( this.scrollHeight > 199 ? "200px" : "auto" );
4
}
5

8. Bicubic scaling for images

One line code that solves the image scaling issue in IE6 and 7. Hats off to Chris Coyier for coming up with this solution.

CSS
1
2
img {
3
 -ms-interpolation-mode: bicubic; 
4
}
5

9. Negative text indent for input buttons

Negative text indent is normally used to hide the text value inside buttons, which lets you use custom background images for them. For some reason, IE doesn't support negative text indent for input buttons. For more details about this issue check out this post

CSS
01
02
input.button {
03
width:114px;
04
height:37px;
05
border: none;
06
background: transparent url(images/button_image.gif) no-repeat center;
07
overflow: hidden;
08
text-indent: -999px;
09
}
10

10. Text shadow

The shadow filter is one of the useful filters for IE.

CSS
1
2
.text_shadow{
3
filter: Shadow(Color=#999999, Direction=135, Strength=5);
4
height: 1%;
5
}
6
We offer complete collection of practice questions and answers for all networking credentials including ccna voice, ccnp and ccie.

IE not interpreting text-indent on submit buttons ?

Filed Under
I’ve worked on many projects where in I had to style the form/input buttons using custom background images. That is, I had to hide the default text of the button. It’s not a big deal, I know. But it is, when it comes to IE. Let’s review this in detail.

The following image(button background) has been used for this tutorial. You may right click and save it.

Sample Image

1: HTML Code

Create a HTML page and insert a button with a class, “button”.
HTML
01
02
<html>
03
<head>
04
<title>ProductiveDreams</title>
05
<link href=”style.css” rel=”stylesheet” type=”text/css”/>
06
</head>
07
<body>
08
<input type=”submit” value=”Submit” class=”button”>
09
</body>
10
</html>
11

2: Style Sheet

I included the following in my stylesheet.
CSS
01
02
input.button {
03
width:114px;
04
height:37px;
05
border: none;
06
background: transparent url(images/submit_btn.gif) no-repeat center;
07
overflow: hidden;
08
text-indent: -999px;
09
}
10
Fixed width, overflow:hidden and negative text indent will hide the text of any button. This works well in all browsers except IE.

3: The Problem

The image below shows how IE displays the button.

IE Issue

You can see the black text within the button which looks odd.

4: IE Fix

So finally, here goes the three line CSS code that does the work for you.
Modify your CSS as shown below.
CSS
01
02
input.button{
03
width:114px;
04
height:37px;
05
border: none;
06
background: transparent url(images/submit_btn.gif) no-repeat center;
07
overflow: hidden;
08
text-indent: -999px;
09
 
10
font-size: 0;
11
display:block;
12
line-height: 0;
13
}

5: How it works

Let's see how it works.

font-size:0 is used to reduce the font size and works well in IE7. But even after adding this line, you would notice a black line(which is basically the text) on the center of the button in IE6.

display:block Negative text-indent works in IE only if this is added.

line-height: 0 Another fix for IE6.

I have included the sample files for your reference.

Download IE text-indent issue Version 1.0
No matter you are interested in ccda or ccvp, pass your networking exam in days using our ccde dumps and other networking resources.

IE CSS hack without using any hacks!

Filed Under

A few days back while working for a MAJOR client (sorry, can’t mention their name), I discovered something new (I hope it’s new ) – A pure CSS based image replacement solution for IE. This method is helpful especially to solve the PNG issue in IE6. I know there are many CSS hacks available out there to solve the PNG transparency issue, but this method doesn’t need any hacks!! Interesting isn’t it?

Step-1: Let’s review the HTML part first.

HTML
01
02
<html>
03
 
04
<head>
05
<title>ProductiveDreams</title>
06
<link href=”style.css” rel=”stylesheet” type=”text/css”/>
07
</head>
08
 
09
<body>
10
<div class=”bg-image”></div>
11
</body>
12
 
13
</html>
14
The following are the images that I've used for this tutorial. The image without saturation is a .gif and the colored one is a .png. You may right click and save the image.

PNG Image

Colorful PNG Image



Desaturated GIF Image

Desaturated GIF Image


Step-2: The stylesheet

I included the following code in the stylesheet
CSS
01
body{
02
background:#000;
03
text-align:center;
04
}
05
 
06
div.bg-image{
07
background:transparent url(images/pd.png) no-repeat center !important;
08
width:134px;
09
height:134px;
10
}
Let me walk you through the CSS. The first part simply applies a background color to the body and center aligns the div element. In the second part, I've specified the width and height of the div (134px) based on the image dimensions and have given the .png as the background image. Everything works fine?

Step-3: Solution for IE

This the most interesting part that does the magic.

I added another line of CSS code just below
background:transparent url(images/pd.png) no-repeat center !important;
and the following is the code
background-image:url(images/pd.gif);

Check out the result in IE! Awesome.... isn't it? In all other browsers except IE you will see the colorful png image.

Consolidating the entire thing

So. the final css would look like:
CSS
01
body{
02
background:#000;
03
text-align:center;
04
}
05
 
06
div.bg-image{
07
background:transparent url(images/pd.png) no-repeat center !important;
08
background-image:url(images/pd.gif);
09
width:134px;
10
height:134px;
11
margin:0px auto;
12
}

For your ease, I have attached the sample files as a zip. Feel free to download it :) and do let me know your feedbacks.

Download CSS Solution for image replacement