在我尝试包括用户的个人资料图片之前,将标头对齐,但我现在似乎无法得到它。经过反复试验后,这是我到目前为止的:
html/php:
<ul id="right-side">
<li>
<a href="">
<img src="<?php echo $user['profile_pic'];?>" id="profilepic">
<?php echo $user['user_name'];?>
</a>
</li>
</ul>
CSS:
nav {
position: fixed;
right: 0px;
top: 0px;
z-index: 1000;
background-color: rgba(0, 0, 0, 0.5);
width: 100%;
}
#right-side {
display: inline;
float: right;
text-align: right;
}
#right-side a {
vertical-align: middle;
}
#profilepic {
height:50px;
width 50px;
border-radius:50px;
}
您可以尝试此代码。
nav {
position: fixed;
right: 0px;
top: 0px;
z-index: 1000;
background-color: rgba(0, 0, 0, 0.5);
width: 100%;
padding: 0 10px;
}
#right-side {
display: inline;
float: right;
text-align: right;
}
#right-side li {
list-style-type: none;
}
#right-side a {
display: flex;
align-items: center;
}
#right-side a img {
margin-right: 10px;
}
#profilepic {
height:50px;
width 50px;
border-radius:50px;
}
<nav>
<ul id="right-side">
<li>
<a href="">
<img src="https://cdn.onlinewebfonts.com/svg/img_235843.png" id="profilepic">
John
</a>
</li>
</ul>
</nav>
我认为您的意思是您希望用户名和图片并排垂直对齐吗?如果是这样,请检查一下这个小提琴。
CSS
#right-side {
display: inline;
float: right;
text-align: right;
}
#profile-pic {
left: 0;
float: left;
width: 50px;
}
#profile-name {
margin-left: 55px;
top: 0;
}
#profilepic {
height: 50px;
width: 50px;
border-radius: 50px;
}
html
<ul id="right-side">
<div id="profile-pic">
<img src="https://i.stack.imgur.com/34AD2.jpg" id="profilepic">
</div>
<div id="profile-name">
User Name
</div>
</ul>