html - 使此图像位于文本左侧,文本位于顶部还是中间?

标签 html css image text

我在互联网上找了很久,想在文本左侧找到一个图像,文本在顶部或 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;

}

JSfiddle

您可以看到文本位于#header div 标记的底部,而我无法将其移至顶部。 我尝试使用 padding-top:-20px;与 margin 相同,但两者均无法正常工作。

有什么想法吗?

提前致谢。

最佳答案

#header h1, #header > #navbar{
    display: inline;
    text-align: text-top;
}

text-top 不是 text-align 的有效值(而 text-align 用于水平对齐)。

你想在这里使用vertical-align,就像你对图像所做的一样;并且您想对两者都使用 top

http://jsfiddle.net/eed6pb9p/2/

关于html - 使此图像位于文本左侧,文本位于顶部还是中间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31088173/

相关文章:

javascript - 不使用 jQuery 来定位 href 地址的特定部分

javascript - 使用HTML5原生拖放时如何限制移动?

html - margin-top 不会移动单个元素

Java游戏无法读取图像文件

php - 从提交表单上传图片到mysql数据库并在div中显示图片?

html - 为什么使用 this.src 时此图像不会在鼠标悬停时发生变化?

javascript - 如何添加从 JSON 文件中获取图像,添加类并追加到 div 中?

javascript - 对于 jQuery "media query"类型的情况使用 setTimeout() 是否有任何不足

html - 选择选项填充在 chrome 中不起作用

html - 使用任意元素格式化 CSS