简体   繁体   English

高度相等的Flexbox,容器的内容物填充高度

[英]Flexboxes of equal height, content filling height of container

Link to the site I'm editing for reference: http://securitysolutionsnw.businesscatalyst.com/fire-life-safety 链接到我正在编辑的网站以供参考: http : //securitysolutionsnw.businesscatalyst.com/fire-life-safety

Here's a CodePen of the thing: http://codepen.io/Murgittroyd/pen/HqEvp 这是一个东西的CodePen: http ://codepen.io/Murgittroyd/pen/HqEvp

I have an unordered list of list items, and I'm trying to get each item to be the same width and height. 我有一个列表项的无序列表,并且我试图使每个项目的宽度和高度都相同。 I've started investigating and using flex-box, which helped, but I can't get the content of each box to fill the whole height of the list item. 我已经开始研究并使用flex-box了,这很有帮助,但是我无法获得每个盒子的内容来填充列表项的整个高度。 Essentially, I need boxes that are dynamically sized but by the size of the largest flexbox...anyone have any ideas? 本质上,我需要具有动态尺寸的盒子,但是需要最大的flexbox的大小...有人有什么想法吗?

HTML: HTML:

<ul class="box-list">
    <li>
        <div class="visual">
            <img src="/images/img07.jpg" width="281" height="187" alt="image description" />
            <div class="hover">
                <a href="/fire-life-safety/fire-extinguishers">
                    <span class="ico"><img src="/images/ico-fire-extinguishers-white-large.png" alt="image description" /></span>
                    <span class="text">Learn More</span>
                </a>
            </div>
        </div>
        <div class="content">
            <h3>
                <span class="ico"><img src="/images/ico-fire-extinguishers-white.png" alt="image description" /></span>
                <span class="text">Fire Extinguishers</span>
            </h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc consectetur sed sem ac facilisis. Proin venenatis nisi ut  elit a scelerisque. </p>
        </div>
    </li>
</ul>

CSS: CSS:

#content .box-list {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -14px 0 0;
    padding: 0;
    list-style: none;
    overflow: hidden;
    color: #fff;
    font-size: 12px;
    line-height: 22px;
}
#content .box-list li {
    float: left;
    padding: 0 14px 43px 0;
    width: 281px;
}
#content .box-list li:after {
    display: none;
}
#content .box-list .content {
    overflow: hidden;
    padding: 18px 20px 33px 33px;
    background: #232a32;
}
#content .box-list .visual {
    position: relative;
    overflow: hidden;
}

Whether or not it's possible with pure CSS depends on your exact needs. 纯CSS是否可行取决于您的确切需求。 If you just need to have each row of li items the same height, then you're already doing it correct. 如果只需li每一行具有相同的高度,那么您已经在正确了。 As you can see with any Element inspection tool, the li items in a row are all the same height (in my Chrome browser at least). 如您使用任何元素检查工具所看到的,连续的li项都具有相同的高度(至少在我的Chrome浏览器中)。 However, the content of your li isn't scaled to fill the full height. 但是,您li的内容未按比例缩放以填满整个高度。

If you need EVERY element on the page the same height, you probably need some JS. 如果页面上的每个元素都需要相同的高度,则可能需要一些JS。

So I've found a solution of sorts, just masking the entire li to appear the same as the .content , since (as Wouter Florijn pointed out) the li were already the same heights due to using flex. 因此,我找到了一种解决方案,只是将整个li屏蔽为与.content相同,因为(如Wouter Florijn指出的那样)由于使用flex, li的高度已经相同。 Here's how I changed some CSS, basically just changed all padding into margin so background-color would fill the li : 这是我更改CSS的方式,基本上只是将所有padding都更改为margin因此background-color将填充li

#content .box-list li {
float: left;
padding: 0 0 0 0;
margin: 0px 14px 43px 0px;
width: 281px;
background-color: #232a32;
}

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

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