【问题标题】:How to make <img style> clickable如何使 <img style> 可点击
【发布时间】:2014-03-03 23:34:59
【问题描述】:

我正在使用以下代码:

<img style="border:2px solid #3591c0;
width:200;
height:200;
border-radius-30px;
-moz-border-radius:30px;
-khtml-border-radius:30px;
-webkit-border-radius:30px;"
src="1.jpg"/></style>

如何使这段代码中的图像可点击?

【问题讨论】:

  • 相信您可能会将 属性 style标签(元素)style 混淆。 &lt;img style=... 不会打开新的 &lt;style&gt; 标记。 &lt;img&gt; 是一个 &lt;style&gt; 另一个。反正我们看到了。 &lt;style&gt; 标签内不能有 HTML,因此 &lt;/style&gt; 不好。
  • 这有帮助。非常感谢
  • 我用下面的代码试过了,它似乎不适用于 div 标签?还有什么我可以使用的吗?
  • 你不能在 div 上使用自闭语法/&gt;。使用 this 验证您的 HTML,使用 this 验证您的 CSS。

标签: html css tags


【解决方案1】:

你可以把它放在一个锚点 &lt;a&gt; 标记中,这将使它成为一个链接。

<a>
    <img style="border:2px solid #3591c0;
    width:200;
    height:200;
    border-radius-30px;
    -moz-border-radius:30px;
    -khtml-border-radius:30px;
    -webkit-border-radius:30px;"
    src="1.jpg"/>
</a>

【讨论】:

    【解决方案2】:

    &lt;img&gt; 标记包装在&lt;a&gt; 标记中。另外,&lt;/style&gt; 也不需要。

    <a href="http://stackoverflow.com">
      <img style="border:2px solid #3591c0;
      width:200;
      height:200;
      border-radius-30px;
      -moz-border-radius:30px;
      -khtml-border-radius:30px;
      -webkit-border-radius:30px;"
      src="1.jpg"/>
    </a>
    

    【讨论】:

      【解决方案3】:

      用锚标记包围它:

      <a href="destination.html">
          <img style="border:2px solid #3591c0;
          width:200;
          height:200;
          border-radius-30px;
          -moz-border-radius:30px;
          -khtml-border-radius:30px;
          -webkit-border-radius:30px;"
          src="1.jpg"/>
      </a>
      

      其中“destination.html”是您希望将用户重定向到的文件路径或链接。是的,你不需要&lt;/style&gt; 标签。

      这一切都显示在 JSFiddle 中:http://jsfiddle.net/Mf6Dq/5/

      【讨论】:

      • 不需要&lt;/style&gt; 太弱了。这是不好的标记,因为我们不能在 &lt;style&gt; 中包含 HTML。
      • 如果它回答了你的问题,你能选择它作为“最佳答案”吗?
      猜你喜欢
      • 2015-09-13
      • 2018-03-06
      • 1970-01-01
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 2013-03-07
      相关资源
      最近更新 更多