2013-01-13 19 views
0

使用Twitter的引導,我有以下CSS一個div:如何接受溢出,並有一個默認的高度

#notecard.hero-unit 
{ 
    background-image: url("../img/notecard.jpg"); 
    background-size: cover; 
    width: 60%; 
    margin-left: 20%; 
    margin-right: 20%; 
    height: 1%; 
    position: relative; 
    text-align: center; 
    overflow: hidden; 

} 

內該div我有文字h2的變化量與下面的CSS:

h1, 
h2, 
h3, 
h4, 
h5, 
h6 { 
    margin: 0; 
    font-weight: bold; 
    color: #333333; 
    text-rendering: optimizelegibility; 
} 

#notecard.hero-unit我使用overflow: hidden;height: 1%因爲大多數時間從h2卷軸進一步比#notecard文 - 這樣的工作正在處理和#notecard現在擴展到h2的文本內。

但是,當h2只有一行或兩行時,#notecard是非常小的。我想#notecard是一個默認大小 - 比如說300px,如果有的話仍然接受溢出。

我試圖在h2300px#noteard設置高度也高,但都忽略了我所需要的溢出。

謝謝。

+1

也許我太累了,但我不知道目標是什麼。爲什麼不在#notecard上放一個最小高度並在一天內打電話呢? http://jsfiddle.net/M9bX8 – isherwood

+1

我很想責怪自己太累了,還有酒,但不幸的是我在設計上很糟糕。最小高度是我需要的。想提交答案,我會接受嗎?謝謝! –

+0

樂意提供幫助。我們都去過那裏。 – isherwood

回答

1

我會使用一個最小高度在H2的父:

<style> 
h1, h2, h3, h4, h5, h6 { 
    margin: 0; 
    font-weight: bold; 
    color: #333333; 
    text-rendering: optimizelegibility; 
} 
.hero-unit { 
    background-color: #eee; 
    background-size: cover; 
    width: 60%; 
    margin-left: 20%; 
    margin-right: 20%; 
    min-height: 50px; 
    position: relative; 
    text-align: center; 
    overflow: hidden; 
} 
</style> 

<div class="hero-unit"> 
    <h2>Some Text</h2> 
</div> 
<br> 

<div class="hero-unit"> 
    <h2>Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. Much more text. </h2> 
</div> 

http://jsfiddle.net/M9bX8/5/