-1

I made an image on which some text apears when I hover the mose over it. I need to move the text in the middle of the image, but I can't find out how.

This is my code:

.home{
    background-image: url("https://www.cvikovacek.cz/wp-content/uploads/2017/08/domecek-270x300.png");
    height: 300px;
    width: 300px;
    background-size: cover;
    font-size: 30px;
    text-align: center;
}
.home:hover{
    background: black;
}
.home:hover::after{
    content: "HOME";
    color: green;
}
<body>
    <div class="home"></div>
</body>

Thanks for any answer.

1 Answers1

1

You can use flex and align it with the justify-content and align-items properties.

.home {
  background-image: url("https://www.cvikovacek.cz/wp-content/uploads/2017/08/domecek-270x300.png");
  height: 300px;
  width: 300px;
  background-size: cover;
  font-size: 30px;
  text-align: center;
}

.home:hover {
  background: black;
}

.home:hover::after {
  content: "HOME";
  color: green;
  /* Changes */
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
<body>
  <div class="home"></div>
</body>
Parco
  • 602
  • 5
  • 12