html – 弹性项目的等高儿童
我在创建一个flexbox响应网格时遇到了问题,并希望有人可以指出我正确的方向.
我希望所有的.block div都是相同的高度,而.bottom div绝对位于底部.这实际上是在当前的解决方案中工作,但是当h2标题太长并且达到2行时,我希望该行的所有h2标题都是相同的高度. 这有可能吗? 我做了一个Codepen来说明问题: h1,h2,h3 { margin: 0; } body { margin: 0; padding: 0; } ul.clean-list { margin: 0; padding: 0; } ul.clean-list li { list-style: none; margin-bottom: 5px; } li:last-child { margin-bottom: 0; } .container { padding-top: 50px; } .block { margin-bottom: 30px; border: 1px solid red; } .block > .bottom { border: 1px solid blue; } @media only screen and (min-width: 480px) { .row.row-flex-wrapper::before,.row.row-flex-wrapper::after { content: none !important; } .row.row-flex-wrapper::after { clear: none; } .row.row-flex-wrapper { display: -webkit-flex; display: -ms-flexbox; display: flex; flex-wrap: wrap; -webkit-flex-wrap: wrap; -ms-flex-wrap: wrap; } .row.row-flex-wrapper .column { display: -webkit-flex; display: -ms-flexbox; display: flex; float: none; border: 1px solid orange; } .row.row-flex-wrapper .column > .block { display: -webkit-flex; display: -ms-flexbox; display: flex; flex-direction: column; -ms-flex-direction: column; -webkit-flex-direction: column; } .row.row-flex-wrapper .column > .block > .block-list { flex: 1 0 auto; -ms-flex: 1 0 auto; -webkit-flex: 1 0 auto; } .row.row-flex-wrapper .column > .block > h2 {} } @media only screen and (min-width: 480px) and (max-width: 767px) { .container .row .column { width: 50%; } } <div class="container"> <div class="row row-flex-wrapper"> <div class="column col-sm-6 col-md-4"> <div class="block"> <h2>Title 1</h2> <div class="block-list"> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,but also the leap into electronic typesetting,remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> </div> <div class="bottom"> <ul class="clean-list"> <li><a href="/button">Some link</a> </li> <li><a href="/button">Some link 2</a> </li> </ul> </div> </div> </div> <div class="column col-sm-6 col-md-4"> <div class="block"> <h2>Another very long title which is actually toooo long...</h2> <div class="block-list"> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,when an unknown printer...</p> </div> <div class="bottom"> <ul class="clean-list"> <li><a href="/another-button">Another button</a> </li> </ul> </div> </div> </div> <div class="column col-sm-6 col-md-4"> <div class="block"> <h2>Title</h2> <div class="block-list"> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,when an unknown printer,Lorem Ipsum has been the industry's standard dummy text...</p> </div> <div class="bottom"> <ul class="clean-list"> <li><a href="/button">Very nice link</a> </li> </ul> </div> </div> </div> <div class="column col-sm-6 col-md-4"> <div class="block"> <h2>This block is cool!</h2> <div class="block-list"> <p>Some text here. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,Lorem Ipsum has been the industry's standard dummy text...</p> </div> <div class="bottom"> <ul class="clean-list"> <li><a href="/button">Another link</a> </li> <li><a href="/button">Check this item</a> </li> </ul> </div> </div> </div> <div class="column col-sm-6 col-md-4"> <div class="block"> <h2>Title Block</h2> <div class="block-list"> <p>Go check out this item... Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,Lorem Ipsum has been the industry's standard dummy text...</p> </div> <div class="bottom"> <ul class="clean-list"> <li><a href="/button">Button</a> </li> </ul> </div> </div> </div> <div class="column col-sm-6 col-md-4"> <div class="block"> <h2>Buttonssssss</h2> <div class="block-list"> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> </div> <div class="bottom"> <ul class="clean-list"> <li><a href="#button">Button</a> </li> </ul> </div> </div> </div> <div class="column col-sm-6 col-md-4"> <div class="block"> <h2>Title</h2> <div class="block-list"> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> </div> <div class="bottom"> <ul class="clean-list"> <li><a href="/button">Link to item</a> </li> <li><a href="/button">Link to item</a> </li> </ul> </div> </div> </div> <div class="column col-sm-6 col-md-4"> <div class="block"> <h2>Title</h2> <div class="block-list"> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> </div> <div class="bottom"> <ul class="clean-list"> <li><a href="/button">Link to item</a> </li> </ul> </div> </div> </div> <div class="column col-sm-6 col-md-4"> <div class="block"> <h2>Another very very very very very very very long title</h2> <div class="block-list"> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> </div> <div class="bottom"> <ul class="clean-list"> <li><a href="/button">Button to item</a> </li> </ul> </div> </div> </div> </div> </div> 解决方法
一般来说,这对于flexbox或CSS是不可能的.
flex容器的初始设置是align-items:stretch.这会导致弹性项目扩展到cross axis的全长.这就是所谓的“弹性相等高度列”. 以下是一些要记住的注意事项: >等高列仅适用于Flex容器的子项.换句话说,flex项必须具有相同的父项.否则,等高特征不适用. 你的问题:
不是用CSS.因为h2存在于不同的容器中,它们不是兄弟姐妹(它们更像堂兄弟),所以不同的高度不适用. 有关: > Equal height rows in a flex container (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |