Welcome

This is a blog maintained by Kabindra Bakey. This blog can contains posts related to css. Here you can find some simple stuffs which may help you for better working using css. If you have any queries and suggestions regarding my posts then you can mail me KoolKabin@live.com.

Thank you,
KoolKabin

Saturday, June 26, 2010

Two columns DIV max size for the second

Here I am writing a solution for a css problem in which we have fixed width for the first left div and viariable with [max] for the second right div. The right div width should be according to the width of the container i.e
width of Right Div = Width of container - width of left div - margin
it may be when you would like to give navigation bar on left and some other content on right or view versa. it can be useful anywhere. Here we got:
1.) main container with clearfix class to fix the afterwards clear.
2.) main container has 2 div , left one with fixed width and right one with variable width.
3.) Left one uses float left to hang over on the left side where as right one uses margin to fix its width over the container.

so here is the code:


<style>
#LeftDiv{
float: left;
width: 150px;
background-color:red;
height: 150px;
}
#RightDiv{
background-color:fuchsia;
margin-left:160px;
height: 50px;
}
</style>
<div id="containerDiv" style="background-color:Lime; width: 1000px; margin: 0 auto;" class="clearfix">
<div ID="LeftDiv">
AAAA
</div>
<div ID="RightDiv">

BBBB
</div>
</div>
<div>
Here goes the footer
</div>



Enjoy...

A sample test can be done here:

ClearFix Hack Method

The clearfix hack, or “easy-clearing” hack, is a useful method of clearing floats. I have written about the original method and even suggested a few improvements. The original clearfix hack works great, but the browsers that it targets are either obsolete or well on their way. Specifically, Internet Explorer 5 for Mac is now history, so there is no reason to bother with it when using the clearfix method of clearing floats.

The original clearfix hack looks something like this:
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix { display: inline-table; }
/* Hides from IE-mac \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* End hide from IE-mac */
Yes it’s ugly, but it works very well, enabling designers to clear floats without hiding overflow and setting a width or floating (nearly) everything to get the job done. The logic behind this hack goes something like this:

  • Target compliant browsers with the first declaration block (if all browsers were standards-compliant, this would be the only thing needed) and create a hidden clearing block after the content of the target element.
  • The second declaration applies an inline-table display property, exclusively for the benefit of IE/Mac.
  • At this point, we use the comment-backslash hack to hide the remainder of the rules from IE/Mac. This enables us to do the following:
  • Apply a 1% height only to IE6 to trigger hasLayout (which is required for the hack to work)
  • Re-apply display:block to everything except IE/Mac
  • The last line is a comment that serves to close the hack for IE/Mac
As you can see, that’s a lot of fuss over a browser that has been dead for at least the last three or four years. Nobody uses IE/Mac anymore, so it is time to drop it from the clearfix hack. The result is a much cleaner and more efficient slice of CSS:
/* new clearfix */
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
* html .clearfix { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */
Stripping out that IE/Mac cruft cleans things up real nice. Notice that we have further improved the clearfix hack by adding support for IE7. Neither IE6 nor IE7 support the :after pseudo-class used in the first declaration, so we need an alternate method of applying the clearfix. Fortunately, applying zoom:1 to either browser triggers IE’s proprietary hasLayout mechanism, which works just fine to clear the float. For expediency’s sake, we accomplish this with a couple of valid browser-specific selectors, but you should be advised that conditional comments are the recommended way to go.

Fortunately, IE8 supports the :after pseudo-class, so this new clearfix method will only become more simplified as IE6 and, eventually, IE7 finally die off.

Bottom line: The new clearfix method applies clearing rules to standards-compliant browsers using the :after pseudo-class. For IE6 and IE7, the new clearfix method triggers hasLayout with some proprietary CSS. Thus, the New Clearfix method effectively clears floats in all currently used browsers without using any hacks.

Thursday, March 26, 2009

:hover not working in IE

Previously we have to use csshover.htc file in IE for making the css selector ":hover" work. But now it can simply tweak its use by defining the doctype like the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

intead of normal:
<html>

This simple tweak helps us making the :hover selector work in IE even.