2014-10-20 28 views
25

Dall'ultima (?) Versione di Firefox Nightly (35.0a1) ho riscontrato un problema con text-overflow: ellipsis all'interno di un contenitore Flexbox con flex-direction: row, con ogni colonna larga al 50%.Ellipsis nel contenitore flexbox

Demo:

.container { 
 
    width: 300px; 
 
    background: red; 
 
} 
 

 
.row { 
 
    display: flex; 
 
    flex-direction: row; 
 
    flex-wrap: wrap; 
 
} 
 

 
.column { 
 
    flex-basis: 50%; 
 
} 
 

 
.column p { 
 
    background: gold; 
 
    
 
    /* Will not work in Firefox Nightly 35.0a1 */ 
 
    text-overflow: ellipsis; 
 
    overflow: hidden; 
 
    white-space: nowrap; 
 
}
<div class="container"> 
 
    <div class="row"> 
 
    <div class="column"> 
 
     <p>Captain's Log, Stardate 9529.1: This is the final cruise of the starship Enterprise under my command. This ship and her history will shortly become the care of another crew. To them and their posterity will we commit our future. They will continue the voyages we have begun and journey to all the undiscovered countries boldly going where no man, where no one has gone before.</p> 
 
    </div> 
 
    <div class="column"> 
 
     <p>Captain's Log, Stardate 9529.1: This is the final cruise of the starship Enterprise under my command. This ship and her history will shortly become the care of another crew. To them and their posterity will we commit our future. They will continue the voyages we have begun and journey to all the undiscovered countries boldly going where no man, where no one has gone before.</p> 
 
    </div> 
 
    </div> 
 
</div>

Nella notte il testo sarà fuoriuscire al di fuori il suo contenitore, e non aggiungere il ... alla fine. In Chrome e Firefox Stable funziona come previsto.

+0

Su webkist sembra bene, ma se avete bisogno della vostra soluzione di lavoro cross browser, si prega di considerare l'utilizzo di soluzioni di JS come http: // dotdotdot .frebsite.nl/ – GibboK

+1

Questa domanda è stata contrassegnata come duplicata, ma duplicata di cosa? Credo che sia [questo] (http://stackoverflow.com/questions/12022288/how-to-keep-a-flex-item-from-overflowing-due-to-its-text), ma trovo l'attuale thread più semplice da leggere. – Tibo

risposta

51

Questo è stato infine rintracciato in recenti cambiamenti in Firefox Nightly. Per farla breve, impostando min-width: 0 sul selettore .column, il lavoro funzionerà come previsto.

Una risposta più completa può essere trovata here. Nota:

"Fondamentalmente: gli elementi flessibili si rifiuteranno di restringersi al di sotto della larghezza intrinseca minima, a meno che non si specifichi esplicitamente" larghezza min "o" larghezza "o" larghezza massima "su di essi."

La soluzione di lavoro:

.container { 
 
    width: 300px; 
 
    background: red; 
 
} 
 

 
.row { 
 
    display: flex; 
 
    flex-direction: row; 
 
    flex-wrap: wrap; 
 
} 
 

 
.column { 
 
    /* This will make it work in Firefox >= 35.0a1 */ 
 
    min-width: 0; 
 
    flex-basis: 50%; 
 
} 
 

 
.column p { 
 
    background: gold; 
 
    text-overflow: ellipsis; 
 
    overflow: hidden; 
 
    white-space: nowrap; 
 
}
<div class="container"> 
 
    <div class="row"> 
 
    <div class="column"> 
 
     <p>Captain's Log, Stardate 9529.1: This is the final cruise of the starship Enterprise under my command. This ship and her history will shortly become the care of another crew. To them and their posterity will we commit our future. They will continue the voyages we have begun and journey to all the undiscovered countries boldly going where no man, where no one has gone before.</p> 
 
    </div> 
 
    <div class="column"> 
 
     <p>Captain's Log, Stardate 9529.1: This is the final cruise of the starship Enterprise under my command. This ship and her history will shortly become the care of another crew. To them and their posterity will we commit our future. They will continue the voyages we have begun and journey to all the undiscovered countries boldly going where no man, where no one has gone before.</p> 
 
    </div> 
 
    </div> 
 
</div>

Problemi correlati