html - 将 div 与文本垂直对齐在同一行

标签 html css

我有一个文本和一个 div 彼此相邻(其中写着“BitHumor”和“检查”符号),但它们彼此不对齐(参见图片)

这是我的 HTML 和 CSS 代码:

<font face='HelveticaNeue-bold' color='#4671A5' font size='6' style='position:absolute;z-index:500;width:100%;top:120px;vertical-align:middle;'>
<center>" . $row["username"]. "&nbsp;<div class='" . $row["status"]. "'></div>   
    <style>
    .official {
    content: url('http://bithumor.co/1234567890.png');
    width: 28px;
    height: 28px;
      display: inline;
    z-index:999999;
    position: absolute;
    vertical-align:middle;
    }
    </style>

enter image description here

如何使文本(“BitHumor”)和 div(图像 - 带复选标记)垂直对齐?

最佳答案

这里有两个选项:

  1. 删除绝对定位。通过从复选标记类 (.official) 中删除 position:absolute,您可以使用vertical-align

  2. 使用margin进行对齐。将其添加到复选标记类中:.official { margin-top: 5px; }

关于html - 将 div 与文本垂直对齐在同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33060251/

相关文章:

html - CSS动画帮助。需要代码解释

JavaScript 通过在不损失高度的情况下滑动更多内容来替换内容

html - 设置 window.innerHeight

javascript - 如何在 iOS Chrome 中使用 CSS scroll snap + picture bug 隐藏滚动条

html - 在 div 下有很多空白区域?

javascript - 使用 URL 打开 Bootstrap 4 Accordion

c# - 如何为 HTML <video> 标签缓存 mp4 视频?

javascript - 在没有 webpack 或 CDN 的情况下加载静态项目

html - 圆形图像周围的圆形文本

html - 从一个 iframe 的 div 中提取/回显文本到页面的另一部分