1

Hello I have a div with the following CSS

{background: purple; max-width: 800px; min-width: 300px; height: 200px; float: left;}

Unfortunately it is being forced to min width (if I remove float it is fine).

Is this just what floats do, or have I made an error somewhere?

JSFiddle:

http://jsfiddle.net/bhY3H/

4

1 回答 1

0

这是预期的行为。
Adiv是块元素,宽度为 100%(如果未应用 css 规则)。
但是如果你浮动 div,你正在修改它的原始流,它停止表现得像一个块,它需要根据其内容所需的宽度(或由 min-width/max-width 指定的宽度)。

所以,不,你没有做错任何事。

编辑:如果我正确理解你想要达到的目标,如果你添加width:100%到你的 div 样式会发生什么?

http://jsfiddle.net/gPTrT/1/

于 2013-08-10T01:28:56.643 回答