2016-04-07 4 views
0

コンテナの幅を変更することができます。両方のコンテナに必要なスペースよりも短くすることができます。私が必要とするのは、そのような状況が起こった場合、最初の容器を縮小することですここに期待される結果: "最初のdivのcon ... 2番目のdivの内容"。現代のすべてのブラウザに対応できる方法はありますか? (最新のChrome、Firefox、IE 11が必要)。例から ここでhtmlコード "https://plnkr.co/edit/rH3ABKvFRltvAL1rXqkr?p=preview":CSS:コンテナの外に出るのではなく、最初のdivを縮小する方法

<div class="container"> 
    <div class="first">first div content</div> 
    <div class="second">second div content</div> 
</div> 

答えて

1

あなたはフレキシボックスを使用することができます

.container { 
 
    background-color: gray; 
 
    display: flex; 
 
    justify-content: space-between; 
 
    overflow-x: hidden; 
 
    white-space: nowrap 
 
} 
 
.first { 
 
    overflow: hidden; 
 
    text-overflow: ellipsis; 
 
}
<div class="container"> 
 
    <div class="first">first div content</div> 
 
    <div class="second">second div content</div> 
 
</div>

+0

をちょうど最初の1の後に "第三のdivを" 入れて適用する方法はありますそのためには2番目のルールと同じルールですか? (例えば、 "First ... SecondThird"と "First Content Second Third"は有効なケースです)。 –

+0

はい、フレックスボックスで '.first {order:1} .second {order:3} .third {order:2}'を使用して並べ替えることができます。 – Oriol

+0

問題は順序ではなく、問題はインデントなしで表示することです。ここに質問を書いてください:http://stackoverflow.com/questions/36484375/css-how-to-shrink-first-div-in-container-instead-of-going-outside-of-container –

関連する問題