【问题标题】:Area Blue outlining in HTML markup?HTML标记中的蓝色区域轮廓?
【发布时间】:2017-07-28 18:33:57
【问题描述】:

我正在查看 HTML 热点,并且对我在之前的 Stack Overflow Q&A 中找到的示例有疑问。

Previous Stack OverFlow Area Example

在“Gibberish”的第一个答案中,他提供了一个关于 JSFiddle 的工作示例。 JSFiddle Example from Gibberish

function hovIn() {
  var areaID = $(this).attr('id');
  //alert('['+areaID+']');
  if (areaID == 'CUST_1') {
    $('#myDiv').show();
  }
}

function hovOut() {
  $('#myDiv').hide();
}

$('map area').hover(hovIn, hovOut);
#num_cust1 {
  padding: 10px;
  background-color: yellow;
  position: absolute;
  top: 60px;
  left: 180px;
}

#num_cust2 {
  padding: 10px;
  background-color: yellow;
  position: absolute;
  top: 60px;
  left: 40px;
}

#num_cust3 {
  padding: 10px;
  background-color: yellow;
  position: absolute;
  top: 160px;
  left: 180px;
}

#myDiv {
  display: none;
  width: 50%;
  height: 50px;
  padding: 10px;
  background-color: skyblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Instructions: Mouse over computer's monitor to see hidden DIV
<!--<img src="http://www.proprofs.com/quiz-school/upload/yuiupload/2014513384.jpg" width="400" height="400" />-->
<div id="imagemap">
  <img src="http://img716.imageshack.us/img716/8287/3ylp.jpg" width="275" height="207" usemap="#Map" border="0" />
  <map name="Map">
        <area shape="poly" coords="105,26,107,126,257,140,256,27" href="#" id="CUST_1" name="CUST:1" />
        <area shape="poly" coords="10,21,14,178,71,184,69,19" href="#" id="CUST_2" name="CUST:2" />
        <area shape="poly" coords="113,145,94,172,241,192,251,164,250,164" href="#" id="CUST_3" name="CUST:3" />
    </map>
  <p>
    <div id="myDiv">This DIV hidden unless hover over the computer's monitor</div>
  </p>
</div>
<!-- Yellow DIV ID numbers overlaid on top of computer components -->
<div id="num_cust1">1</div>
<div id="num_cust2">2</div>
<div id="num_cust3">3</div>

我了解大多数答案是如何工作的)。谁能解释他们如何/为什么在没有任何代码(我可以看到)的情况下显示为蓝色??

Fiddle 输出的屏幕截图,显示蓝色点击区域:

【问题讨论】:

  • 当您使用&lt;area&gt; 标签时,它会自动让您选择它并在其周围添加默认的蓝色边框。

标签: javascript jquery html css area


【解决方案1】:

这就是浏览器处理点击地图区域的方式,如果您在 Internet Explorer 中尝试,您会看到一条虚线。在 Chrome 中,您会收到一个蓝色轮廓,而在 FireFox 中,您不会收到!

它的处理类似于按钮。

以下 CSS 将删除轮廓:

map area{
    outline: none;
}

【讨论】:

    【解决方案2】:

    这个可以解决

    outline:none;
    

    【讨论】:

      【解决方案3】:

      ma​​p 标签用于定义客户端图像映射。图像地图是具有可点击区域的图像。

      ma​​p 元素的必需 name 属性与 img 的 usemap 属性相关联,并在图像和地图之间创建关系。

      ma​​p 元素包含许多 area 元素,它们定义了图像地图中的可点击区域。

      要隐藏轮廓,您可以这样做

      map area {
        outline: none;
      }
      <map name="primary">
        <area shape="circle" coords="75,75,75" href="#">
        <area shape="circle" coords="275,75,75" href="#">
      </map>
      <img usemap="#primary" src="http://placehold.it/350x150" alt="350 x 150 pic">

      使用outine css 属性,您可以对地图区域做很多事情。例如,您想将颜色从blue 更改为red,您可以这样做

      map area{
      outline-color: red;
      }
      <map name="primary">
        <area shape="circle" coords="75,75,75" href="#">
        <area shape="circle" coords="275,75,75" href="#">
      </map>
      <img usemap="#primary" src="http://placehold.it/350x150" alt="350 x 150 pic">

      【讨论】:

      • 感谢大家在回答我最初的问题时的回答-你们太棒了.. 有没有一种方法可以始终显示热点区域(例如,无需单击的恒定边框甚至不透明颜色填充以突出显示一个区域是可点击的)而不是仅在点击时显示???
      • @Mikeyd 如果此答案有帮助,请点赞并将其标记为正确答案。
      猜你喜欢
      • 2020-09-26
      • 2016-09-19
      • 2022-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-16
      • 1970-01-01
      相关资源
      最近更新 更多