0

在这个jsfiddle 上 ,您可以看到我有 6 个圆圈:第一行 3 个,第二行 3 个。

我想在它们之间添加一些空间,并计划使用 margin-right: 5px。如果我这样做,问题是最后一个元素(第 3 圈和第 6 圈)的右侧也会有额外的 5px,这是我不想要的(因为它们旁边没有元素)。有解决方法吗?

我需要的是:

(圈 1) 5px 空间 (圈 2) 5px 空间 (圈 3)

谢谢

HTML:

<div class="circle circlebackground">
    <p>Circle 1</p>
    <div class="innercircle">
        <p>by Angela</p>
    </div>
</div>
<div class="circle circlebackground">
    <p>Circle 2</p>
    <div class="innercircle">
        <p>by Angela</p>
    </div>
</div>
<div class="circle circlebackground">
    <p>Circle 3</p>
    <div class="innercircle">
        <p>by Angela</p>
    </div>
</div>

<div class="circle circlebackground clear">
    <p>Circle 4</p>
    <div class="innercircle">
        <p>by Angela</p>
    </div>
</div>
<div class="circle circlebackground">
    <p>Circle 5</p>
    <div class="innercircle">
        <p>by Angela</p>
    </div>
</div>
<div class="circle circlebackground">
    <p>Circle 6</p>
    <div class="innercircle">
        <p>by Angela</p>
    </div>
</div>

CSS:

.circle {
    float: left;
    margin-bottom: 10px;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    position: relative;
    box-shadow: inset 0 0 0 16px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.1);
    -webkit-transition: all 0.4s ease-in-out;
    -moz-transition: all 0.4s ease-in-out;
    -o-transition: all 0.4s ease-in-out;
    -ms-transition: all 0.4s ease-in-out;
    transition: all 0.4s ease-in-out;
}
.circlebackground {
    background: #fff;
    border:1px solid #37629B;

}
.innercircle {
    position: absolute;
    background: red;
    width: inherit;
    height: inherit;
    border-radius: 50%;
    opacity: 0;
    -webkit-transition: all 0.4s ease-in-out;
    -moz-transition: all 0.4s ease-in-out;
    -o-transition: all 0.4s ease-in-out;
    -ms-transition: all 0.4s ease-in-out;
    transition: all 0.4s ease-in-out;
    -webkit-transform: scale(0);
    -moz-transform: scale(0);
    -o-transform: scale(0);
    -ms-transform: scale(0);
    transform: scale(0);
    -webkit-backface-visibility: hidden;
}
.circle p {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
    margin: 0;
}
.innercircle p {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
    margin: 0;
    opacity: 1;
    -webkit-transition: all 1s ease-in-out 0.4s;
    -moz-transition: all 1s ease-in-out 0.4s;
    -o-transition: all 1s ease-in-out 0.4s;
    -ms-transition: all 1s ease-in-out 0.4s;
    transition: all 1s ease-in-out 0.4s;
}
.circle:hover {
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 1px 2px rgba(0, 0, 0, 0.1);
}
.circle:hover .innercircle {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -o-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
    opacity: 1;
}
.circle:hover .innercircle p {
    opacity: 1;
}

.clear {
    clear: both;
}
4

3 回答 3

4

如果你真的想给margin-right,你可以使用这种类型的css。

.circle {
    float: left;
    margin-bottom: 10px;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    margin-left:5px;   /*added*/
    position: relative;
    box-shadow: inset 0 0 0 16px rgba(255, 255, 255, 0.6), 0 1px 2px rgba(0, 0, 0, 0.1);
    -webkit-transition: all 0.4s ease-in-out;
    -moz-transition: all 0.4s ease-in-out;
    -o-transition: all 0.4s ease-in-out;
    -ms-transition: all 0.4s ease-in-out;
    transition: all 0.4s ease-in-out;
}
.circle:nth-of-type(3n+0) {
    margin-right:0px;
}

jsfiddle链接

于 2013-09-07T13:04:22.153 回答
1

创建一个课程margin-right: 5px,并将您添加到您想要的圈子中。

这里是JSfiddle

.circle_5px_marging {
     margin-right: 5px;
}
于 2013-09-07T13:04:57.410 回答
1

为你的最后一个 div 添加另一个类并在那里提到margin-right:0;

标记::

<div class="all_circles">
</div>
<div class="all_circles">
</div>
<div class="all_circles last_circle">
</div>

CSS::

.all_circles{
  margin-right:5px;
}
.last_circle{
  margin-right:0;
}

现在在这个例子 .all_circles中适用于每个 divmargin-right:5px;并通过添加一个额外的类来更改最后一个 divmargin-right:0;

注意::在这种情况下附加样式,即.last_circle必须在定义后定义.all_circles,因为这里.last_circle会覆盖边距属性.all_circles

于 2013-09-07T13:05:50.683 回答