[英]Generating buttons side by side not working with display:inline-block
I'm generating buttons using Angular and the buttons are one on top of the other rather than side by side 我正在使用Angular生成按钮,这些按钮是一个在另一个之上,而不是并排
<div *ngIf="response">
<div *ngFor="let hit of response.hits.hits">
<button class="btn btn-primary" role="button" style="display:inline-block">{{hit._source.keywords[0].keyword}}</button>
</div>
</div>
I've tried style="display:inline-block"
as well as style="display:inline"
and they both end up one above the other. 我尝试过
style="display:inline-block"
以及style="display:inline"
,它们都以另一个结尾。 Does it have to do with the way *ngFor
works or is there some other CSS style i could use? 它是否与
*ngFor
工作方式*ngFor
还是我可以使用其他CSS样式?
They are stacked vertically because you generate a series of div
, which are block elements. 它们是垂直堆叠的,因为您会生成一系列
div
元素,它们是块元素。
You should apply the ngFor
loop to the button: 您应该将
ngFor
循环应用于按钮:
<div *ngIf="response">
<button *ngFor="let hit of response.hits.hits" ... style="display: inline-block">...</button>
</div>
or apply the display
style to the inner div
: 或将
display
样式应用于内部div
:
<div *ngIf="response">
<div *ngFor="let hit of response.hits.hits" style="display: inline-block">
<button...>...</button>
</div>
</div>
I see that you are using bootstrap so you just need to encapsulate these buttons inside btn-group : 我看到您正在使用引导程序,因此只需要将这些按钮封装在btn-group中 :
<div *ngIf="response" class="btn-group">
<button *ngFor="let hit of response.hits.hits" class="btn btn-primary" role="button" >{{hit._source.keywords[0].keyword}}</button>
</div>
<button style="float:left" class="btn btn-primary" role="button" style="display:inline-block">{{hit._source.keywords[0].keyword}}</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.