0

Hi all I have an h2 element like so:

<h2 id="back">Back</h2>

and I added an image before:

#back::before {
    background-image: url(/images/arrow.png);
    background-size: 20px 30px;
    display: inline-block;
    width: 30px;
    height: 40px;
    content: "";
    background-repeat: no-repeat;
    background-position: center;
}

However the output is the screenshot attached...my question is how do I get my arrow to be aligned in the middle and before the text. How would I do that?

enter image description here

user979331
  • 10,209
  • 56
  • 186
  • 339

2 Answers2

2

You can simply do this with flex:

#back{
display: flex;
align-items:center;
justify-content:center;
....
}
#back::before{
width: 20px;
height: 20px;
rest of your styling
}
alex067
  • 2,646
  • 1
  • 8
  • 16
0
#back::before {
    background-image: url(/images/arrow.png);
    background-size: 20px 30px;
    display: inline-block;
    width: 30px;
    height: 40px;
    content: "";
    background-repeat: no-repeat;
    background-position: center;
    vertical-align: middle;
}

Try vertical align property.

9841pratik
  • 187
  • 7