2

I want the borders of my divs to look like this

                        outer div #info
 ------------------------------------------------------------
 | |-----------------||-----------------||-----------------||
 | |                 ||                 ||                 ||
 | |                 ||                 ||                 ||
 | |                 ||                 ||                 ||
 | |      1 inner    ||      2 inner    ||     3 inner     ||
 | |        div      ||        div      ||       div       ||
 | |                 ||                 ||                 ||
 | |  #leftpannel    ||  #centerpannel  ||  #rightpannel   ||
 | |                 ||                 ||                 ||
 | |                 ||                 ||                 ||
 | |-----------------||-----------------||-----------------||
 |----------------------------------------------------------|

but when I put it in a browser it looks like

 ------------------------------------------------------------
 |                    |-----------------||-----------------||
 |                    |                 ||                 ||
 |                    |                 ||                 ||
 |                    |                 ||                 ||
 |                    |      2 inner    ||    3 inner      ||
 |                    |        div      ||      div        ||
 |                    |                 ||                 ||
 |                    |                 ||                 ||
 |                    |                 ||                 ||
 |                    |                 ||                 ||
 |                    |-----------------||-----------------||
 ||------------------|--------------------------------------|
  |                  |                   
  |                  |
  |                  |
  |                  |
  |      1 inner     |
  |        div       |
  |                  |
  |                  |
  |                  |
  |                  |
  |------------------|

this is my css

#rightpannel
{
   width:32%;
   float:right;
   height:390px;
   border: solid;
   border-width:1px;
   border-color:green;
}
#centerpannel
{
    width:32%;
    display:inline;
    margin-left:auto;
    margin-right:auto;
    height:390px;
    border: solid;
    border-width:1px;
    border-color:green;
}
#leftpannel
{
    width:32%;
    float:left;
    height:390px;
    border: solid;
    border-width:1px;
    border-color:green;
}
#info
{
    width:92%;
    height:400px;
    border: solid;
    border-width:1px;
    border-color:red;
    margin:0 auto;
    padding-left: 5px;
    padding-right: 5px;
    padding-top: 5px;
    padding-bottom: 0px;    
}

and this is my html

<div id="info">     
    <div id="rightpannel"></div>        
    <div id="centerpannel"></div>       
    <div id="leftpannel"></div> 
</div>

I really do not know why this is happening and I appreciate any help thanks in advance

4

3 回答 3

3

主 div 的宽度不足以容纳其他 3 个。填充、边距和边框都需要考虑在内。设置小提琴并进行测试,但最终您需要使用数字来获得所需的结果。

也值得查看盒子模型以获得更清晰的理解

永远不要使用表格来对齐 div。那个业余的和丑陋的!表格用于表格数据。结尾。

于 2013-07-22T23:03:51.057 回答
2

尝试这个

#rightpannel {
width:32%;
float:right;
height:390px;
border: solid;
border-width:1px;
border-color:green;
margin-left:1%;
}
#centerpannel {
width:32%;
float:right;
height:390px;
border: solid;
border-width:1px;
border-color:green;
margin-left:1%;
}
#leftpannel {
width:32%;
float:right;
height:390px;
border: solid;
border-width:1px;
border-color:green;
}
#info {
width:100%;
height:400px;
border: solid;
border-width:1px;
border-color:red;
margin:0 auto;
padding: 5px 5px 5px 0;
}

例子

您仍然需要稍微更改边距填充。

于 2013-07-22T23:21:00.570 回答
1

您可以稍微简化一些事情并使用一个类而不是 3 个 ID,但看起来为了使 3 列布局“牢不可破”并且可以重新调整大小,您可能需要使用一点 JavaScript ...

工作示例

HTML

<div id="info">
    <div class="pannel"></div>
    <div class="pannel"></div>
    <div class="pannel"></div>
</div>

CSS

.pannel {
    display:inline-block;
    float:left;
    height:390px;
    border: solid;
    border-width:1px;
    border-color:green;
    margin: 2px;
}
#info {
    width:90%;
    height:400px;
    border: solid;
    border-width:1px;
    border-color:red;
    margin:0 auto;
    padding:5px 2px 0 2px;
}

JS

var pannel = function(){
    var x = $('#info').width() / 3 - 6.3;
$('.pannel').width(x);
};

$(document).ready(pannel);
$(window).resize(pannel);
于 2013-07-22T23:04:44.257 回答