1

使用样式,想在我的 Web 应用程序中并排放置两个 div,就像在 stackoverflow 左侧部分那样。我试过了

<div style="width:60%; " >

</div>

  <div style="width:40%; ">    

</div>

但是 div 正在下一行到另一个 div,我希望 div 以 60% 和 40% 的宽度并排出现。你能帮助我吗

4

2 回答 2

2

Add float:left to both the divs and it should work

Demo : http://jsfiddle.net/JvBJT/

于 2012-09-05T09:55:58.103 回答
0

虽然我不热衷于使用浮动来对齐事物......你可以这样做......它将屏幕分成两个 div 元素(有点像框架)

<!DOCTYPE html>
<html>
    <head>
        <title>Template</title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <style type="text/css">
            html, body
            {
                /* height: 100%; removed as per user comments */ 
            }

            .div1
            {
                background: none repeat scroll 0 0 #FF0000;
                display: inline-block;
                /* height: 100%; removed as per user comments */ 
                width: 60%;
                float: left;
            }

            .div2
            {
                background: none repeat scroll 0 0 #0000FF;
                display: inline-block;
                /* height: 100%; removed as per user comments */ 
                width: 40%;
                float: left;
            }
        </style>
    </head>
    <body>
        <div class="div1">
            I am Div1 and this is my content<br/>
            I am Div1 and this is my content<br/>
            I am Div1 and this is my content<br/>
            I am Div1 and this is my content<br/>
            I am Div1 and this is my content<br/>
        </div>
        <div class="div2">
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
            I am Div2 and this is my content<br/>
        </div>
    </body>
</html>
于 2012-09-05T10:00:20.357 回答