<div>
{iconElement}
<div className='id-count-title'>
{title}
<div className='id-count-description'>
{description}
</div>
</div>
</div>
我尝试编写CSS并为其设置样式,
.id-count-title {
width: 37px;
height: 32px;
left: 443px;
font-family: Open Sans;
font-style: normal;
font-weight: bold;
font-size: 32px;
text-align: center;
color: #4CA6EA;
}
.id-count-description {
width: 58px;
height: 16px;
left: 432px;
font-family: Open Sans;
font-style: normal;
font-weight: normal;
line-height: 16px;
font-size: 11px;
text-align: center;
}
如何实现所需的样式?
答案 0 :(得分:1)
使用flexbox,这是flexbox的指南:https://css-tricks.com/snippets/css/a-guide-to-flexbox/。
根据需要选择使容器显示:flex 和 justify-content:环绕或分隔。
.flex {
display: flex;
justify-content: space-around;
background: #135;
padding: 10px;
color: #fff;
text-align: center;
}
.flex span {
font-size: 24px;
display: block;
}
.flex .active {
color: #4CA6EA;
}
<div class="flex">
<div class="active"><span>18</span>Users</div>
<div><span>1</span>Native</div>
<div><span>17</span>Non-native</div>
</div>
答案 1 :(得分:1)
我认为Flexbox正是您所需要的。 您可以通过以下方式更改代码:
html:
<div className="id-block">
<div className="icon">
{iconElement}
</div>
<div className="text">
<div className='id-count-title'>
{title}
</div>
<div className='id-count-description'>
{description}
</div>
</div>
</div>
css / sass:
.id-block {
display: flex;
flex-direction: row;
align-items: center;
}
.text {
display: flex;
flex-direction: column;
align-items: center;
}
.id-count-title {
width: 37px;
height: 32px;
left: 443px;
font-family: 'Open Sans';
font-style: normal;
font-weight: bold;
font-size: 32px;
text-align: center;
color: #4CA6EA;
}
.id-count-description {
width: 58px;
height: 16px;
left: 432px;
font-family: 'Open Sans';
font-style: normal;
font-weight: normal;
line-height: 16px;
font-size: 11px;
text-align: center;
}