【问题标题】:How can I get my image to be vertically aligned in the center with respect to a dynamic div on it's left?如何让我的图像相对于左侧的动态 div 在中心垂直对齐?
【发布时间】:2016-02-05 07:39:38
【问题描述】:

所以我有一个引导行,其左侧的文本内容位于 4 列的 div 中,右侧的图像位于另一个 8 列的 div 中。现在,在基于平板电脑的视图中,我需要我的图像相对于其左侧的文本位于其容器的确切中心(可以添加新文本,因此图像相对于文本的中心对齐应该是动态的)

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>

对于 CSS:我现在所做的是硬编码一个值,以确保它以上面的 p 标签为中心,但是当我添加新的 Lorem Ipsum 文本时,它没有居中。我需要的是当 p 标签中的文本发生变化时图像的动态居中。

CSS:

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

【问题讨论】:

  • 为什么你有两次transform 属性?我也很欣赏 jsFiddle 演示,也许是所需效果的图像

标签: html css twitter-bootstrap


【解决方案1】:

transform 对您没有帮助,您需要删除 float: left 并尝试添加

显示:内联块;
垂直:中间;

【讨论】:

    猜你喜欢
    • 2015-08-19
    • 2014-11-17
    • 2014-11-23
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 2011-11-12
    相关资源
    最近更新 更多