html - 如何将一个图像放在另一个图像之上

标签 html css image href

我试图在我的网站上将一个放在另一个之上 finegra.in .这是该网站目前的屏幕截图:

enter image description here

我只想在此处显示“访问我们的 kickstarter 元素”img: enter image description here

这是 html 和样式表:

<div id="page" class="hfeed">
    <header id="branding" role="banner">



            <!-- 
<nav id="access" role="navigation">
                <h3 class="assistive-text">Main menu</h3>
                                <div class="skip-link"><a class="assistive-text" href="#content" title="Skip to primary content">Skip to primary content</a></div>
                <div class="skip-link"><a class="assistive-text" href="#secondary" title="Skip to secondary content">Skip to secondary content</a></div>
                                <div class="menu"><ul><li class="current_page_item"><a href="http://www.finegra.in/" title="Home">Home</a></li></ul></div>
            </nav><!~~ #access ~~>
 -->

            <hgroup>
            <div>
                <a href="http://www.finegra.in"><img id="logo" alt="fine grain Logo" src="http://www.finegra.in/wp-content/uploads/2012/04/fineGRAINlogoGOOD-WEB.png">
</a>
<img id="headerimg" alt="The Sheffield Case" src="http://www.finegra.in/wp-content/uploads/2012/04/headerimg2.jpg">
<a href="http://www.kickstarter.com/projects/finegrain/17408941?token=364cb635"><img id="branding" alt="The Sheffield Case" src="http://www.finegra.in/wp-content/uploads/2012/04/checkOurProject.png">
</a>

            </div>
            <div id="site-generator">
                FineGrain LLC Copyright 2012. All Rights Reserved  
            </div>
        </hgroup>
    </header><!-- #branding -->

样式.css:

#branding {
    border-top: 0px solid #BBBBBB;
    padding-bottom: 10px;
    position: relative;
    z-index: 9999;
    background: none repeat scroll 0 0 #DADAD2;
}

#headerimg {
    width: 30% !important;
    width: 100% !important;
}

#branding img {
    margin-bottom: 20px;
    width: auto;
}

.one-column #page {
    max-width: 1500px;
}

.one-column #content {
    margin: 0;
    width: auto;
}

最佳答案

假设您使用的是 jQuery,您可以在 DOM 就绪函数中为您的图像创建水印,并使它们的位置绝对并相对于图像进行计算。

<script type="text/javascript">

    // Watermark image, change the src with your image's url
    var watermark = '<img src="watermark.png" border="0" style="border:none; background-color:transparent; position:absolute; ';

    // Position relative to image inside:
    var insideTop = 20;
    var insideLeft = 50;

    $(document).ready(function () {
        $("img").each(function (ix, el) {
            var top = $(this).offset().top + insideTop;
            var left = $(this).offset().left + insideLeft;
            var imgWatermark = watermark + 'top:' + top + 'px; left:' + left + 'px;"/>';
            $("body").append(imgWatermark);
        });
    });

</script>

如果您有将带有水印的图像和不带有水印的图像,请向将带有水印的图像添加属性 class="withWatermark",并将脚本中的 $("img") 替换为 $("。带水印”)。

<img src="myimage.jpg" class="withWatermark" />

$(".withWatermark").each(function (ix, el) {

关于html - 如何将一个图像放在另一个图像之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10168070/

相关文章:

java - 在保持尺寸的同时移动图像

javascript - 如何迭代选定的<select multiple>中的选项?

javascript - 如何更改悬停时的多个图像的列表

html - 我需要一些关于动态设置悬停 BG 的说明

css - iPad 上 div 垂直滚动条的问题

asp.net - 为什么异步 ASHX 生成的图像在 IE6 中并不总是有效?

html - Facebook Like Box 指定图像尺寸

javascript - 如何使用 jQuery 单独检索每个 div 的内容

javascript - offset().top 无法正常工作

javascript - 在 IE 和跨浏览器中为小书签注入(inject) CSS 文件