简体   繁体   English

如何使图像相对于左侧的动态div在中心垂直对齐?

[英]How can I get my image to be vertically aligned in the center with respect to a dynamic div on it's left?

So i have a bootstrap row with text content on the left in a div spanning 4 cols and my image on the right in another div spanning 8 cols. 所以我有一个引导行,左边的文本内容跨度为4列,而我的图像在右边的另一行跨越8列。 Now, in the tablet based view i need my image to be in the exact center of it's container with respect to the text on it's left(New text may be added so the center alignment of the image with respect to the text should be dynamic) 现在,在基于平板电脑的视图中,我需要我的图像相对于其左侧的文本位于容器的确切中心(可以添加新文本,因此图像相对于文本的中心对齐应该是动态的)

HTML:
<div class="row">
      <div class="col-sm-8 col-sm-push-4 tab_image">
            <img src="images/event/event-banner-v3.jpg" alt="">

      </div>      
        <div class="col-sm-4 col-sm-pull-8 col-xs-12">
           <p>This year's Bank of Scotland Great Scottish Run, will see thousands of runners to the streets of Glasgow on Sunday 4 October.<br><Br>Join us at the biggest running event in Scotland and soak up the atmosphere provided by thousands supporters lining the streets, music and bands on the run, charity cheering points..</p>        
        </div>
</div>

For CSS: What I've done now is hard coded a value to ensure it is centering to the text wrt the p tag above but when i add new Lorem Ipsum text it's not centered. 对于CSS:我现在所做的是对值进行硬编码,以确保它位于上面带有p标签的文本的中心,但是当我添加新的Lorem Ipsum文本时,它没有居中。 What i need is dynamic centering of the image as and when text in the p tag changes. 我需要的是当p标签中的文本更改时图像的动态居中。

CSS: CSS:

@media (min-width: 768px) and (max-width: 991px){
    .tab_image {
        position: relative;
        transform: translateX(17%);
        transform: translateY(17%);
    }

transform will not help you you need to remove float: left and try to add 变换不会帮助您删除浮点:左并尝试添加

display: inline-block;
vertical: middle;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM