我的页面具有一个div内3个格(一个或多个)。在平板电脑和桌面屏幕上,它们看起来不错(中心对齐),但是在像手机这样的非常小的设备上,内部div对齐(我希望它们水平居中对齐)。我将文本中心和中心块应用到外部div,但它不起作用。任何建议?这里是html和css代码。水平居中多个div在小型设备一个div内(XS)
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
portfolio-caption {
max-width: 281px;
background-color: #994ACC;
text-align: center;
padding: 10px;
border-top: 3px solid #ffffff;
margin-bottom: 10px;
}
<div class="row">
<div class="col-md-4 col-sm-6 col-xs-12">
<div style="max-width: 281px">
<a href="#" ">
<img src="./x/pilotproject1.jpg " class="img-responsive " style="margin: 0 auto; " alt=" ">
</a>
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div style="max-width: 281px ">
<a href="# ">
<img src="./x/pilotproject2.jpg " class="img-responsive "
style="margin: 0 auto; " alt=" ">
</a>
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div style="max-width: 281px ">
<a href="# " class="pilot-link ">
<img src="./x/pilotproject3.jpg " class="img-responsive "
style="margin: 0 auto; " alt=" ">
</a>
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
</div>
我已经是该图片的宽度为281像素,究其原因,如果我不设置宽度,自带之后IMG将是更大的div宽度比281像素,这是不是我想要的东西。 as you can see in this picture, the images are all left-aligned
感谢@Daniel^h :) – NinaDev
@NinaDev乐意帮助= d –