1

Problem Statement : Center alignment not happening

Relevant code:

#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>

any help would be appreciated.

Kalabalik
  • 99
  • 1
  • 10
Ken
  • 65
  • 8

3 Answers3

1

You can use text-align:center; to center text.

#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>
Master Yoda
  • 4,334
  • 10
  • 43
  • 77
1

To fully center your text you can use flexbox:

#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>
Honsa Stunna
  • 577
  • 2
  • 8
  • 24
-2

You need to add the CSS property text-align:center;.

Hope this helps.

#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>
kingmaker
  • 59
  • 6