首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >绝对内相对定位

绝对内相对定位
EN

Stack Overflow用户
提问于 2013-03-29 00:38:24
回答 3查看 2.1K关注 0票数 4

我使用的是100%宽度相对定位,但是需要一个绝对定位的子div或span来保持jquery图像滑块。

布局

-宽度为100%

img1 +滑块+ img2 _x

当前,滑块跨度没有像其他对象那样被内联地放置和重叠。

到目前为止我所拥有的是:

小提琴

代码语言:javascript
复制
<div class="pic_container">
    <img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">  
    <span class="viewer"> 
       <img src="http://images.printsplace.co.uk/Content/Images/Products/46576/43569/Image_of_M101_1.jpg" alt="" class="active" />
        <img src="http://i.bosity.com/clothes_cache/261/12002348/3480000011312473207_12002348_1_image.jpg" alt="" />
        <img src="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-6.jpg" alt="" />
    </span>
    <img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
</div>

</div>

CSS

代码语言:javascript
复制
/*slideshow*/

.viewer {
    font-size:0;
  display:inline;
}

.viewer IMG {
    position:absolute;

    z-index:8;
    width:50%;
  vertical-align:top;
}

.viewer IMG.active {
    z-index:10;
}

.viewer IMG.last-active {
    z-index:9;
}


/*pics*/

.pic_container{
    font-size:0;
    display:inline;

    }


 .pic_container img {

    width:25%;
  vertical-align:top;
 }
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-03-29 03:09:32

我为查看器添加了一个包装器,并使用html注释标记删除了外部图像与幻灯片查看器之间的额外间隔(这比设置字体大小:0要好)。我调整了JS,这样过渡就能工作了。我还清理并减少了所需的CSS数量。

代码语言:javascript
复制
<div class="picture-container">
    <img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg" /><!--
        --><div class="viewer">
        <img src="http://images.printsplace.co.uk/Content/Images/Products/46576/43569/Image_of_M101_1.jpg" class="active" />
        <img src="http://i.bosity.com/clothes_cache/261/12002348/3480000011312473207_12002348_1_image.jpg" />
        <img src="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-6.jpg" /> 
        </div><!--
    --><img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg" />
</div>

CSS:

代码语言:javascript
复制
* {margin:0;padding:0}
.picture-container > img {display:inline-block;width:25%;}
.viewer {display:inline-block;position:relative;width:50%;vertical-align:top;}
.viewer img {position:absolute;width:100%;}

JS

代码语言:javascript
复制
function slideSwitch() {
  var transitionDuration = 1000;
    var active = $('.viewer img.active');
    var next = $('.viewer img:first').insertAfter(active);
    active.removeClass('active').fadeOut(transitionDuration);
    next.addClass('active').hide().fadeIn(transitionDuration);
}
$(document).ready(function(){
    $('.viewer img.active').insertAfter('.viewer img:last');
    setInterval("slideSwitch()", 4000);
});

你可以在这里看到它:http://jsfiddle.net/Ry7Su/1/

希望这能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2013-03-29 02:35:17

以下更改将解决您的问题。

这是基于你的代码。你可以调整它使它更短。

HTML部件:

代码语言:javascript
复制
<div class="pic_container">
     <div class="leftDiv">
        <img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">  
     </div><!--
  --><div class="viewerWrapper"><div class="viewer">
        <img src="http://images.printsplace.co.uk/Content/Images/Products/46576/43569/Image_of_M101_1.jpg" alt="" class="active" />
        <img src="http://i.bosity.com/clothes_cache/261/12002348/3480000011312473207_12002348_1_image.jpg" alt="" />
        <img src="http://lokeshdhakar.com/projects/lightbox2/images/examples/image-6.jpg" alt="" />
     </div></div><!--
  --><div class="rightDiv">
        <img src="http://www.image-and-text.com/pictures/whiskey_with_ice.jpg">
     </div>
</div>

CSS部分:

代码语言:javascript
复制
.pic_container {
    display: block;
    width: 100%;
    position:relative;
    }
.leftDiv {
    display:inline-block;
    width: 25%;
    position:relative;
}
.rightDiv {
    display:inline-block;
    width: 25%;
    position:relative;
}
.viewerWrapper {
    display:inline-block;
    width: 50%;
    position:relative;
    vertical-align: top;
}
.viewer {
    width:100%;
}
.leftDiv IMG, .rightDiv IMG, .viewer IMG {
    max-width: 100%;
}
.viewer IMG {
    z-index:8;
    position: absolute;
}
.viewer IMG.active {
    z-index:10;
}
.viewer IMG.last-active {
    z-index:9;
}

请看这里:http://jsfiddle.net/FTEan/

票数 0
EN

Stack Overflow用户

发布于 2013-03-29 04:18:20

尝试给pic_container position: relative;,并尝试给viewer display: inline-block;,这可能是可行的。pic_container也可能是display: inline-block;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15694589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档