2017-12-05 10 views
1

Problem Statement: Zentriert nichtText innerhalb div wont Zentrum

Relevante Code passiert:

#tekst { 
 
    font-family: 'Roboto', sans-serif; 
 
    font-size: 14px; 
 
    color: #EFEFEF; 
 
    width: 100%; 
 
    height: 30%; 
 
} 
 

 
#innhold { 
 
    width: 100%; 
 
    height: 30%; 
 
    top: 18%; 
 
    left: 0%; 
 
    background-color: #7e7e7e; 
 
    position: absolute; 
 
    border-radius: 5px; 
 
    z-index: 2; 
 
}
<div id="innhold"> 
 
    <div id="tekst"> text </div> 
 
</div>

jede mögliche Hilfe würde geschätzt.

+0

Verwenden CSS-Eigenschaft 'text-align: center' –

+1

Mögliche Duplikat von [ Text zentrieren in div?] (Https://stackoverflow.com/questions/6055412/center-text-in-div) – ArneHugo

Antwort

1

Sie können text-align:center; verwenden, um Text zu zentrieren.

#tekst { 
 
    font-family: 'Roboto', sans-serif; 
 
    font-size: 14px; 
 
    color: #EFEFEF; 
 
    width: 100%; 
 
    height: 30%; 
 
    text-align: center; 
 
} 
 

 
#innhold { 
 
    width: 100%; 
 
    height: 30%; 
 
    top: 18%; 
 
    left: 0%; 
 
    background-color: #7e7e7e; 
 
    position: absolute; 
 
    border-radius: 5px; 
 
    z-index: 2; 
 
}
<div id="innhold"> 
 
    <div id="tekst"> text </div> 
 
</div>

+1

"' text-align: center' muss benutzt werden ", so habe ich es gelesen. – UncaughtTypeError

+1

@UncaughtTypeError Umzug in die Stadt, die ich habe, vermische ich muss. –

-2

Sie benötigen text-align:center; die CSS-Eigenschaft hinzuzufügen.

Hoffe, das hilft.

#tekst { 
 
    font-family: 'Roboto', sans-serif; 
 
    font-size: 14px; 
 
    text-align:center; 
 
    color: #EFEFEF; 
 
    width: 100%; 
 
    height: 30%; 
 
} 
 

 
#innhold { 
 
    width: 100%; 
 
    height: 30%; 
 
    top: 18%; 
 
    left: 0%; 
 
    background-color: #7e7e7e; 
 
    position: absolute; 
 
    border-radius: 5px; 
 
    z-index: 2; 
 
}
<div id="innhold"> 
 
    <div id="tekst"> text </div> 
 
</div>

1

Zum Zentrieren Sie Ihren Text vollständig können Sie Flexbox verwenden:

#tekst { 
 
    font-family: 'Roboto', sans-serif; 
 
    font-size: 14px; 
 
    color: #EFEFEF; 
 
    height: 30%; 
 
} 
 

 
#innhold { 
 
    width: 100%; 
 
    height: 30%; 
 
    top: 18%; 
 
    left: 0%; 
 
    background-color: #7e7e7e; 
 
    position: absolute; 
 
    border-radius: 5px; 
 
    z-index: 2; 
 
    display: flex; 
 
    justify-content: center; 
 
    align-items: center; 
 
}
<div id="innhold"> 
 
    <div id="tekst"> text </div> 
 
</div>