2011-12-26 45 views
5

Có cách nào để đặt đường viền xung quanh <area> không?Làm cách nào để đặt đường viền trên khu vực?

tôi cần phải làm điều này để thử nghiệm một Imagemap, nhưng điều này không làm việc:

area { 
    outline: 1px solid red; 
    border: 1px solid red; 
} 
+0

lẽ plugin này giúp bạn http: //plugins.jquery. com/project/maphilight –

+0

Liên kết đó đã chết. Đây là một vấn đề khác: http://davidlynch.org/projects/maphilight/docs/ – Urbycoz

Trả lời

4

Nếu bạn sẵn sàng để sử dụng Javascript, thêm mouseover/mouseout người nghe sự kiện vào <area> yếu tố và .focus()/.blur().

Demo: http://jsfiddle.net/ThinkingStiff/Lwnf3/

Script:

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); 
}; 

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> 

CSS:

#map { 
    height: 245px; 
    width: 180px; 
} 
+1

+1 Thats một câu trả lời rất gọn gàng! Tks. Đã học một kỹ thuật mới ngay hôm nay. – techfoobar

+0

Tôi cũng vậy! Thx giúp đỡ! : D – timkl

Các vấn đề liên quan