定位绝对并排CSS

时间:2014-11-25 09:46:12

标签: html css

我正面临着关于像这张图片一样放置气球的问题:

enter image description here

    <div class="red_frame">
    <img src="http://i.stack.imgur.com/54SMF.png"  class="r_over"/>
    <img src="http://i.stack.imgur.com/54SMF.png"  class="r_over"/>
        <img src="http://i.stack.imgur.com/54SMF.png"  class="r_over"/>
        <img src="http://i.stack.imgur.com/54SMF.png"  class="r_over"/>
        <img src="http://i.stack.imgur.com/54SMF.png"  class="r_over"/>
        <img src="http://i.stack.imgur.com/54SMF.png"  class="r_over"/>
        <img src="http://i.stack.imgur.com/54SMF.png"  class="r_over"/>
    </div>
.red_frame {
float: left;
width: 143px;
height: 346px;
margin: 0 2px 0 0;
position: relative;
}

.r_over
{position: relative;
right: 29px;}

小提琴链接 http://jsfiddle.net/fddkdvn4/

4 个答案:

答案 0 :(得分:2)

你几乎要亲自解决。

使用位置是一种很好的方法,但对于此解决方案,您只需要margin-left: -10px

.red_frame {
  float: left;
  width: 143px;
  height: 346px;
  margin: 0 2px 0 0;
  position: relative;
}
.r_over {
  position: relative;
  right: 29px;
  margin-left: -10px;
}
<div class="red_frame">
  <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
  <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
  <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
  <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
  <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
  <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
  <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
</div>

答案 1 :(得分:1)

使用

DEMO

<强> CSS

.red_frame {
float: left;
width: 143px;
height: 346px;
margin: 0 2px 0 0;
position: absolute;
}

.r_over
{margin-left:-10px;
}

答案 2 :(得分:1)

margin-left: -10px;中添加.r_over{},但删除postion:relative;right:29px;

答案 3 :(得分:1)

负边距是最简单的方法。但是,请确保使用:not(:first-child)选择器,否则第一张图片也会获得负边距。

<强> 段:

.red_frame {
    width: 143px; height: 346px; margin: 8px;
}
.r_over:not(:first-child) {
    margin-left: -10px;
}
<div class="red_frame">
    <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
    <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
    <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
    <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
    <img src="http://i.stack.imgur.com/54SMF.png" class="r_over" />
</div>