html - 内容随文本向下移动

标签 html css twitter-bootstrap

我有一个内联元素,分为三个部分:首先是一个只有背景图片的元素。第二个用于内容,最后一个用于另一个也只有背景图像。 HTML 是

<span class="box-l"></span>
<span class="box-c">some text</span>
<span class="box-r"></span>

和CSS:

.box-l{
    width: 7px;
    height: 20px;
    min-width: 10px;
    background:url(../img/c_box.png) 0 0;
    display: inline-block;
    border: 0px;
}
.box-r{
    width: 5px;
    height: 20px;
    min-width: 5px;
    background:url(../img/c_box.png) -42px 0;
    display: inline-block;
}
.box-c{
    height: 20px;
    min-width: 10px;
    max-width: 40px;
    display: inline-block;
    font-size: 11px;
    line-height: 20px;
    background:url(../img/c_box.png) -9px 0;
}

当中心元素什么都没有时,结果如下:fine result 但是当我将一些文本放入第二个元素时,结果是这样的:wrong result

为什么中间元素向下移动,里面有文字?我该如何解决这个问题?

最佳答案

当使用 display: inline-block: 不要忘记放置 vertical-align: middle;文本并保持行高 (line-height) 具有相同的时间量以确保您具有垂直对齐

关于html - 内容随文本向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16200827/

相关文章:

css - Bootstrap Accordion 显示最初在 React 应用程序中打开的所有元素,应关闭

javascript - 如果超过值,则在文本框上显示弹出框

css - 将元素符号点插入我的 div 会将其向左移动

javascript - 我如何在 JS 中取消转义 HTML 实体? (将 < 更改为 <)

css - Bootstrap 4 向右浮动无法与导航栏一起使用

html - 表格边框不显示

html - div 中的中心文本,其中有一个 div

javascript - 页面更改后保持下拉菜单中的所选选项处于选中状态

html - 使用 CSS/HTML 创建固定的 5 圈评级

css - 如何为 Bootstrap 3 strip 表中的两行分配相同的背景颜色?