水平对齐缩略图

时间:2018-12-23 14:29:31

标签: css angular twitter-bootstrap angular6

我正在使用Angular 7

我使用了引导程序的图像缩略图类,它是垂直对齐的,我想水平对齐。

.thumbnail
{
text-align: center;
float: left;
}
.row
{
text-align: center;
}

以下是我的代码:

 <div class= "row">
 <div class = "col-xs-12">
 <button class="btn btn-success">New Recipe</button>
 </div>
 <hr>
  <div class = "col-md-12" >
  <a href="#" class="thumbnail" *ngFor="let recipe of recipes">
    <img src = "{{ recipe.imagePath }}" alt="{{ recipe.name }}" class = 
     "img-responsive" class="img-thumbnail">
    <h4 class = "caption">{{ recipe.name }}</h4>
    <p class = "caption">{{ recipe.description }}</p>
</a>
<app-recepie-item></app-recepie-item>
</div>
</div>

Have created 2 objects

recipes: Recipe [] = [ new Recipe('My Sample Recipe', 'This is my first 
recipe', 'image url'),
new Recipe('Potato Recipe', 'This an actual Potato 
Recipe', 'http://coastguard.dodlive.mil/files/2014/04/unnamed-2- 
560x281.jpg')];

输出看起来像这样。

缩略图垂直显示。

我想水平显示。

enter image description here

1 个答案:

答案 0 :(得分:1)

如果您使用bootstrap的grid属性进行对齐,我认为您无需编写更多的CSS。

HTML:

 <div class="container">
  <div class="row">
    <div class = "col-xs-12">
      <button class="btn btn-success">New Recipe</button>
    </div>
  </div>
  <hr>
  <div class="row">
    <div class="col-md-4 col-xs-4" *ngFor="let recipe of recipes">
      <a href="#">
      <img src={{recipe.url}} height="100" width="100">
      <h4 class = "caption">{{ recipe.name }}</h4>
        <p class = "caption">{{ recipe.desc }}</p>
      </a>
    </div>
  </div>
</div>

TS:

recipes: any[] = [
    {name:'product_name', desc: 'Description', url: 'http://www.movingimage.us/images/homepage/features/jhe_jim_kermit.jpg'},
    {name:'product_name', desc: 'Description', url: 'http://www.movingimage.us/images/homepage/features/jhe_jim_kermit.jpg'},
    {name:'product_name', desc: 'Description', url: 'http://wallpaper-gallery.net/images/image/image-8.jpg'}
    ];