在 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;
}
答案 0 :(得分:4)
如果你真的想给予保证金权利,你可以使用这种类型的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;
}
答案 1 :(得分:1)
答案 2 :(得分:1)
为您的上一个div添加另一个类,并提及margin-right:0;
<强> MARK-UP :: 强>
<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
适用于每个具有margin-right:5px;
的div,并通过在margin-right:0;
note ::在这种情况下,必须在定义.last_circle
后定义其他样式,即.all_circles
,因为此处.last_circle
将覆盖margin属性
.all_circles