2017-02-28 34 views
-3

的中间,我想垂直中心旁边的文字上的图像左,但似乎做中心文字图像

.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>

继承人的一个例子的codepen什么我有。

CodePen Link

+0

是这样的吗? http://codepen.io/mcoker/pen/xqwPgE –

+1

请在问题本身而不是第三方网站上提供[mcve]中的所有相关代码。 –

+0

[在HTML图像上水平垂直居中文本(绝对定位)]的可能重复(http://stackoverflow.com/questions/34955797/horizo​​ntally-vertically-center-text-over-an-html-image-absolute-定位) –

回答

1

假设你正在谈论在页面底部的分享按钮,只需添加vertical-align: middle;到图像的CSS属性将垂直居中旁边的文本。

1

img元素添加一个垂直对齐,以将正在处理的文本拉到外部div标记的中心。像这样:

img { 

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

    vertical-align: middle; 
    } 
0

我相信你与你的CSS一些嵌套错误以及 你也有高度,哪些应该被移动到你的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>