2015-03-26 6 views
7

I have this simple div with a button inside of it. justify-content: center; funktioniert Firefox und Chrome, aber funktioniert nicht auf IE 11:Warum nicht gerechtfertigt-Inhalt: Center Arbeit in IE?

#div { 
 
    height: 200px; 
 
    width: 50px; 
 
    border: 1px solid black; 
 
    display: flex; 
 
    flex: 0 0 auto; 
 
    align-items: center; 
 
    justify-content: center; 
 
} 
 
#button { 
 
    height: 50px; 
 
    width: 200px; 
 
    min-width: 200px; 
 
    border: 1px solid black; 
 
    background-color: red; 
 
}
<div id="div"> 
 
    <button id="button">HELLO</button> 
 
</div>

Mein Ziel ist es, dass, wenn ich transform mit rotate(90deg) oder rotate(270deg), the button will fit into the div:

#div { 
 
    height: 200px; 
 
    width: 50px; 
 
    border: 1px solid black; 
 
    display: flex; 
 
    flex: 0 0 auto; 
 
    align-items: center; 
 
    justify-content: center; 
 
} 
 
#button { 
 
    height: 50px; 
 
    width: 200px; 
 
    min-width: 200px; 
 
    border: 1px solid black; 
 
    background-color: red; 
 
    transform: rotate(90deg); 
 
}
<div id="div"> 
 
    <button id="button">HELLO</button> 
 
</div>

Die height und width der div und button sind immer die gleichen, sind aber anpassbar.

So viel wie möglich, ich bevorzuge keine Verpackung Elemente.

Antwort

17

IE11 benötigt das übergeordnete Element flex-direction: column.

Dieses Beispiel hat Ihre Knopf gedreht:

#div { 
 
    height: 200px; 
 
    width: 50px; 
 
    border: 1px solid black; 
 
    display: flex; 
 
    align-items: center; 
 
    justify-content: center; 
 
    flex-direction: column 
 
} 
 
#button { 
 
    height: 50px; 
 
    width: 200px; 
 
    min-width: 200px; 
 
    border: 1px solid black; 
 
    background-color: red; 
 
    transform: rotate(90deg); 
 
}
<div id="div"> 
 
    <button id="button">HELLO</button> 
 
</div>

+0

Ich dachte, flex-Richtung, um die Hauptachse für die Eltern zugeordnet. Wenn Sie also auf Zeile setzen, sollte 'justify-content: center' den Inhalt entlang der horizontalen Achse zentrieren. Wenn Sie die Spalte explizit angeben, sollte der Inhalt entlang der Vertikalen zentriert werden. IE11 scheint "justify-content: center" in einer Zeile nicht zu respektieren. – ChrisPEditor

Verwandte Themen