[英]CSS Positioning - Fixed Centre - Fixed Left & Fixed Right Elements
I have the following structure for a slide within a site created for an iPad 我为iPad创建的网站内的幻灯片具有以下结构
<div id="slide4">
<div class="slide4A1"></div>
<div class="slide4A2"></div>
<div class="slide4A3"></div>
</div>
Each block contains background images which are controlled via media queries to allow them to fill the screen whether the Ipad is portrait or landscape. 每个块都包含通过媒体查询控制的背景图像,无论Ipad是纵向还是横向,都可以通过它们填充屏幕。
I need to animate the blocks but want the positions to be as follows - 我需要为块设置动画,但希望位置如下:
.slide4A1 - fixed left .slide4A2 - fixed centre .slide4A3 - fixed right .slide4A1-固定左.slide4A2-固定中心.slide4A3-右固定
I have tried floating left and right for slides 1 and 3 and centering with auto margin- but the layout go's astray - any ideas? 我尝试过为幻灯片1和幻灯片3左右浮动,并以自动页边距居中-但布局误入歧途-有什么想法吗?
js fiddle here - http://jsfiddle.net/chunk_pd/PAqSb/6/ js拨弄这里-http://jsfiddle.net/chunk_pd/PAqSb/6/
I believe this is what you expected to see: 我相信这是您期望看到的:
CSS: CSS:
#slide4 {position: relative; }
.slide4A1, .slide4A3{ position:absolute; top: 0; }
.slide4A1{background:#000; width:120px; height:1024px; left:-120px;}
.slide4A2{background:#367ab2; width:531px; height:1024px; margin-left:auto; margin-right:auto; position:relative!important; display: none;}
.slide4A3{background:#ff7e00; width:120px; height:1024px; right:-120px;}
JS: JS:
function goDown3bPt2(){
$('.slide4A1').animate({left:'0',}, 1600);
$('.slide4A2').fadeIn('slow');
$('.slide4A3').animate({right:'0',}, 2100);
}
First you have to clean your CSS - combining position: absolute;
首先,您必须清理CSS-组合
position: absolute;
and float
won't work. 和
float
将无法正常工作。 Use your wrapper <div id="slide4">
and set its positioning as relative and width: 100%
. 使用包装器
<div id="slide4">
并将其位置设置为相对和width: 100%
。 Both animated divs have to have position: absolute; top: 0px;
两个动画div都必须具有以下
position: absolute; top: 0px;
position: absolute; top: 0px;
in order to reach top of the wrapper. 为了达到包装的顶部。
What is more - you have a typo in your JS: 更重要的是-您的JS中有错字:
$('.slide4A1').animate({left:'0px;',}, 1600);
just remove ; 只是移开; after
0px
and voila. 在
0px
和voila之后。
Apply width :100%, margin:0 auto to slide4 width :33 % to slide4A1,slide4A2,slide4A3 将宽度:100%,边距:0自动应用于幻灯片4宽度:33%,应用于slide4A1,slide4A2,slide4A3
Float Left to slide4A1 and float right to slide4A3 classes....!! 向左浮动到slide4A1,向右浮动到slide4A3类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.