-3

I would like to vertically center text next to the image on the left but can seem to do it

.socialShare {
  position: relative;
  &__CTA {
    position: absolute;
    bottom: -30px;
    background-color: #d0d0d0;
    padding-right: 18px;
    height: 38px;
    img {
      display: inline;
      height: 38px;
      width: 38px;
    }
    p {
      display: inline;
    }
  }
}
<div class="socialShare">
  <strong>
              <img alt="" src="https://www.asthma.org.uk/globalassets/health-advice/asthma-attacks/what-to-do-if-youre-having-an-asthma-attack.jpg" height="350" width="700" />
            </strong>
  <div class="socialShare__CTA">
    <img src="dist/images/arrow.jpg" alt="">
    <p>Share image</p>
  </div>

heres a codepen for an example what I've got.

CodePen Link

happymacarts
  • 2,547
  • 1
  • 25
  • 33

3 Answers3

1

Assuming you are talking about the share button at the bottom of the page, just add vertical-align: middle; to the CSS property of the image will vertically center the text next to it.

1

Add a vertical-align, to the img element, to pull the proceeding text to the center of the outer div tag. Like so:

  img {

    display: inline;
    height: 38px;
    width: 38px;

    vertical-align: middle;
  }
0

I believe you had some nesting errors with your css as well you also had height and width attributes on the image which should be moved to your css

.socialShare {
  position: relative;
}

.socialShare strong img {
  height: "350px";
  width: "700px";
}

.socialShare__CTA {
  position: absolute;
  bottom: -30px;
  background-color: #d0d0d0;
  padding-right: 18px;
  height: 38px;
}

.socialShare__CTA img {
  display: inline;
  height: 38px;
  width: 38px;
  vertical-align: middle;
  /* <-- add this line */
}

p {
  display: inline;
}
<div class="socialShare">
  <strong>
    <img alt="" src="https://www.asthma.org.uk/globalassets/health-advice/asthma-attacks/what-to-do-if-youre-having-an-asthma-attack.jpg"  />
  </strong>

  <div class="socialShare__CTA">
    <img src="dist/images/arrow.jpg" alt="">
    <p>Share image</p>
  </div>

</div>
happymacarts
  • 2,547
  • 1
  • 25
  • 33