<分区>
#xxx {
position:relative;
display:flex;
height:32px;
width:150px;
background-color:black;
color:white;
font-family: Helvetica, Arial, sans-serif;
justify-content: center;
margin-left:10px;
}
#xxx > span {
align-self: center;
}
#xxx > img{
margin-right:auto;
}
<body>
<div id="xxx"><img src="xxx.png" height="32" width="32"/><span>hello</span></div>
</body>
我一直在尝试让以下内容正确对齐。我试图让图像左对齐,跨度内的文本居中。起初我尝试用绝对定位跨度并设置 left:0;但那搞砸了。然后我尝试了 margin:auto 但这弄乱了居中对齐的元素。
<!DOCTYPE HTML>
<html>
<style>
#xxx {
position:relative;
display:flex;
height:32px;
width:150px;
background-color:black;
color:white;
font-family: Helvetica, Arial, sans-serif;
justify-content: center;
margin-left:10px;
}
#xxx > span {
align-self: center;
}
#xxx > img{
margin-right:auto;
}
</style>
<body>
<div id="xxx"><img src="xxx.png" height="32" width="32"/><span>hello</span></div>
</body>
</html>