我有下一个HTML代码
.ratings {
border: 1px solid #CCC;
overflow: visible;
padding: 10px;
position: relative;
width: 100%;
height: 100px;
}
.ratings_stars {
background: url('/images/rsz_star_icon_1.png') no-repeat;
float: left;
height: 28px;
padding: 2px;
width: 32px;
}
.ratings_vote {
background: url('star_voted.png') no-repeat;
}
.ratings_over {
background: url('star_overs.png') no-repeat;
}
.total_votes {
background: #eaeaea;
top: 58px;
left: 0;
padding: 5px;
position: absolute;
}

<div class="row">
<div class="col-xs-12">
<div id="rating_1" class="ratings">
<div class="star_1 ratings_stars"></div>
<div class="star_2 ratings_stars"></div>
<div class="star_3 ratings_stars"></div>
<div class="star_4 ratings_stars"></div>
<div class="star_5 ratings_stars"></div>
<div class="star_6 ratings_stars"></div>
<div class="star_7 ratings_stars"></div>
<div class="star_8 ratings_stars"></div>
<div class="star_9 ratings_stars"></div>
<div class="star_10 ratings_stars"></div>
<div class="total_votes">vote data</div>
</div>
</div>
</div>
&#13;
我想让divs的图像响应......我希望所有的星星都能以内联为中心。我可以这样做吗?有相同的保证金并保持中心的星星图标
答案 0 :(得分:2)
在父div上使用display:flex;
和justify-content:space-between;
。如果您不希望它与图像一起居中,也可以将.total_votes
移出评级。
通过这种方式,您无需担心给予他们保证金。
.ratings {
border: 1px solid #CCC;
overflow: visible;
padding: 10px;
position: relative;
width: 100%;
height: 100px;
display:flex;
align-items:center;
justify-content:space-between;
}
.ratings_stars {
background: url('http://www.chinabuddhismencyclopedia.com/en/images/thumb/b/b8/Nature.jpg/240px-Nature.jpg') no-repeat;
float: left;
height: 28px;
padding: 2px;
width: 32px;
}
.ratings_vote {
background: url('http://images.financialexpress.com/2015/12/Lead-image.jpg') no-repeat;
}
.ratings_over {
background: url('http://images.financialexpress.com/2015/12/Lead-image.jpg') no-repeat;
}
.total_votes {
background: #eaeaea;
padding: 5px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-12">
<div id="rating_1" class="ratings">
<div class="star_1 ratings_stars"></div>
<div class="star_2 ratings_stars"></div>
<div class="star_3 ratings_stars"></div>
<div class="star_4 ratings_stars"></div>
<div class="star_5 ratings_stars"></div>
<div class="star_6 ratings_stars"></div>
<div class="star_7 ratings_stars"></div>
<div class="star_8 ratings_stars"></div>
<div class="star_9 ratings_stars"></div>
<div class="star_10 ratings_stars"></div>
</div>
<div class="total_votes">vote data</div>
</div>
</div>
答案 1 :(得分:1)
只需使用display:inline-block
和text-align:center
.ratings {
border: 1px solid #CCC;
overflow: visible;
padding: 10px;
position: relative;
width: 100%;
height: 100px;
text-align:center;
}
.ratings_stars {
background: url('http://www.chinabuddhismencyclopedia.com/en/images/thumb/b/b8/Nature.jpg/240px-Nature.jpg') no-repeat;
float: none;
display:inline-block;
height: 28px;
padding: 2px;
width: 32px;
margin:0 10px;
}
.ratings_vote {
background: url('http://images.financialexpress.com/2015/12/Lead-image.jpg') no-repeat;
}
.ratings_over {
background: url('http://images.financialexpress.com/2015/12/Lead-image.jpg') no-repeat;
}
.total_votes {
background: #eaeaea;
padding: 5px;
}
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-12">
<div id="rating_1" class="ratings">
<div class="star_1 ratings_stars"></div>
<div class="star_2 ratings_stars"></div>
<div class="star_3 ratings_stars"></div>
<div class="star_4 ratings_stars"></div>
<div class="star_5 ratings_stars"></div>
<div class="star_6 ratings_stars"></div>
<div class="star_7 ratings_stars"></div>
<div class="star_8 ratings_stars"></div>
<div class="star_9 ratings_stars"></div>
<div class="star_10 ratings_stars"></div>
</div>
<div class="total_votes">vote data</div>
</div>
</div>
&#13;
答案 2 :(得分:0)
只需使用以下CSS
.ratings {
display: flex;
align-items: center;
justify-content: space-between;
}
答案 3 :(得分:0)
有一个名为<center></center>
的标记,请尝试使用其中的<div>
。
例如:
<center><div class="star_3 ratings_stars"></div></center>
<center><div class="star_4 ratings_stars"></div></center>