简体   繁体   English

将div放在智能手机图像中

[英]Position a div inside a smartphone image

I'm trying to create a slideshow embedded inside a smartphone image for my website. 我正在尝试为我的网站创建一个嵌入智能手机图像内的幻灯片。 Creating the slideshow is pretty easy using Owl Carousel . 使用Owl Carousel创建幻灯片非常简单。 What i'm unable to do is placing my div inside the phone image so that it covers all the screen, even when the image has different sizes. 我无法做的是将我的div放在手机图像中,以便它覆盖所有屏幕,即使图像大小不同。

I started by measuring the margins that I had to apply in percents, but I don't like this solution. 我开始测量我必须应用百分比的边距,但我不喜欢这个解决方案。

Is there a way to manually set the four corners of the div relatively to the image ? 有没有办法手动设置div的四个角相对于图像?

I can use jQuery 我可以使用jQuery

iphone gold

Checkout the SNIPPET below. 查看下面的SNIPPET

 $('.owl-carousel').owlCarousel({ center: true, items:1, loop:true, margin:0 }); 
 .screen .item{ background-color:#5fba7d; } .phone{ background-image: url(https://i.stack.imgur.com/vKQ2K.png); width: 320px !important; height: 650px; background-position: -25px 0; } .no-js .owl-carousel, .owl-carousel.owl-loaded { position: relative; top: 48px; width: 278px; left: 20px; height: 100%; } .owl-stage-outer, .owl-item, .item{ height:100%; } .owl-stage{ height:calc(100% - 153px); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.theme.green.min.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/owl.carousel.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.carousel.min.css" rel="stylesheet" /> <div class="phone"> <div class="owl-carousel owl-theme screen"> <div class="item"><h4>1</h4></div> <div class="item"><h4>2</h4></div> <div class="item"><h4>3</h4></div> <div class="item"><h4>4</h4></div> <div class="item"><h4>5</h4></div> </div> <div> 

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

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