【发布时间】:2015-09-14 07:01:30
【问题描述】:
我在互联网上找了很长时间,得到一个文本左侧的图像,文本在顶部或 div 的中心。我在互联网上查看了很多帖子,How to have image and text side by side、Cant figure out how to have image and text side by side in a div and keep it responsive, fiddle included 以及其他一些帖子。
HTML
<div id="header">
<img src="logo1.png" alt="LimitMove Logo"> </img>
<h1> Limit Move </h1>
</div>
CSS
*{
margin: 0;
padding: 0;
}
a,a:link,a:visited,a:hover,a:active{
color: #3C3C3C;
text-decoration: none;
}
a:hover,a:active{
color:#4D4D4D;
}
h1{
font-family: Tahoma;
font-size: 28px;
color: #DFDFDF;
}
#header{
display: inline-block;
width:100%;
height: 64px;
background-color: rgb(0,120,170);
}
#header img{
display: inline;
vertical-align:bottom;
}
#header h1, #header > #navbar{
display: inline;
text-align: text-top;
}
您可以看到文本位于#header div 标签的底部,而我无法将其移至顶部。 我尝试使用 padding-top:-20px;与margin相同,但它们都不能正常工作。
有什么想法吗?
提前致谢。
【问题讨论】:
-
注意
img是一个空元素,它不需要单独的结束标签</img>。 -
谢谢,不知道。