2012-12-22 16 views
3

我有兩個元素這個div容器:製作一個div使用所有可用的空間在容器

<div id="container"> 
    <div id="right">Some, list, of, words, that, I, use</div> 
    <div id="left">Person Name</div> 
</div>​ 

我想讓#right DIV使用了由該留下的空間#left div並隱藏溢出。

請注意,#left div的寬度是可變的。

我想出了這個CSS至今:

#container { 
    width: 250px; 
    border: 1px solid black; 
    padding: 10px; 
} 

#left { 
    white-space: nowrap; 
    border: 1px dotted #ccc; 
    display: inline; 
} 

#right { 
    text-overflow: ellipsis; 
    overflow: hidden; 
    border: 1px dotted #ddd; 
    white-space: nowrap; 
    display: inline; 
    float: right; 
} 

#right格仍顯示的所有文字,最終以下行,像下面顯示:

Sample result

我玩弄#right div不浮動,增加width: 100%但似乎沒有任何工作。 ..

有誰知道我可以如何使兩者都顯示在同一行,但使#right div有其溢出隱藏?

的jsfiddle鏈接:http://jsfiddle.net/y4xnx/13/

編輯:固定我的解釋,其中的div應該做的事情。

+1

你可能想修改你的解釋,特別是「我想使#right DIV用不完的空間由#right div留下「。 – Marcel

+0

感謝@Marcel,看看現在好不好。 – kolrie

+1

你可以在**#右**之前把**#左**放到你的html中嗎? – grc

回答

6

這將有助於把#left#right

<div id="container"> 
    <div id="left">Person Name</div> 
    <div id="right">Some, list, of, words, that, I, use</div> 
</div>​ 

然後在CSS中的幾個變化應該做你想要什麼:

#left { 
    white-space: nowrap; 
    border: 1px dotted #ccc; 
    float: left; 
    margin-right: 5px; 
} 

#right { 
    text-overflow: ellipsis; 
    overflow: hidden; 
    border: 1px dotted #ddd; 
    white-space: nowrap; 
} 

例子: http://jsfiddle.net/grc4/MvXuN/

+0

超棒的男人,完美的作品! – kolrie

1

我試圖實現我從你的問題中理解的任何東西。檢查這裏的小提琴:http://jsfiddle.net/y4xnx/20/

HTML:

<div id="container"> 
    <div id="left">Person Name</div> 
    <div id="right">Some, list, of, words, that, I, use</div> 
</div>​ 

CSS:

#container { 
    width: 250px; 
    border: 1px solid black; 
    padding: 10px; 
    white-space:nowrap; 
    overflow:hidden; 
} 

#left { 
    border: 1px dotted #ccc; 
    display: inline-block; 
} 

#right { 
    display:inline-block; 
    border: 1px dotted #ddd; 
} 
​ 
+0

如果#right放置在#left之前,這是正確的答案。 – andrewk

+0

我猜OP可以在#right之前放置#left。 – andrewk

相關問題