使浮动div的位置不受其内容的影响,不设置宽度

时间:2012-11-15 03:09:21

标签: html css-float

我想做这个布局,div2的宽度不会受到他内容的影响

-----------------------------------------
          |      |               |
   div1   |      |      div2     |      
          |      |               |       
-----------------------------------------

这是我的代码:

    <html>
    <body>

    <div style="background:red;height:200px;">

        <div  style="background:black;width:100px;float:left;height:100px;">

        </div>


        <div  style="background:green;height:50px;float:left;margin:10px;">
        when here the content is too much, this div will start another line, 
which is not wanted, I want this div to be float always, also , I dont know the with.
        </div>

    </div>


    <body>
    </html>

那么,怎么样?

1 个答案:

答案 0 :(得分:1)

添加css属性

max-width:100px