简体   繁体   English

扩展浮动div的高度,直到父div的底部

[英]Extending floated div height until the bottom of the parent div

I have two divs that are floated left and right. 我有两个div左右浮动。 They are inside a parent div with overflow hidden. 它们位于父div内,其中隐藏了溢出。 Problem is, the one floated right is longer than the other and this other div doesn't extend until the bottom of the parent div so there's a huge patch of grey on the left. 问题是,一个浮动的右边比另一个浮动的要长,而另一个div直到父div的底部才扩展,因此左侧有一个巨大的灰色区域。

Here's my code: 这是我的代码:

<div class="content">
 <div class="left">
    Blue Bottle pork belly messenger bag squid narwhal. Yr craft beer iPhone pug, flexitarian PBR&B retro chia wayfarers. Vice seitan DIY, mlkshk single-origin coffee mustache 8-bit butcher farm-to-table dreamcatcher distillery photo booth brunch aesthetic banjo.
 </div>

 <div class="right">
    Wolf forage flannel seitan, vinyl small batch authentic Etsy plaid swag. Ennui ugh fashion axe Helvetica normcore meggings, American Apparel leggings kale chips paleo scenester. Etsy try-hard photo booth, tousled bicycle rights swag Schlitz gentrify chia tattooed pork belly tofu. Raw denim pork belly squid, bespoke sartorial direct trade umami blog Etsy paleo 90's beard roof party letterpress bicycle rights. Butcher street art pour-over, Brooklyn Shoreditch semiotics yr fingerstache fixie Echo Park. Readymade irony gastropub ethical Pitchfork. Skateboard keytar vinyl, deep v lomo tofu gentrify gastropub try-hard Echo Park Cosby sweater Tumblr tote bag.
 </div>

 <div class="clear"></div>
</div>

Here's a fiddle of it. 这是一个小玩意儿

You can add min-height to your .right and .left divs: 您可以在.right.left div中添加min-height

.left, .right{
    min-height:100px;  // or one can select 100% as per requirement
}

Option 1: Use a background gradient 选项1:使用背景渐变

http://dabblet.com/gist/2957349/857c8069b850252a5eaf3b06ad243b6f22632952 If you're looking for a purely asthetic fix up then you can consider a CSS gradient running down the parent (#content) to simulate the equal height of both divs http://dabblet.com/gist/2957349/857c8069b850252a5eaf3b06ad243b6f22632952如果您正在寻找纯粹的美学修复方法,则可以考虑沿父级(#content)运行CSS渐变,以模拟两个div的相等高度

Option 2: There are other CSS/HTML options available 选项2:还有其他CSS / HTML选项可用

http://css-tricks.com/fluid-width-equal-height-columns/ http://css-tricks.com/fluid-width-equal-height-columns/

Option 3: Use JS 选项3:使用JS

http://css-tricks.com/equal-height-blocks-in-rows/ http://css-tricks.com/equal-height-blocks-in-rows/

Option 4: Fix the height of the parent and columns with CSS 选项4:使用CSS固定父级和列的高度

This however won't make it very flexible for varying amounts of text, but it's an option. 但是,这对于可变数量的文本来说并不十分灵活,但这是一个选择。

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

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