2016-12-22 3 views
1

Ich versuche, den Text in der Mitte der Flexboxen so die große Box h4 und p ist zentriert zu seiner Box, sowie der Text in den beiden kleineren Boxen sind in der Mitte ihrer Boxen. Großartig für jede Hilfe.Center innerhalb, in Flexbox Vollbild

body { 
 
\t -moz-box-sizing: border-box; 
 
\t -webkit-box-sizing: border-box; 
 
\t box-sizing: border-box; 
 
} 
 

 
.equal-height-container { 
 
\t margin: 0 auto; 
 
\t display: flex; 
 
\t height: 100vh; 
 
} 
 
\t 
 

 
.first { 
 
\t background-color: #fff; 
 
\t padding: 20px; 
 
\t flex: 1; 
 
} 
 
    
 

 

 
.second { 
 
\t background-color: yellow; 
 
\t flex: 1; 
 
\t display: flex; 
 
\t flex-direction: column; 
 
} 
 

 

 

 
.second-a { 
 
\t background-color: #c0dbe2; 
 
\t flex: 1; 
 
\t padding: 20px; 
 
} 
 

 

 
.second-b { 
 
\t background-color: honeydew; 
 
\t flex: 1; 
 
\t padding: 20px; 
 
}
<div class="equal-height-container"> 
 
    <div class="first"> 
 
    <h4>Feature1</h4> 
 
    <p>Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit    standard ända sedan 1500-talet.</p> 
 
    </div> 
 
    <div class="second"> 
 
    <div class="second-a"> 
 
     <h4>Feature1</h4> 
 
     <p>Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit    standard ända sedan 1500-talet,</p> 
 
    </div> 
 
    <div class="second-b"> 
 
     <h4>Feature1</h4> 
 
     <p>Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem   ipsum har   varit standard ända sedan 1500-talet,</p> 
 
    </div> 
 
    </div>

Antwort

1

Verwenden align-items: center & justify-content: center.

Auch Ihre .first, .second-a & .second-b machen und die flexible Ausrichtung Eigenschaft in diese auch anzuwenden. Wie:

.equal-height-container { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
} 

.first, .second-a, .second-b { 
    display: flex; 
    align-items: center; 
} 

Werfen Sie einen Blick auf das Snippet unten:

body { 
 
\t -moz-box-sizing: border-box; 
 
\t -webkit-box-sizing: border-box; 
 
\t box-sizing: border-box; 
 
    margin: 0; 
 
} 
 

 
.equal-height-container { 
 
\t margin: 0 auto; 
 
\t display: flex; 
 
    align-items: center; 
 
    justify-content: center; 
 
\t height: 100vh; 
 
} 
 
\t 
 

 
.first { 
 
\t background-color: #fff; 
 
\t padding: 20px; 
 
\t flex: 1; 
 
    display: flex; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
    height: calc(100vh - 40px); 
 
} 
 
    
 

 

 
.second { 
 
\t background-color: yellow; 
 
\t flex: 1; 
 
\t display: flex; 
 
    flex-direction: column; 
 
    height: 100vh; 
 
} 
 

 

 

 
.second-a { 
 
\t background-color: #c0dbe2; 
 
\t flex: 1; 
 
    display: flex; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
    height: calc(100vh - 20px); 
 
\t padding: 20px; 
 
} 
 

 

 
.second-b { 
 
\t background-color: honeydew; 
 
\t flex: 1; 
 
    display: flex; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
    height: calc(100vh - 20px); 
 
\t padding: 20px; 
 
} 
 

 
h4 { 
 
    margin-bottom: 0; 
 
}
<div class="equal-height-container"> 
 
    <div class="first"> 
 
    <h4>Feature1</h4> 
 
    <p>Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit    standard ända sedan 1500-talet.</p> 
 
    </div> 
 
    <div class="second"> 
 
    <div class="second-a"> 
 
     <h4>Feature1</h4> 
 
     <p>Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit    standard ända sedan 1500-talet,</p> 
 
    </div> 
 
    <div class="second-b"> 
 
     <h4>Feature1</h4> 
 
     <p>Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem   ipsum har   varit standard ända sedan 1500-talet,</p> 
 
    </div> 
 
    </div>

hoffe, das hilft!

+0

Leider nein. Dadurch werden die Boxen nur in der Mitte des Bildschirms angezeigt. Wenn Sie das Vollbild-Ergebnis betrachten. Ich wollte die volle Größe der Boxen behalten. Thnx für die Hilfe. – bboogie

+1

@bboogie Das Code-Snippet in meiner Antwort wurde aktualisiert. Bitte guck dir das an. Ich habe '.first',' .second-a' & '.second-b' einen Flex-Container erstellt und die Flex-Alignment-Eigenschaften angewendet. Lassen Sie mich wissen, ob das hilft. –

+0

Saurav Rastogi! Danke, genau so. Habe meinen Tag gerettet! – bboogie

0

hinzufügen text-align: center;-.equal-height-container > div

Wo > die sofortige Kind bedeutet

body { 
 
\t -moz-box-sizing: border-box; 
 
\t -webkit-box-sizing: border-box; 
 
\t box-sizing: border-box; 
 
} 
 

 
.equal-height-container { 
 
\t margin: 0 auto; 
 
\t display: flex; 
 
\t height: 100vh; 
 
} 
 
.equal-height-container > div { 
 
\t text-align: center; 
 
} 
 
\t  
 

 
.first { 
 
\t background-color: #fff; 
 
\t padding: 20px; 
 
\t flex: 1; 
 
} 
 
    
 

 

 
.second { 
 
\t background-color: yellow; 
 
\t flex: 1; 
 
\t display: flex; 
 
\t flex-direction: column; 
 
} 
 

 

 

 
.second-a { 
 
\t background-color: #c0dbe2; 
 
\t flex: 1; 
 
\t padding: 20px; 
 
} 
 

 

 
.second-b { 
 
\t background-color: honeydew; 
 
\t flex: 1; 
 
\t padding: 20px; 
 
}
<div class="equal-height-container"> 
 
    <div class="first"> 
 
    <h4>Feature1</h4> 
 
    <p>Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit    standard ända sedan 1500-talet.</p> 
 
    </div> 
 
    <div class="second"> 
 
    <div class="second-a"> 
 
     <h4>Feature1</h4> 
 
     <p>Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem ipsum har varit    standard ända sedan 1500-talet,</p> 
 
    </div> 
 
    <div class="second-b"> 
 
     <h4>Feature1</h4> 
 
     <p>Lorem Ipsum är en utfyllnadstext från tryck- och förlagsindustrin. Lorem   ipsum har   varit standard ända sedan 1500-talet,</p> 
 
    </div> 
 
    </div>

+0

Ich könnte das Problem falsch formuliert haben. Ich habe vertikale und horizontale Mitte der Boxen. So ist es bis Vollbild, aber nur der Text in ihnen ist vertikal und vertikal in der Mitte. – bboogie

Verwandte Themen