duanjue9296 2014-06-19 12:29
浏览 59
已采纳

将2个div和1个img组合成1个img? [关闭]

I want to achieve the following:

  1. Display an image inside a <div> element.
  2. Image is served using a image-server-php (image.php) to "mask" the image location.
  3. The image should be clickable with another link opening after click.
  4. Image is hidden behind a sorry.gif to make sure that the user cannot "right click and save image".

Below is my code:

<!-- IMAGE FRAME -->
<div class="img-frame">
    <!-- CLICKABLE TO TAKE TO ANOTHER PAGE --> 
    <a href="javascript: void(0)" OnClick="window.open('page1.php'); return false;" class="img-preview" title="Click here for more info" >
        <!-- COVER IMAGE TO STOP PPL DOWNLOADING IMAGES -->
        <div class="CoverImage">
            <!-- IMAGE SERVED VIA A IMAGE-SERVER-PHP -->
            <img src="image.php?f=three.jpg" class="scale-with-grid" width="300px" height="275px" />
            <div class="cover"><img src="assets/mm/sorry.gif" class="scale-with-grid"/></div>
        </div>
        <!-- END COVER IMAGE -->    
    </a>
    <!-- END CLICKABLE -->
</div>
<!-- END IMAGE FRAME --->

Is there a way I can merge the two images into one, in the same <img> element?

I need it inside the <img> element because I use prettyPhoto for gallery creation.

  • 写回答

2条回答 默认 最新

  • dongwei7913 2014-06-19 12:32
    关注

    Hiding the image behind another one is a technique that will work only against non-technical users. Be aware of that.

    A tech-savy user will simply browse the source code of your page.

    This can be achieved by using CSS. What you want to have is two images, the one you want to serve overlayed with sorry.png with transparency set to 100%. Then the sorry.png should be linking to page1.php

    .container {
        position: relative;
    }
    .image {
        position: absolute;
        width: 100px;
        height: 100px;
        border: 1px solid red;
    }
    .imageOne {
        z-index: 0;
    }
    .imageTwo {
        z-index: 1;
    }
    
    <div class="container">
    <div class="imageOne image">
        <img src="http://placehold.it/100x100/000"></img>
    </div>
    <div class="imageTwo image"> <a href="page1.php">
        <img src="http://placehold.it/100x100/fff">
    
        </img>
        </a>
    </div>
    

    JsFiddle

    Source

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法