html - 内联显示两个 div

标签 html css

我需要在同一行上并排显示两个 div,但我不明白为什么第二个比第一个略低。

<div class="cont-title">
    <div class="triang-header"></div>
    <div class="h2-stripe">
        <h2 itemprop="name">
        Title
        </h2>
    </div>
</div>

这是CSS:

.cont-title{
    margin-right: -7px;
    min-width: 90%;
    max-width: 100%;
    height:51px;
    float:right;
    text-align:right;
    white-space: nowrap;
}

.triang-header{
    position:relative;
    width:39px;
    height:38px;
    display:inline-block;
    background:url('../images/titlebar.png') no-repeat top left;

}

.h2-stripe{
    position:relative;
    z-index:10;
    display:inline-block;
    text-align:left;
    background-color: #2A58AE;
    margin:0;
    height:38px;
    min-width:80%;
    line-height:38px;
    box-shadow: 2px 3px 5px 0 #555;
}

我做错了什么?

最佳答案

我想你没有计算行高,

.h2-stripe 的样式应该是这样的:

.h2-stripe{
    position:relative;
    line-height: 23px; // <----
    z-index:10;
    display:inline-block;
    text-align:left;
    background-color: #2A58AE;
    margin:0;
    height:38px;
    min-width:80%;
    box-shadow: 2px 3px 5px 0 #555;
}

这是一个 line-height:23px for .h2-stripe 的例子:http://jsfiddle.net/6a0ga3uq/

关于html - 内联显示两个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26786219/

相关文章:

css - 位置相对重叠 float-left

javascript - 将元素宽度设置为其内部的图像

html - div 的不透明度会产生意想不到的结果并将内容与图像混合

html - 三列 CSS 在 IE 中不起作用

html - 伪元素和按钮标签 : how to prevent the pseudo element from being clickable?

java - GWT 中的圆 Angular 面板

html - 你如何告诉浏览器 "if you need to wrap, wrap here first"?

jquery - 呃,将 2 个 div 放在居中容器的内联中,该容器粘在顶部

javascript - 按类名监听 href 的点击事件

javascript - 从页面底部滑入一个div?