2013-05-03 36 views
1

我在一个大小为300px的div中有一个图像,并且我希望图像任一侧的下一个和上一个箭头。然而,有一个额外的问题是,如果屏幕是300像素,我希望箭头位于图像的顶部。如何才能做到这一点?在图像的任一侧放置下一个和上一个箭头

我的div代码如下:

<!--this div is the container for the carousel --> 
<div id='mySwipe' style='max-width:300px; margin:0 auto' class='swipe'> 
    <!--the images are in this div --> 
    <div class='swipe-wrap'id="featured"> 
    </div> 
</div> 
+0

你应该用float来管理:left和float:right – nicolas 2013-05-03 01:16:56

回答

2
.container { position: relative; } 

.container .arrow { position: absolute; top: 150px; } 

.container .arrow.left { left: 0; } 

.container .arrow.right { right: 0; } 

通过相对定位设置父(默认为static)和绝对定位的孩子,他们将是相对于他们的父母是绝对的。

+0

会尽快试用'.container'是要添加到容器中的类是否正确? – 2013-05-03 01:32:51

+0

@KernElliott'.container'只是一个示例类。只要你遵循结构,你可以使用任何你想要的选择器。 – Jared 2013-05-03 02:21:16

相关问题