gpt4 book ai didi

css - div 的垂直和水平对齐 - 第 2 部分

转载 作者:行者123 更新时间:2023-11-28 12:37:18 25 4
gpt4 key购买 nike

引用Vertical and horizontal align of divs

和这个新代码 http://jsfiddle.net/8B29k/2/

为什么“底部框”没有覆盖整个宽度?

我不想使用 html colspan(在这种情况下不能,因为框将动态生成,我可能自己不知道一个框有多少个上下)

每个盒子都独立于它旁边或上面/下面的盒子。现在表格就是这种情况。如果每个 TR 中有 3 个 TR 和 3 个 TD,我不能使中间的 TR 只有一个 TD 并将其宽度扩展为等于其他 TR(所有 TD 组合)。如果没有 colspan 在 html 中就无法做到这一点。但在这种情况下。我自己不知道周围的 TD。那么解决方案是什么?

这是我要创建的布局:

enter image description here

.board{
display:block;
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;

border: red solid thin;
/**min-height:510px;**/

}


.board-title{
background-color:black;
color:white;
font-size:50px;
}

.board-body{

}

.box{

vertical-align:top;
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;
border: blue solid thin;
/**min-height:500px;**/
min-width:160px;
height:100%;



}

.box-title{

width:100%;
background-color:grey;
font-size:50px;
}

.box-body{
display:table-row;
}

.box-parent{


}

.box-vertical{
display:table-cell;
vertical-align:top:


vertical-align:top;
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;
border: blue solid thin;
/**min-height:500px;**/
min-width:160px;
height:100%;
}

.box-horizontal{
display:table-row;

vertical-align:top;
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;
border: blue solid thin;
/**min-height:500px;**/
min-width:160px;
height:100%;
}



.task{
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;
display:block;
float: left;
border: green solid thin;
width:150px;
height:100px;
}

HTML 看起来像:

<div class="board">
<div class="board-title">board title-
</div>
<div class="board-body">

<div class="box-vertical">
<div class="box-title">box1 title-
</div>
<div class="box-body">
<div class="box-vertical">
<div class="box-title">inner box title
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>
</div>



</div>






<div class="box-vertical">
<div class="box-title">box at side title-
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>





<div class="box-horizontal">
<div class="box-title">box at bottom - title
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>
















</div>

</div>

最佳答案

http://jsfiddle.net/7brCZ/7/ http://jsfiddle.net/7brCZ/7/embedded/result/

enter image description here

.board{
display:block;
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;

border: red solid thin;
/**min-height:510px;**/

}


.board-title{
background-color:black;
color:white;
font-size:50px;
}

.board-body{

}

.box{

vertical-align:top;
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;
border: blue solid thin;
/**min-height:500px;**/
min-width:160px;
height:100%;



}

.box-title{

width:100%;
background-color:grey;
font-size:50px;
}

.box-body{
display:table;
}

.box-parent{


}

.box-vertical{
display:table-cell;
vertical-align:top:


vertical-align:top;
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;
border: blue solid thin;
/**min-height:500px;**/
min-width:160px;
height:100%;
}

.box-horizontal{


vertical-align:top;
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;
border: blue solid thin;
/**min-height:500px;**/
min-width:160px;
height:100%;
}



.task{
margin-right:5px;
margin-left:5px;
margin-top:10px;
margin-bottom:10px;
display:block;
float: left;
border: green solid thin;
width:150px;
height:100px;
}






<div class="board">
<div class="board-title">board
</div>
<div class="board-body">






<div class="box-vertical">
<div class="box-title">box at virtical
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>



<div class="box-vertical">
<div class="box-title">box at virtical
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>









<div class="box-vertical">
<div class="box-title">box virtical
</div>
<div class="box-body">
<div class="box-vertical">
<div class="box-title">inner virtical box
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>
<div class="box-vertical">
<div class="box-title">inner virtical box
</div>
<div class="box-body">





<div class="box-vertical">
<div class="box-title">inner virtical box
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>
<div class="box-vertical">
<div class="box-title">inner virtical box
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>






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



</div>






<div class="box-vertical">
<div class="box-title">box at side
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>





<div class="box-horizontal">
<div class="box-title">box at horizontal
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>



<div class="box-horizontal">
<div class="box-title">box at horizontal
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>


<div class="box-horizontal">
<div class="box-title">box at horizontal
</div>
<div class="box-body">



<div class="box-vertical">
<div class="box-title">inner virtical box
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>
<div class="box-vertical">
<div class="box-title">inner virtical box
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>

<div class="box-vertical">
<div class="box-title">inner virtical box
</div>
<div class="box-body">
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
<div class="task">
</div>
</div>
</div>





</div>
</div>





</div>

</div>

关于css - div 的垂直和水平对齐 - 第 2 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17902138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com