如何在区域上设置边框?

tim*_*mkl 5 javascript css imagemap

有没有办法围绕一个边界<area>

我需要这样做来测试一个imagemap,但这不起作用:

area {
    outline: 1px solid red;
    border: 1px solid red;
}
Run Code Online (Sandbox Code Playgroud)

Thi*_*iff 6

如果您愿意使用 Javascript,请将mouseover/mouseout事件侦听器添加到<area>元素和.focus()/.blur().

演示:http : //jsfiddle.net/ThinkingStiff/Lwnf3/

脚本:

var areas = document.getElementsByTagName( 'area' );
for( var index = 0; index < areas.length; index++ ) {    
    areas[index].addEventListener( 'mouseover', function () {this.focus();}, false );
    areas[index].addEventListener( 'mouseout', function () {this.blur();}, false );
};
Run Code Online (Sandbox Code Playgroud)

HTML:

<img id="map" src="http://thinkingstiff.com/images/matt.jpg" usemap="#map"/>
<map name="map">
    <area shape="circle" coords="50,50,50" href="#" />
    <area shape="circle" coords="100,100,50" href="#" />
</map>
Run Code Online (Sandbox Code Playgroud)

CSS:

#map {
    height: 245px;
    width: 180px;
}
Run Code Online (Sandbox Code Playgroud)