html - 将两列与图像和文本并排放置

标签 html css

大家好,目前我有以下内容:

.iconcontainer.first, .iconcontainer.second {
    display: inline-block;
}
.iconcontainer img {
    display: block;
    margin: 0 auto;
    text-align: center;
    width:50%;
    height:50%;
}
p {
    text-align: center;
    font-family:'Lato', sans-serif;
    font-weight: 400;
}
.fullhome {
    background-color: #FEF1D9;
    height: 100%;
}
<div class="fullhome">
    <div class='fulliconcontainer'>
        <div class='iconcontainer first'>
            <img class='homeicons1' src="http://localyz.com/wp-content/uploads/2014/09/local-seo-reviews-icon.png">
            <p>I want this under first image</p>
        </div>
    </div>
    <div class='iconcontainer second'>
        <img class='homeicons1' src="http://www.pd4pic.com/images800_/flat-keyboard-theme-typing-icon-types.png">
        <p>I want this under second image</p>
    </div>
</div>

我想做的是将 iconcontainer1iconcontainer2 中的内容并排放置,以创建两列的效果。由于某种原因,iconcontainer2 掉到了底部。有谁知道如何解决这一问题?我认为 inline-block 可以解决这个问题。

最佳答案

具有 inlineinline-block 的两个元素之间始终有一个空格。您可以通过执行 float: left 来 float 这两个元素。

如果您想使用inline-block,请确保删除spacenewline以删除它们之间的空格。

根据您的情况,您必须这样做:

<div class='iconcontainer first'>
    <img class='homeicons1' src="http://localyz.com/wp-content/uploads/2014/09/local-seo-reviews-icon.png">
    <p>I want this under first image</p>
  </div><div class='iconcontainer second'>
  <img class='homeicons1' src="http://www.pd4pic.com/images800_/flat-keyboard-theme-typing-icon-types.png">
  <p>I want this under second image</p>
</div>

更新:

没有注意到您将 50% 放入 img 元素中,这是错误的。您应该将其放在 .iconcontainer.first、.iconcontainer.second 容器上。

你的最终 CSS 应该是这样的:

.iconcontainer.first, .iconcontainer.second{
  display: inline-block;
  width:50%;
  height:50%;
}

.iconcontainer img {
  display: block;
  margin: 0 auto;
  text-align: center;
  width: 100%;
  height: 100%;
}

p {
  text-align: center;
  font-family: 'Lato', sans-serif;
  font-weight: 400;
}

.fullhome{
  background-color: #FEF1D9;
  height: 100%;
}

工作中Fiddle

关于html - 将两列与图像和文本并排放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30879622/

相关文章:

html - 如何自动换行标题?

javascript - 对动态 HTML 表格应用多重过滤

php - 在 div 中显示行

css - 在div中自动居中超大图像

javascript - 在div中的rails显示中拉出帖子图像

css - 基于子元素的菜单控制CSS

css - Flex box justify-content on main axis in center 除了最后一个 flex item

javascript - 使用jquery查找data*属性而不指定标签

HTML/CSS 背景图像问题

javascript - div 删除/显示而不影响内容