【问题标题】:HTML Hyperlink with Image AND Text带有图像和文本的 HTML 超链接
【发布时间】:2012-07-06 01:22:09
【问题描述】:

是否可以让超链接看起来像按钮上带有文字?

我们可以用代码制作超链接按钮:

<a href="..."> <img src="button.png" width="100" height="50" alt="Some text"></img> </a>

但我还需要按钮中心的文本。

谢谢。

【问题讨论】:

    标签: html image button text hyperlink


    【解决方案1】:

    可以将按钮设置为背景:

    <a href="..." style="text-align:center; background: url('button.png'); width: 100px; height: 50px;">Your text</a>
    

    但我会尽量避免使用带有背景图像的按钮(除非它们是奇怪的形状)。相反,我会尝试使用 CSS3。

    【讨论】:

      【解决方案2】:

      我建议,在不知道你想要什么的情况下,假设以下标记:

      <a href="#"><img src="path/to/image.png" /><span>Some text</span></a>
      
      a {
          position: relative;
          display: inline-block;
      }
      
      a span {
          position: absolute;
          top: 50%;
          left: 50%;
          margin-top: -1em;
          margin-left: -50%;
          width: 100%;
          height: 2em;
          color: #f90;
          background-color: rgba(0,0,0,0.5);
      }​
      

      JS Fiddle demo.

      【讨论】:

        【解决方案3】:

        您可以使用一些 UI 框架,例如 bootstrap 或 Flat ui 。

        <a href="#" class="btn btn-primary"> Click Me</a>
        

        【讨论】:

          猜你喜欢
          • 2023-03-26
          • 1970-01-01
          • 2018-11-20
          • 1970-01-01
          • 2014-01-07
          • 2017-05-22
          • 2013-02-10
          • 2021-09-06
          • 2017-01-07
          相关资源
          最近更新 更多