我有这个例子:
这是代码HTMl:
<div class="wrap">
<div class="wrap1">
<div class="image1">This is some text</div>
<div class="image2">This is some text</div>
<div class="image3">This is some text</div>
</div>
<div class="image4">This is some text</div>
<div class="image5">This is some text</div>
</div>
这是代码CSS:
.image1,.image2,.image3{
display: inline-block;
height: 200px;
width: 200px;
background: url(http://placekitten.com/g/300/300);
margin-left:auto;
}
.image4,.image5
{
display: inline-block;
height: 200px;
width: 200px;
background: url(http://placekitten.com/g/300/300);
}
.wrap1{
margin-left:auto;
margin-right:auto;
}
.wrap
{ border:1px solid;
width:700px;
}
如何将图像对齐?
我希望所有图像都在正方形中间对齐,边框
答案 0 :(得分:1)
根据我的理解,你需要所有图像到边框的中心。
在包装类中使用text-align:center
:
.wrap
{ border:1px solid;
width:700px;
text-align: center;
}
检查Fiddle。
答案 1 :(得分:1)
试试这个......
.image{
display: inline-block;
height: 200px;
width: 200px;
background: url(http://placekitten.com/g/300/300);
margin-left:auto;
}
.wrap
{
border:1px solid;
width:700px;
text-align: center;
}
<div class="wrap">
<div class="wrap1">
<div class="image">This is some text</div>
<div class="image">This is some text</div>
<div class="image">This is some text</div>
</div>
<div class="image">This is some text</div>
<div class="image">This is some text</div>
</div>
答案 2 :(得分:0)