1

How do I align this content word in middle of rectangle. Word 'test' is on the top. I used everything, text-align:center; vertical-align:middle, justify-content:center, align-items: center, and still not working

.rectangle {
  height: 75px;
  width: 75px;
  color:white;
  background-color: rgb(77,77,77);
  border-radius:7px;
  text-align:center;
  vertical-align:middle;
  justify-content:center;
  align-items: center;
}
<div class="rectangle"> 
  Test
</div>
jerrythomas38
  • 759
  • 2
  • 16
  • 41

2 Answers2

7

You almost had it. You're using the properties justify-content and align-items, but not the flex display that these properties require to work. Furthermore, I removed text-align: center and vertical-align: middle, as they are no longer needed.

.rectangle {
  height: 75px;
  width: 75px;
  color:white;
  background-color: rgb(77,77,77);
  border-radius:7px;
  display: flex;
  justify-content:center;
  align-items: center;
}
<div class="rectangle"> 
  Test
</div>
Andy Hoffman
  • 18,436
  • 4
  • 42
  • 61
3

You forgot to add display: flex or display:grid :)

.rectangle {
      height: 75px;
      width: 75px;
      color: white;
      display: flex;
      background-color: rgb(77, 77, 77);
      border-radius: 7px;
      justify-content: center;
      align-items: center;
    }
<div class="rectangle">
    Test
  </div>
Grzegorz T.
  • 3,903
  • 2
  • 11
  • 24