In this Blog post, we have shared the simple steps to apply Rounded corner for image to support in IE browser. For this, we use .htc file (html component file) which is used to deliver non specific functionality using behavior Url. .htc file is nonstandard which uses vml, javascript and jscript.
Through .htc file, border radius does not crap the images. It only craps the background images. For rounded corner images, we use javascript to hide the four corners of the image using four images. The four images must be similar to the background color.To achieve this, we will need to copy the css content to ie.css and define new class name for images called as rounded.
Java script code:
- $(document).ready(function() {
- $('img.rounded').one('load',function () {
- varimg = $(this);
- varimg_width = img.width();
- varimg_height = img.height();
- // build wrapper
- var wrapper = $('
- ');
- wrapper.width(img_width);
- wrapper.height(img_height);
- // move CSS properties from img to wrapper
- wrapper.css('float', img.css('float'));
- img.css('float', 'none')
- wrapper.css('margin-right', img.css('margin-right'));
- img.css('margin-right', '0')
- wrapper.css('margin-left', img.css('margin-left'));
- img.css('margin-left', '0')
- wrapper.css('margin-bottom', img.css('margin-bottom'));
- img.css('margin-bottom', '0')
- wrapper.css('margin-top', img.css('margin-top'));
- img.css('margin-top', '0')
- wrapper.css('display', 'block');
- img.css('display', 'block')
- // IE6 fix (when image height or width is odd)
- if ($.browser.msie&& $.browser.version == '6.0')
- {
- if(img_width % 2 != 0)
- {
- wrapper.addClass('ie6_width')
- }
- if(img_height % 2 != 0)
- {
- wrapper.addClass('ie6_height')
- }
- }
- // wrap image
- img.wrap(wrapper);
- // add rounded corners
- img.after('
- ');
- img.after('
- ');
- img.after('
- ');
- img.after('
- ');
- }).each(function(){
- if(this.complete) $(this).trigger("load");
- });
- });
Below is the Html Code :
- <head>
- <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
- <link rel="stylesheet" href="css/styles.css"/>
- <script type="text/javascript" src="js/lib/jquery.js"></script>
- <script type="text/javascript" src="js/main.js"></script>
- </head>
- <body>
- <p>
- <imgsrc="images/01.jpg" alt="image"/>
- </p>
- </body>
Here is the link to download the Js files
Finally place the Css Code :
- .rounded_wrapper {
- position: relative;
- }
- .rounded_wrapperimg {
- border-width: 0;
- border-style: none;
- }
- .rounded_wrapper div {
- height: 7px;
- position: absolute;
- width: 100%;
- }
- .rounded_wrapper .tl {
- top: 0;
- left: 0;
- background: url(img/rounded_corners/tl.gif) no-repeat left top;
- }
- .rounded_wrapper .tr {
- top: 0;
- right: 0;
- background: url(img/rounded_corners/tr.gif) no-repeat right top;
- }
- .rounded_wrapper .br {
- bottom: 0;
- right: 0;
- background: url(img/rounded_corners/br.gif) no-repeat right bottom;
- }
- .rounded_wrapper .bl {
- bottom: 0;
- left: 0;
- background: url(img/rounded_corners/bl.gif) no-repeat left bottom;
- }
- .ie6_width .tr {
- right: -1px;
- }
- .ie6_width .br {
- right: -1px;
- }
- .ie6_height .br {
- bottom: -1px;
- }
- .ie6_height .bl {
- bottom: -1px;
- }
Finally you will get the output similar to the screenshot given below :

This entry was posted on Saturday, October 29th, 2011 at 1:17 am and is filed under CSS Tips, XHTML Templates. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.











