【发布时间】:2015-01-19 02:26:01
【问题描述】:
寻找一种解决方案,将用户的个人资料图片保留在 h1 旁边,并使它们都居中,两边的边距相等,无论屏幕大小如何。 h1 通过 text-align 居中,但我不知道如何将 img 保持在 h1 旁边。目前, img 向左浮动,当我注释掉 float: left 时,img 居中,h1 消失。下面是同时保存 img 和 h1 的 div 的代码,然后是分别保存 img 和 h1 的代码。
.biohead {
width: 100%;
position: fixed;
text-align: center;
display: block;
padding-bottom: 1%;
color: dimgray;
font-size: 2.5em;
box-shadow: 0 0 15px rgba(0, 0, 0, .2);
}
.biohead img {
height: 50px;
border-radius: 39px;
width: 50px;
margin-top: 5px;
float: left;
margin-left: 5px;
margin-right: 5px;
margin-bottom: 5px;
/*margin-left: 15%;*/
/*margin-right: 11px;*/
}
.biohead h1 {
/* float: left;
*/ margin: 0 auto;
margin-top: 10px;
}
和 html :
<div class="biohead">
<img src="images/fisherman.png" alt="Raul">
<h1>Raul Pescadero</h1>
</div> <!--biohead-->
【问题讨论】: