Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Setting a text as a centered background to another text

I would like to have something similar to this:

photo

but with the text over the question mark (the text should strike through the middle of the question mark)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve been trying to do it myself but I can’t really figure out how to do it.

Here’s my result so far:

.quiz-question {
    position: relative;
    font-size: 4rem;
}

.quiz-question::before {
   content: "?";
   font-size: 7rem;
   position: absolute;
   top: -40%;
   left: 0;
   bottom: 0;
   right: 0;
   z-index: -1;
   overflow: hidden;
   text-align: center;
}
<div class="quiz-question">
            This is a test text.
</div>

The problem is that the background "?" is not centered horizontally and also that it is centered vertically because of the hard-coded top: -40%.

How can I fix these problems?

>Solution :

.quiz-question {
  position: relative;
  font-size: 4rem;
  
  /* Added by me */
  display: inline-block;
}

.quiz-question::before {
  content: "?";
  font-size: 7rem;
  position: absolute;
  
  /* Added by me */
  top: 50%;
  transform: translateY(-50%);
  /* bottom: 0; */
  
  left: 0;
  right: 0;
  z-index: -1;
  overflow: hidden;
  text-align: center;
}
<div class="quiz-question">
  This is a test text.
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading