添加一個容器div
圍繞文本旁邊的圓圈,則G香港專業教育學院父容器display:flex
,align-items:center
和justify-content:center
即 HTML
<div class="public_profile">
<div class="profile_image business">
<img src="img/realestate_icon.png" />
</div>
<div class="profile-container">
<h4>BUSINESS ACCOUNT</h4>
<h3>Sunny Real Estate Sarl.</h3>
<hr class="business_line" />
<h5>VERIFIED USER</h5>
<h5 class="registered">Registered on January 27th 2016</h5>
</div>
</div>
CSS
.public_profile{
float: left;
width: 100%;
display:flex;
align-items:center;
justify-content:center;
border:solid 1px red;
}
.public_profile .profile-container {
border:solid 1px green;
}
.public_profile .profile_image{
border-radius: 50%;
float: left;
width: 120px;
height: 120px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 15px;
overflow: hidden;
}
.public_profile .profile_image.business{
background-color: #fdb902;
}
.public_profile .profile_image img{
width: 100%;
height: 100%;
}
.public_profile h4{
font-family: 'OpenSans-ExtraBold';
font-size: 12px;
color: #a1d15f;
margin: 0;
}
.public_profile h3{
font-family: 'OpenSans-Light';
font-size: 24px;
color: #1e1e1e;
margin: 0;
}
.public_profile h5{
font-family: 'OpenSans-Regular';
font-size: 12px;
color: #4d5663;
margin: 0;
}
.public_profile h5.registered{
font-size: 11px;
color: #4c4d4d;
}
hr.business_line{
margin-top: 0;
margin-bottom: 0;
width: 30px;
display: inline-block;
border-top: 2px solid #a1d15f;
}
(注:邊界是純粹是爲了顯示的目的)
Fiddle example
編輯:好吧,所以我誤解了一點,我也垂直居中文本旁邊的圓以及水平居中的一切,容器中的align-items:center
垂直居中一切,而justify-content:center
水平居中它,只要使用任何一個解決你的問題:)
是否要水平或垂直定位圈和文字? – Pugazh