[英]Margin doesn't center
I am currently working on my portfolio website and so far. 到目前为止,我目前正在我的投资组合网站上工作。 But now I am having problem to center the "about me" page but i think i made a mistake somewhere because it doesn't do what i want.
但是现在我在将“关于我”页面居中时遇到了问题,但是我认为我在某个地方犯了一个错误,因为它不能满足我的要求。
Html: HTML:
<div class="pageAbout">
<div id="icon">
<img src="images/iconAbout.png" />
</div>
<div id="infoLeft">
<h3>Name</h3>
<p>Jeffrey van der Heijden</p>
<h3>Birthday</h3>
<p>-</p>
<h3>Hobbies</h3>
<p>hanging around with friends and family</p>
</div>
<div id="avatar">
<img src="images/avatarMe.png" />
</div>
<div id="infoRight">
<h3>Place of birth</h3>
<p>Eindhoven</p>
<h3>Phone</h3>
<p>-</p>
<h3>Email</h3>
<p>-</p>
</div>
</div>`
CSS: CSS:
.pageAbout{
width: 100%;
height: auto;
background-color: #e5e5e5;
padding-top: 1%;
}
h3{
font-family: Aller_regular;
font-size: 16px;
}
p{
font-family: Aller_regular;
font-size: 14px;
margin: 2% 0px;
}
#infoLeft{
width: 12%;
height: auto;
float: left;
margin-top: 2%;
text-align: right;
}
#avatar{
width: 18%;
height: auto;
float: left;
margin-top: 2%;
text-align: center;
}
#infoRight{
width: 12%;
height: auto;
float: left;
margin-top: 2%;
text-align: left;
}
so What I want is. 所以我想要的是
infoLeft
needs to be on the left
side of the avatar
and infoRight
on the right
side of the avatar
image and the image needs to be in the center of the page. infoLeft
必须在left
的侧面avatar
和infoRight
在right
的侧面avatar
图像和图像必须是在页面的中心。
I hope i gave given enough and the right information. 我希望我给了足够的和正确的信息。
Thanks. 谢谢。
Okay, so these are the mistakes: 好的,这些是错误:
width: 100%;
width: 100%;
and height: auto;
height: auto;
. overflow: hidden;
overflow: hidden;
to clear the float
s. float
。 width
s of the info-*
and #image
to sum up to 100%
. info-*
和#image
的width
s,总计为100%
。 #avatar img
centered by using text-align: center;
text-align: center;
对齐#avatar img
居中text-align: center;
. #avatar
to look like it is vertically centered. #avatar
创建一个假边缘 ,使其看起来像垂直居中。 Snippet 片段
.pageAbout { background-color: #e5e5e5; padding-top: 1%; overflow: hidden; } h3 { font-family: Aller_regular; font-size: 16px; } p{ font-family: Aller_regular; font-size: 14px; margin: 2% 0px; } #infoLeft{ width: 30%; height: auto; float: left; margin-top: 2%; text-align: right; } #avatar { width: 40%; height: auto; float: left; margin-top: 10%; text-align: center; } #avatar img { display: inline-block; } #infoRight{ width: 30%; height: auto; float: left; margin-top: 2%; text-align: left; }
<div class="pageAbout"> <div id="icon"> <img src="images/iconAbout.png" /> </div> <div id="infoLeft"> <h3>Name</h3> <p>Jeffrey van der Heijden</p> <h3>Birthday</h3> <p>-</p> <h3>Hobbies</h3> <p>hanging around with friends and family</p> </div> <div id="avatar"> <img src="images/avatarMe.png" /> </div> <div id="infoRight"> <h3>Place of birth</h3> <p>Eindhoven</p> <h3>Phone</h3> <p>-</p> <h3>Email</h3> <p>-</p> </div> </div>
I advise you to improve your boxing and get into the CSS3 flexbox ! 我建议您改善拳击方式,并使用CSS3 flexbox !
Also, remove the auto height. 另外,删除自动高度。
<div class="flex-center"> <div id="infoLeft" > <h3>Name</h3> <p>Jeffrey van der Heijden</p> <h3>Birthday</h3> <p>-</p> <h3>Hobbies</h3> <p>hanging around with friends and family</p> </div> <div id="avatar-container"> <div id="avatar"> <img src="images/avatarMe.png" /> </div> </div> <div id="infoRight" > <h3>Place of birth</h3> <p>Eindhoven</p> <h3>Phone</h3> <p>-</p> <h3>Email</h3> <p>-</p> </div> </div>
and 和
.pageAbout{
width: 100%;
height: auto;
background-color: #e5e5e5;
padding-top: 1%;
}
h3{
font-family: Aller_regular;
font-size: 16px;
}
p{
font-family: Aller_regular;
font-size: 14px;
margin: 2% 0px;
}
#infoLeft{
width: 12%;
/* height: auto; */
/*float: left;*/
margin-top: 2%;
text-align: right;
}
#avatar{
width: 18%;
/* height: auto; */
/*float: left;*/
margin-top: 2%;
text-align: center;
}
#infoRight{
width: 12%;
/* height: auto; */
/*float: left;*/
margin-top: 2%;
text-align: left;
}
#avatar-container {
width: 18%;
display: flex;
align-items: center;
justify-content: center;
}
.flex-center {
display: flex;
justify-content: center;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.