html - 我需要对齐标题上的图像和文本

标签 html css

我正在尝试将标题中心的图像和文本对齐,一个显示在左侧,另一个显示在右侧。虽然我无法让文本居中。

header{
    height: 7em;
    background-color: gray;
}
header h1{
    vertical-align: middle;
    float: right;
}
header img{
    height: 7em;
    width: 12em;
    vertical-align: middle;
    float: left;
}
<header>
        <link rel="stylesheet" type="text/css" href="css/style.css"/>
        <img src="img/filmes.png" alt="logo"/>
        <h1>Sua Locadora Virtual!</h1>
    </header>

最佳答案

你可以使用行高:

header{
    height: 7em;
    background-color: gray;
}
header h1{
    vertical-align: middle;
    float: right;
    line-height: 2em;
}
header img{
    height: 7em;
    width: 12em;
    vertical-align: middle;
    float: left;
}
<header>
        <link rel="stylesheet" type="text/css" href="css/style.css"/>
        <img src="img/filmes.png" alt="logo"/>
        <h1>Sua Locadora Virtual!</h1>
    </header>

关于html - 我需要对齐标题上的图像和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30931876/

相关文章:

javascript - 单击小图像并覆盖大图像

html - Outlook 中的按钮未正确显示

html - Bootstrap 4 移动导航无法打开

javascript - 来自字符串的 Canvas toDataURL

html - 在 iframe 中覆盖/自定义 css

css - 流体 div,一个带有要排列的图像?

html - 如何使 flex 元素正确对齐?

css - 重复的花园语法

html - CSS:如何为输入单选按钮标签添加不同颜色的边框?

html - margin 不会在 iframe 中崩溃吗?