我有3个盒子,我试图排队..
.box {
width: 50px;
height: 50px;
background: #8C8C8C;
margin:0 auto;
border: solid 4px grey;
text-align: center;
display:block;
}
显示内联块不起作用,它也会杀死居中
HTML
<div class="box"(click)="boxnumber('1')" >
<p class="count1">{{item1count}}<p>
</div>
<br>
<div class="box" (click)="boxnumber('2')" >
<p class="count2">{{item2count}}<p>
</div>
<br>
<div class="box" (click)="boxnumber('3')" >
<p class="count3">{{item3count}}<p>
</div>
另外我想在每个box.count1上显示item1count,item2count,item3count数字.count2 css类现在是空的,因为我不确定在它们中写什么。
答案 0 :(得分:1)
只需删除br
代码,然后将display:block
替换为inline-block
.box {
width: 50px;
height: 50px;
background: #8C8C8C;
margin:0 auto;
border: solid 4px grey;
text-align: center;
display:inline-block;
}
.boxes {
text-align: center;
}
<div class="boxes">
<div class="box"(click)="boxnumber('1')" >
<p class="count1">{{item1count}}<p>
</div>
<div class="box" (click)="boxnumber('2')" >
<p class="count2">{{item2count}}<p>
</div>
<div class="box" (click)="boxnumber('3')" >
<p class="count3">{{item3count}}<p>
</div>
</div>
答案 1 :(得分:1)
尝试将{css margin: 0px auto;
添加到.box
以使其居中。
试试这个:
.box{
width:50px;
height: 50px;
border: 2px solid red;
margin: 15px auto;
display: table;
}
要在右角显示数字,您需要添加垂直对齐,如下所示:
.box p{
vertical-align:bottom;
display: table-cell;
}
您可以查看我的plunkr here
答案 2 :(得分:0)
试试这个:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
.box {
width: 50px;
height: 50px;
background: #8C8C8C;
float: left;
margin-right:10px;
border: solid 4px grey;
text-align: center;
}
.box-container{
width:204px; /* 50*3+(4*2)*3+10*3 */
margin:0 auto;
}
</style>
</head>
<body>
<div class="box-container">
<div class="box"(click)="boxnumber('1')" >
<p class="count1">{{item1count}}<p>
</div>
<div class="box" (click)="boxnumber('2')" >
<p class="count2">{{item2count}}<p>
</div>
<div class="box" (click)="boxnumber('3')" >
<p class="count3">{{item3count}}<p>
</div>
</div>
</body>
</html>