Unwanted border around the image map area

不羁岁月 提交于 2019-12-10 13:52:31

问题


I am using an Image map with a circular area. The problem is I get an unwanted border around the area in IE7. This border doesn't appear in FF and Chrome and also in IE8/IE9.

I tried adding border="0" to the image, css properties for the anchors i.e

a{ 
border:none !important;
outline:none !important;
}

but didn't work.

I also tried adding the IE fix onfocus="blur();" in the tag. This solved the issue in IE but then FF got the border now. Searched a lot and came through this fix which said it will fix the issue for FF when IE fix is used.

#parent_div *:active, #parent_div *:focus { overflow-x:hidden; outline:none; }

But sadly even this didn't work. I am using FF 9.0.1.

Any help will be greatly appreciated. Thanks in advance.


回答1:


img{border:none;}

and this is the fix for ie versions

<!--[if lte IE 6]>
<script type="text/javascript">
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{

   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)

      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""

            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "

            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle

            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"

            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML

            i = i-1
         }
      }
   }    
}
window.attachEvent("onload", correctPNG);
</script>
<![endif]-->

try this hope it helps !!!




回答2:


This is the solution:

onclick="blur()" onfocus="navigator.appName == 'Microsoft Internet Explorer' ? blur() : null"



回答3:


You could use conditional comments (more info here) + jQuery.

HTML:

<!-- 
    "old-ie" targets IE7 or less
    "ie8" targets IE8
    "ie" targets IE8+
-->

<!--[if lt IE 8]> <html lang="en" class="old-ie"> <![endif]-->
<!--[if IE 8]> <html lang="en" class="ie ie8"> <![endif]-->
<!--[if gt IE 8]> <html lang="en" class="ie"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->

<head>
...
</head>

<body>
    <a href="#link">
        <img src="/img/image.jpg" />
    </a>
</body>

</html>

jQuery:

// we first check if current browser is IE7 or older, than apply our "hack"

if (jQuery('html').is('.old-ie') === true) {
    jQuery('a').focus(function() { jQuery(this).blur(); });
}



回答4:


Well found a way to solve this issue...which is probably not a good way to go for. By using js browser detection we can apply the IE fix as follows which will not cause problems to other browsers(FF in my case)

if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
    document.getElementsByTagName('area')[0].onfocus = function () {this.blur();};
   }

Well please, if anyone finds a better solution then do post here. Thanks.



来源:https://stackoverflow.com/questions/9030444/unwanted-border-around-the-image-map-area

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!