【问题标题】:How to stack two img tags when centered居中时如何堆叠两个img标签
【发布时间】:2014-05-29 04:15:02
【问题描述】:

我正在尝试将两个 img 标签放在彼此上,但让它们都居中。

这是我尝试做的地方:http://nathanturnbull.me/scrolldiv/home.html

HTML:

<div id="divs" class="div1">
    <div class="textcont">
        <img class="imglogo" src="gpk.gif" alt="GPK NET">
        <div class="textcont" >
            <img class="imgbutton" src="gpk.gif">
        </div>
    </div> 
</div>

CSS:

#divs, #div4 {
    height: 100%;
    width: 100%;
    overflow: hidden;
    background-size: cover;
    font-family: 'Cousine';
    font-size: 80px;
    color: #ffffff;
    text-align: center;
}

.div1 {
    display: table;
}

.textcont {
    display: table-cell;
    vertical-align: middle;
    background-color: transparent;
}

.imgbutton {
    height: 42px;
    width: 84px;
}

【问题讨论】:

    标签: css image html cover


    【解决方案1】:
    .container {
        text-align: center;
    }
    
    .container IMG {
        display: inline; /* browser default */
    }
    

    IMG {
        display: block;
        margin: 0 auto;
    }
    

    您的图片应在其容器内水平居中。

    【讨论】:

      【解决方案2】:

      .textcont CSS 类中删除display:table-cell; 语句。

      See example.

      【讨论】:

      • 这确实有效,但现在图像位于页面顶部,而不是位于中间。我该如何解决这个问题?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-20
      • 2013-11-12
      • 2019-03-03
      • 2013-05-14
      • 1970-01-01
      • 2021-04-07
      相关资源
      最近更新 更多