简体   繁体   English

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

[英]How can I put an image on top of another image?

I have seen a few that explains how to do it with absolute position. 我已经看到一些解释如何使用绝对位置进行操作的信息。 I'm currently making a Bootstrap 3 site, so I cannot use the absolute attribute. 我目前正在建立Bootstrap 3网站,因此无法使用absolute属性。

Below is a quick mock-up of what I'm talking about (note that the play buttons won't be burned into the images below) 以下是我所谈论内容的快速模型(请注意,播放按钮不会被烧入下面的图像中)

小样

Also, if you could explain how to make a similar gradient, it would be nice. 另外,如果您可以解释如何制作相似的渐变,那将是很好的。

I have tried to use the z-index attribute, but when using it I couldn't figure out how to position the elements relative to elements with lower z-indexes. 我尝试使用z-index属性,但是使用它时,我不知道如何相对于具有较低z-indexes的元素定位元素。

Edit: The play-button (seen on top of the images) will not be a part of the jpg image asset. 编辑:播放按钮(在图像顶部)不会成为jpg图像资产的一部分。 Rather, it will be its own svg asset put on top of the jpg (thumbnail) image. 而是将其自身的svg资产放在jpg(缩略图)图像的顶部。 I choose this way so that I can animate the "play-button" independently. 我选择这种方式,以便可以独立为“播放按钮”制作动画。

Neither will the gradient, title, subtitle or "article-tag" be a part of the thumbnail image asset. 渐变,标题,副标题或“文章标签”都不是缩略图资源的一部分。

The red "divider's" will be its own svg asset as well. 红色的“分隔符”也将是其自己的svg资产。

Ideally, I would like to be able to place <img></img> objects on top of another <img></img> bounding box and be able to move it relative to the bounding box. 理想情况下,我希望能够将<img></img>对象放置在另一个<img></img>边界框之上,并能够相对于边界框进行移动。 eg x=50% y=50% for centering. 例如,x = 50%y = 50%用于居中。 The method should be scalable so that I can have more than two layers as well as having multiple objects on the same layer. 该方法应该是可伸缩的,这样我可以有两个以上的层,并且在同一层上可以有多个对象。

Note: The thumbnail images will be stored on the web server in a resolution of 1920x1080. 注意:缩略图将以1920x1080的分辨率存储在Web服务器上。 When trying to use the "divider" as a background image I had a clipping issue: 尝试使用“分隔线”作为背景图像时,出现裁剪问题:

在此处输入图片说明

It wouldn't expand its parent <div> . 它不会扩展其父<div> (also, is there a way to detect user's screen size and rescale the pictures accordingly (on the server) in order to increase loading speed? Like a cookie or something?) (另外,是否有一种方法可以检测用户的屏幕尺寸并相应地(在服务器上)重新缩放图片以提高加载速度?例如cookie或其他东西?)

I'm sorry for probably breaking tons of rules on the site, this is my first question. 我很抱歉可能违反了网站上的大量规则,这是我的第一个问题。

regarding the gradient, a short css writing will be: 关于渐变,简短的CSS文字将是:

background: -webkit-linear-gradient(135deg, #a11633 45%, #7D1229 48%, #7D1229 20%);

In addition: I've created a JSFiddle for you for the layouting :) 另外:我为布局创建了一个JSFiddle :)

HTML: HTML:

<div class="relative-container">
  <div class="absolute-container">
    <div class="flex-1">
    Img 1
    </div>
    <div class="flex-1">
    Img 2
    </div>
    <div class="flex-1">
    Img 3
    </div>
  </div>
</div>

CSS: CSS:

.relative-container{
  width:300px;
  height:200px;
  background: -webkit-linear-gradient(135deg, #a11633 45%, #7D1229 48%, #7D1229 20%);
}

.absolute-container{
  width:300px;
  height:100px;
  display:flex;
  align-items: center;
  position:absolute;
  top:55px;
}

.flex-1{
  flex:1;
  border:1px dashed black;
  text-align:center;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM