如何阻止文本显示/流出<h3>标记?</h3>

时间:2013-02-04 18:26:10

标签: html css css3 css-float

我不知道为什么,但我会在<h3>标记之外显示/流动此文字。我认为这与浮动有关,但我已经尝试了所有我知道的解决方案来修复它们并且它们没有用。

这是jsfiddle(我在Safari中):http://jsfiddle.net/BJCkv/1/

HTML:

<div id="header-container">
    <div class="wrapper"> <!-- has width of 940px; and aligned in middle -->
        <h1>PCSA - TRAINING</h1>
        <h3>Security Architecture</h3> <!-- This is the problem text -->
    </div>
</div>

CSS:

#header-container {
    height: 84px;
    line-height: 84px;
    background-color: #e0dfd9;
    background-image: url(../img/header.png);
    border-top: 1px solid #ccccc7;
    border-bottom: 1px solid #ccccc7;
}
#header-container .wrapper {
    overflow: hidden;
}
#header-container h1 {
    color: #b8622b;
    font-family: 'Open Sans', sans-serif;
    font-size: 38px;
    text-shadow: 0 1px 0 #f7f7f5;
    font-weight: 600;
    float: left;
    background: red;
}
#header-container h3 {
    color: #a5a5a4;
    float: left;
    font-family: 'Open Sans', sans-serif;
    font-style: italic;
    padding: 3px 0 3px 10px;
    margin-left: 20px;
    height: 30px;
    border-left: 1px solid #a5a5a4;
    background: yellow;
}

2 个答案:

答案 0 :(得分:2)

replace height: 30px; line-height: 30px;可以解决问题。 http://jsfiddle.net/BJCkv/7/

答案 1 :(得分:1)

您需要重置h3元素的行高:实时演示:http://jsfiddle.net/BJCkv/5/

#header-container h3 {
    line-height: 30px; /* add this */
    color: #a5a5a4;
    float: left;
    font-family: 'Open Sans', sans-serif;
    font-style: italic;
    padding: 3px 0 3px 10px;
    margin-left: 20px;
    height: 30px;
    border-left: 1px solid #a5a5a4;

    background: yellow;
}