背景颜色不填div [英] Background colour not filling div

查看:136
本文介绍了背景颜色不填div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个例子,我想我的包装div有一个红色的背景颜色,它会填充下来,因为其他的div放在里面。

For an example I want my wrapper div to have a red background color and it will fill down as other divs are placed inside it.

但是由于它是使用margin:auto;并且其内部的div是浮动的,颜色不继续向下。如果我删除margin自动并替换为float:left;然后颜色将继续它应该。

However since it is centered using margin: auto; and the divs inside it are floated left the colour does not continue down. If i remove the margin auto and replace it with float:left; then the colour will continue as it should.

我已经通过保持我的边缘自动和使用overflow:hidden允许颜色向下流动。然而对于这个网站,我正在努力,我需要保持溢出可见。

I have got around this by keeping my margin auto and using overflow: hidden which allows the colour to flow down. However for this site i am working on I need to keep the overflow visible.

有没有另一种方式,我可以让这个工作?如果你知道,你能解释为什么溢出隐藏的工作方式。

Is there another way I can get this to work? Also if you know, could you explain why overflow hidden works in the way it does.

谢谢

推荐答案

解决方法是把一个div里面的div ...

The workaround is to put a div inside that div...

像这样...

<div id="container"> 

   <div id="colordiv">

   <div></div>
   <div></div>
   <div></div>

  </div>

</div>

其中container是自动边距为container的颜色div是100%

Where container is an auto margined 'container', and the color div is 100% color fill for that container.

这样,你可以使主容器有任何宽度,其余的将跟随,颜色继续到内容

This way you can make the main container any width, the rest will follow, and the color continues as far as the content

此处的演示

其他示范 - 较小的div

至于你的溢出问题....我不知道为什么这种情况下

As for your overflow question....Im not sure at all why thats the case

这篇关于背景颜色不填div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆