2012-07-11 149 views
6

我有我想覆盖三个图像(用HTML + CSS,我做要使用JavaScript如果可能的话):覆盖多个图像

image1image2image3

这是结果,我想实现: My preferred result
[图像4]

这是我曾尝试:

CSS:

.imageContainer { 
    position: relative; 
} 

#image1 { 
    position: absolute; 
    top: 0; 
    z-index: 10; 

    border: 1px solid blue; 
} 
#image2 { 
    position: absolute; 
    top: 0; 
    z-index: 100; 

    border: 1px solid fuchsia; 
} 
#image3 { 
    position: absolute; 
    top: 0; 
    z-index: 1000; 

    width: 10%; 
    height: 10%; 

    border: 1px solid green; 
} 

HTML:

<div class="imageContainer"> 
    <img id="image1" src="http://i.stack.imgur.com/Es4OT.png"/> 
    <img id="image2" src="http://i.stack.imgur.com/WQSuc.png"/> 
    <img id="image3" src="http://i.stack.imgur.com/Xebnp.png"/> 
</div>​ 

image1的: “主” 图像(图像1应该设置最大高度和用于imageContainer最大宽度 - 上述SE HTML) [蓝色边界]
IMAGE2horizontal-align: center;top: 0;相对于IMAGE1 [粉红边界]
图像3:从原点尺寸由10%调整,horizontal-align: center;相对于图像1 [绿色边框]

我容易出错的HTML + CSS导致了这一点: enter image description here

我无法弄清楚如何我的CSS应该是。我应该怎么做才能达到[image4]的效果?

+0

您需要哪些浏览器支持? – steveax 2012-07-11 23:44:30

+0

尽可能多的但如果我必须选择:FF和Chrome – 2012-07-11 23:56:34

+0

您的z-index对于任何元素在哪里?您可以将它们添加到 – Lawrence 2012-07-12 04:19:53

回答

5

您可以更新代码再次图像旋转transperancy问题 更新的代码透明

图像有一个股利和更多的背景,例如使其:

#someDiv 
{ 
    background: url('topImage.jpg') center, 
      url('imageInTheMiddle.jpg') 0px 0px, 
      url('bottomImage.jpg') /*some position*/; 
} 

这是迪更简单的方法展开它。当然,在我放置定位值的地方,您必须添加一个定位值。

UPDATE

在你之后说的话,我想你可以使用3周绝对定位的div你的背景和使用CSS3属性transform操纵它们。它使您可以旋转,缩放和更多与您的元素。你也可以用JavaScript来操作它。

More info about css3 transform

+0

感谢您的回答!它绝对没有错,但我需要访问量角器图像([image2]与我的命名约定)。为什么?首选结果[image4]显示了一项主要任务的简化部分:量角器应能够旋转。在下一步中,我将使用该行为来指示监控摄像机的当前转角。 是否可以通过您的建议以任何方式访问imageInTheMiddle.jpg? – 2012-07-12 06:08:12

+2

Whaa?我不知道你可以放多个url()。真棒。 – ThinkingStiff 2012-07-12 06:17:25

+0

@ThinkingStiff谢谢:) – 2012-07-12 06:24:26

1

让我申请图像旋转的量角器图像(图像2) 希望帮助你

<style type="text/css"> 
    .imageContainer { 
     position: relative; 
     width:165px; 
     height:169px; 
    } 

    #image1 { 
     position: absolute; 
     top: 0; 
     z-index: 10; 
     width:120px; 
     height:120px; 
     border: 1px solid blue; 
    } 
    #image2 { 
     position: absolute; 
     top: 0; 
     z-index: 20; 
     border: 1px solid fuchsia; 
     opacity:0.6; 
    filter:alpha(opacity=60); /* For IE8 and earlier */ 


    /*for adding image rotation */ 
     -webkit-transform: rotate(90deg); /*//For chrome and safari*/ 
     -moz-transform: rotate(90deg); /*//For ff*/ 
     filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1); /*// For ie */ 
    /* End for adding image rotation */ 



    } 
    #image3 { 
     position: absolute; 
     top: 0; 
     z-index: 30; 
     width: 40%; 
     height: 40%; 
     border: 1px solid green; 
     left:70px; 
     opacity:0.9; 
    filter:alpha(opacity=90); /* For IE8 and earlier */ 


    } 

    </style> 






    <form name="frmabc" action="" method="post"> 
<div class="imageContainer"> 
    <img id="image1" src="Es4OT.png"/> 
    <img id="image2" src="WQSuc.png" /> 
    <img id="image3" src="Xebnp.png" /> 
</div> 
</form> 
+0

是否有可能避免修复[image1]或[image1]上的'width'和'height'。 [image3]并使用'%'这样的相对变体(所有与[image1]相关的变体)? – 2012-07-12 06:20:46

+1

你的意思是说根据时钟图像?因为时钟图像的尺寸比其他图像多。如果您将时钟图像的尺寸标注给.imageContainer。您将能够以%为单位设置其他图像的其余部分的尺寸。我更新了上面的代码。 – Parag 2012-07-12 06:36:18

+0

那么,最后一个问题(我在原始问题中没有提到)是指示监视摄像机当前的转角。 所有这些都可以在普通浏览器(大屏幕)**和**智能手机(小屏幕)下工作。这就是为什么我不想在像素前使用%。 ----- 我将为此拍摄三张照片:一张监控图像(由上面的蝴蝶图像描绘),一张量角器图像和一张箭头图像。监控图像每秒通过javascript更新,量角器角度取决于相机的位置,箭头始终指向上方。 – 2012-07-12 06:51:01