【问题标题】:How to download an image in HTML using a button如何使用按钮下载 HTML 格式的图像
【发布时间】:2019-07-14 22:42:01
【问题描述】:

我的 PHP 和 HTML 网页中有一个图库,我想单击一个按钮,然后下载作为 div 背景发布的图像。这里的一个 div 对应一个图像,它包含在主 div 中。 将鼠标悬停在以图像为背景的 div 上后会显示下载按钮

代码是这样的,包括我的试验:

<div class="row">
  <div class="col-md-4 col-sm-4 text-center animate-box">
    <div
      class="work-grid"
      id="logosera"
      style="background-image: url(images/logo-biocentru.png);"
    >
      <img id="logosera" src="images/logo-biocentru.png" style="display:none" />
      <div class="desc">
        <h3><a href="#">Carti vizita</a></h3>
        <span class="cat">Graphic Design</span>
        <p>
          <span class="download">
            <a href="#logosera" download="biocentru.png">
              <i class="icon-download"></i>
            </a>
          </span>
          <span class="love">
            <a href="#"><i class="icon-heart"></i></a>
          </span>
        </p>
      </div>
    </div>
  </div>
</div>

看起来像这样:

image before hover

image after hover

【问题讨论】:

标签: php html css image download


【解决方案1】:

将图片文件路径放在href标签中:

<span class="download">
    <a href="biocentru.png" download="biocentru.png">
        <i class="icon-download"></i>
    </a>
</span>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-18
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 1970-01-01
    • 2019-08-09
    • 2014-07-27
    相关资源
    最近更新 更多