【问题标题】:Setting a height of container, while content doesn't have specified height - only padding设置容器的高度,而内容没有指定的高度 - 仅填充
【发布时间】:2016-08-03 18:08:19
【问题描述】:

我想不出解决办法。我有很多这样的方形 div: width=padding-bottom=16,6%

它在有许多 (72) 个正方形的屏幕上制作了一个漂亮的网格。每个内部都有一个带有图像的背景属性。

问题是我也有一个固定的底部条纹,我的问题是它与网格的最后一行重叠。

如何设置 margin-bottom ?没有指定 div 的高度。

我试图把它全部放在一个div中,但它认为内容的高度是0。

下面的代码,感谢您的任何想法。

HTML:

<div class="homemade-container">
<div class="square img_1-2"> </div>
THERE IS 72 DIVS LIKE THIS ONE, JUST WITH DIFFERENT SECOND CLASS NUMBER (BACKGROUND IMAGE)
</div>
<div class="lowermenu">
CONTENT
</div>

CSS:

.homemade-container{
    padding-bottom:75px;
}
.square{
    float:left;
    position: relative;
    width: 16.45%;
    padding-bottom : 16.45%;
    margin:0.1%;
    background-position:top center;
    background-repeat:no-repeat;
    background-size:cover;
}
.img_1-2{
    background-image:url('../portfolio/www/www24.jpg');
}
.lowermenu{
    color:#d4d4d4;
    width:100%;
    height:75px;
    background-color:#2b2b2b;
    position:fixed;
    bottom:0;
    left:0;
}

【问题讨论】:

    标签: html css grid height padding


    【解决方案1】:

    您可以简单地通过 CSS 为最后一个 div 添加边距:

    div[class~='square']:last-of-type {
        margin-bottom: 90px;
    }
    

    【讨论】:

    • :last-of-type 不会像您希望的那样适用于类(它只适用于元素),但无论如何您的想法对我有所帮助。感谢您解开我的思绪 :) 我刚刚将 .last 类添加到最后一个 div 并添加了一个 margin-bottom 。再次感谢!
    • 实际上,根据文档,您是对的,在这方面它只能与属性选择器一起使用。虽然我做了一个快速的小提琴并实际在类元素作品上使用它。 jsfiddle.net/bkpLybkp 那应该不行吧?
    • 嗯,你是对的,它在你的小提琴中工作,当我用我的文件尝试它时它不是。也许这只是对小提琴本身的过度解读,而不是验证代码?
    • 不确定,当我尝试使用 .html 和 .css 文件时,也可以使用最新的 Crome 版本。也许这是一种 webkit 行为?
    猜你喜欢
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 2012-02-11
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    相关资源
    最近更新 更多