gpt4 book ai didi

Aligning tables or DIV in one ROW using HTML Css(使用HTMLCSS在一行中对齐表格或DIV)

转载 作者:bug小助手 更新时间:2023-10-25 10:40:57 26 4
gpt4 key购买 nike



I have a problem in which I can't align the two table in PREPARED BY: and CHARGE It's not necessary to make two tables I tried just div the PREPARED BY: but it doesn't work so I came up to make another table one is belong to the PREPARED BY: with the name below and the other one is the charge table to below until Grand Total , the purpose why I created two tables because I loop the other table if I merge them into one the PREPARED by table will be loop two and I avoid that, I tried aligning them but it doesn't work,

我有一个问题,我不能在Prepared By中对齐两个表:和Charge我试着做两个表只需div Prepared By:但它不起作用所以我来做另一个表一个属于Prepared By:下面有名字,另一个是Charge表到下面直到总计,我之所以创建两个表是因为我循环另一个表如果我将它们合并成一个Prepared By表将是循环二,我避免了,我试着对齐它们,但它不起作用,


The result must be like this image

结果必须如下图所示


enter image description here


What I've tried

我尝试过的东西




       
.container-wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
height: auto;
padding-bottom: 50px;
background-color: #cccccc;
}

.container {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 5%;
background-color: #f0f0f0;
border-radius: 8px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
margin-bottom: 20px;
padding: 0 10px;
}

.print-button {
background-color: #b2c2ce;
color: white;
border: none;
border-radius: 4px;
padding: 8px 12px;
cursor: pointer;
margin-right: 500px;
}

.container-body, .container-body2,.container-body3,.container-body4 {
width: 210mm;
height:auto;
background-color: #ffffff;
box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
padding: 20px;
position: relative;
padding: 50px;
}
.appendix {
position: absolute;
top: 65px;
right: 50px;
font-size: 14px;
font-style: italic;
}

table {
border: 3px solid;
border-collapse: collapse;
width: 100%;
margin-top: 40px;
}

th,
td {
border: 1px solid #000000;
text-align: left;
padding: 8px;
}

th {
background-color: #f2f2f2;
}

.center-text {
text-align: center;
vertical-align: top;
}
.dvnumber {
background-color:#c6e0b4;
border:1.8px solid;
font-size: 12px;
}
.align-u-left {
text-align: left;
vertical-align: top;
}

@media print {
.container {
display: none;
}

.container-body, .container-body2,.container-body3,.container-body4{
background-color: #f0f0f0;
box-shadow: none;
width: 210mm;
height: 297mm;
margin-top: -30px;
}

.container h3 {
color: transparent;
}

.container-wrapper {
align-items: flex-start;
}

table {
margin-top: 15px;
border: 3px solid;
}

.appendix {
top: 45px;
}

/* Adjust font size for Disbursement Voucher in print */
.center-text b {
font-size: 14px;
}
.dvnumber {
background-color: #c6e0b4 !important; /* Use !important to ensure it's applied */
color: black; /* Make sure text remains readable */
border: 1.8px solid;
font-size: 10px;
}

.container-body2,.container-body3,.container-body4 {
page-break-before: always;
}
}
.innerTable{
margin:0px;
border-color:white;
}
.lastRow{
padding:0px;
}

.align-text-right{
text-align: right;
}
.align-text-right{
text-align: right;
}
.no-border{
border: 0;
}

.footer {
margin-top: 95%;

}

   <div class="container-wrapper">
<div class="container">
<h3></h3>
<button class="print-button" onclick="window.print()">Print</button>
</div>

<div class="container-body3">
<span ><center>Test data test data tes est data test data tes TEST<br> Test / Test / Test<br> Test# Test.0.dv_no <br> for Date 8, 2023</center></span>
<table >
<thead></thead>
<tbody>
<tr >
<td><b>CODE</b></td>
<td><b>Account Number</b></td>
<td><b>ID NUMBER</b></td>
<td><b><center>NAME</center></b></td>
<td><b>AMOUNT</b></td>
<td><b>CHARGE</b></td>
<td><b><center>PURPOSE</center></b></td>

</tr>


<tr>
<td class="align-text-right" style="padding: 2;">214214214</td>
<td class="align-text-right" style="padding: 4;">4214124</td>
<td class="align-text-left" style="padding: 4;">214</td>
<td class="align-text-left" style="padding: 4;">4124</td>
<td style="padding: 4;"><center> testt </center></td>
<td class="align-text-left" style="padding: 4;"> emp.charges </td>
<td class="align-text-left" style="padding: 4;"> emp.purpose </td>
</tr>


<tr >
<td style="padding: 0;"></td>
<td style="padding: 0;"><b>TOTAL</b></td>
<td style="padding: 0;"></td>
<td style="padding: 0;"></td>
<td style="padding: 0;"><center><b> 50000 </b></center></td>
<td style="padding: 0;"></td>
<td style="padding: 0;"><center><b> 1 </b></center></td>
</tr>
</tbody>
</table>



<table style="border: 0;">
<tbody>
<tr >
<td style="width: 50px;border:0;"></td>
<td style="width: 125px;border:0;"></td>
<td style="width: 100px;border:0;"></td>
<td style="width: 140px;border:0;"></td>
<td style="width:80px;border:0;"></td>
<td style="width:72px;border:0;"></td>
<td style="border:0;"></td>

</tr>
<tr>
<td style="font-size: 13px;padding: 0;" colspan="2" class="no-border">PREPARED BY:</td>

</tr>
<tr>
<td class="no-border"></td>

</tr>
<tr>
<td class="no-border"></td>
<td class="no-border"><center><b><u>Lebron James</u></b></center></td>
</tr>
<tr>
<td class="no-border"></td>
<td class="no-border"><center>AO II</center></td>
</tr>


</tbody>
</table>

<table style="border: 0;">
<tbody>
<tr >
<td style="width: 50px;border:0;"></td>
<td style="width: 125px;border:0;"></td>
<td style="width: 100px;border:0;"></td>
<td style="width: 140px;border:0;"></td>
<td style="width:80px;border:0;"></td>
<td style="width:72px;border:0;"></td>
<td style="border:0;"></td>

</tr>
<tr>

<td class="no-border"></td>
<td class="no-border" colspan="2"></td>
<td style="font-size: 13px;background-color:rgb(158, 198, 255); padding: 0;" class="no-border"><b>CHARGE</b></td>
<td style="font-size: 13px;background-color:rgb(158, 198, 255); padding: 0;" colspan="2" class="no-border"><b><center>Sum of AMOUNT</center></b></td>
</tr>


<tr >
<td class="no-border"></td>
<td class="no-border"></td>
<td class="no-border"></td>
<td style="padding: 0;" class="no-border"> 4214</td>
<td style="padding: 0;" class="no-border" colspan="2"><center> 4214214 </center></td>

</tr>

<tr>
<td class="no-border"></td>
<td style="font-size: 13px;padding: 0;" class="no-border"><center><b></b></center></td>
<td class="no-border"></td>
<td style="padding: 0;;background-color:rgb(158, 198, 255);" class="no-border"><b>GRAND Total</b></td>
<td style="padding: 0;background-color:rgb(158, 198, 255);" class="no-border" colspan="2"><center><b> 4214214 </b></center></td>
</tr>
</tbody>
</table>


<div class="footer">
Cash Unit's Copy
</div>
</div>
<br>
</div>




更多回答

Have a look at what you are doing; you are first setting up width for each column by creating dummy tds with specified width, with last td to cover the remaining width (because table width is set to 100% so that it has to fill the width of parent). When you put table { width: 100%} each table will occupy 100% of parent width. So more than one table can't occupy a row (unless you decide to put one above another using properties like position: fixed or float).

看看您在做什么;您首先通过创建具有指定宽度的虚拟TD来设置每一列的宽度,最后一个TD覆盖剩余的宽度(因为表格宽度被设置为100%,所以它必须填充父列的宽度)。当您放置表格{Width:100%}时,每个表格将占用父宽度的100%。因此,多个表不能占据一行(除非您决定使用位置:FIXED或FLOAT之类的属性将一个表置于另一个表之上)。

Please check this also: stackoverflow.com/q/14278167/21598034 . But your code has other problems as well

也请查看:stackoverflow.com/q/14278167/21598034。但是您的代码还存在其他问题

Tables are not supposed to be used for layout purposes. If you want things align use a CSS grid.

表格不应用于布局目的。如果你想让东西对齐,使用一个css网格。

优秀答案推荐

To make two tables appear on same row, I suggest this method: Put those tables on a bigger table. But as I have mentioned in the comments you are using dummy tds for defining the width of a column. So I have removed unnecessary tds present on the first row.

要使两个表出现在同一行上,我建议使用此方法:将这些表放在更大的表上。但是,正如我在评论中提到的,您正在使用虚拟TD来定义列的宽度。因此,我删除了第一行中出现的不必要的TD。




.container-wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
height: auto;
padding-bottom: 50px;
background-color: #cccccc;
}

.container {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 5%;
background-color: #f0f0f0;
border-radius: 8px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
margin-bottom: 20px;
padding: 0 10px;
}

.print-button {
background-color: #b2c2ce;
color: white;
border: none;
border-radius: 4px;
padding: 8px 12px;
cursor: pointer;
margin-right: 500px;
}

.container-body,
.container-body2,
.container-body3,
.container-body4 {
width: 210mm;
height: auto;
background-color: #ffffff;
box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
padding: 20px;
position: relative;
padding: 50px;
}

.appendix {
position: absolute;
top: 65px;
right: 50px;
font-size: 14px;
font-style: italic;
}

table {
border: 3px solid;
border-collapse: collapse;
width: 100%;
margin-top: 40px;
}

th,
td {
border: 1px solid #000000;
text-align: left;
padding: 8px;
}

th {
background-color: #f2f2f2;
}

.center-text {
text-align: center;
vertical-align: top;
}

.dvnumber {
background-color: #c6e0b4;
border: 1.8px solid;
font-size: 12px;
}

.align-u-left {
text-align: left;
vertical-align: top;
}

table.myClass * { /*new*/
border: 0;
}

table table tr { /*new*/
height: 30px;
}

@media print {
.container {
display: none;
}
.container-body,
.container-body2,
.container-body3,
.container-body4 {
background-color: #f0f0f0;
box-shadow: none;
width: 210mm;
height: 297mm;
margin-top: -30px;
}
.container h3 {
color: transparent;
}
.container-wrapper {
align-items: flex-start;
}
table {
margin-top: 15px;
border: 3px solid;
}
.appendix {
top: 45px;
}
/* Adjust font size for Disbursement Voucher in print */
.center-text b {
font-size: 14px;
}
.dvnumber {
background-color: #c6e0b4 !important;
/* Use !important to ensure it's applied */
color: black;
/* Make sure text remains readable */
border: 1.8px solid;
font-size: 10px;
}
.container-body2,
.container-body3,
.container-body4 {
page-break-before: always;
}
}

.innerTable {
margin: 0px;
border-color: white;
}

.lastRow {
padding: 0px;
}

.align-text-right {
text-align: right;
}

.align-text-right {
text-align: right;
}

.no-border {
border: 0;
}

.footer {
margin-top: 95%;
}

<div class="container-wrapper">
<div class="container">
<h3></h3>
<button class="print-button" onclick="window.print()">Print</button>
</div>

<div class="container-body3">
<span><center>Test data test data tes est data test data tes TEST<br> Test / Test / Test<br> Test# Test.0.dv_no <br> for Date 8, 2023</center></span>
<table>
<thead></thead>
<tbody>
<tr>
<td><b>CODE</b></td>
<td><b>Account Number</b></td>
<td><b>ID NUMBER</b></td>
<td><b><center>NAME</center></b></td>
<td><b>AMOUNT</b></td>
<td><b>CHARGE</b></td>
<td><b><center>PURPOSE</center></b></td>

</tr>


<tr>
<td class="align-text-right" style="padding: 2;">214214214</td>
<td class="align-text-right" style="padding: 4;">4214124</td>
<td class="align-text-left" style="padding: 4;">214</td>
<td class="align-text-left" style="padding: 4;">4124</td>
<td style="padding: 4;">
<center> testt </center>
</td>
<td class="align-text-left" style="padding: 4;"> emp.charges </td>
<td class="align-text-left" style="padding: 4;"> emp.purpose </td>
</tr>


<tr>
<td style="padding: 0;"></td>
<td style="padding: 0;"><b>TOTAL</b></td>
<td style="padding: 0;"></td>
<td style="padding: 0;"></td>
<td style="padding: 0;">
<center><b> 50000 </b></center>
</td>
<td style="padding: 0;"></td>
<td style="padding: 0;">
<center><b> 1 </b></center>
</td>
</tr>
</tbody>
</table>


<table style="border: 0;" class="myClass" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<table style="border: 0;">
<tbody>
<tr>
<td style="width: 50px;border:0;"></td>
<td style="width: 125px;border:0;"></td>
<td style="width: 100px;border:0;"></td>
</tr>
<tr>
<td style="font-size: 13px;padding: 0;" colspan="2" class="no-border">PREPARED BY:</td>

</tr>
<tr>
<td class="no-border"></td>
<td class="no-border">
<center><b><u>Lebron James</u></b></center>
</td>
</tr>
<tr>
<td class="no-border"></td>
<td class="no-border">
<center>AO II</center>
</td>
</tr>


</tbody>
</table>
</td>
<td>
<table style="border: 0;">
<tbody>
<tr>
<td style="width: 140px;border:0;"></td>
<td style="width:80px;border:0;"></td>
<td style="width:72px;border:0;"></td>
<td style="border:0;"></td>

</tr>
<tr>
<td style="font-size: 13px;background-color:rgb(158, 198, 255); padding: 0;" class="no-border"><b>CHARGE</b></td>
<td style="font-size: 13px;background-color:rgb(158, 198, 255); padding: 0;" colspan="2" class="no-border"><b><center>Sum of AMOUNT</center></b></td>
</tr>


<tr>
<td style="padding: 0;" class="no-border"> 4214</td>
<td style="padding: 0;" class="no-border" colspan="2">
<center> 4214214 </center>
</td>

</tr>

<tr>
<td style="padding: 0;;background-color:rgb(158, 198, 255);" class="no-border"><b>GRAND Total</b></td>
<td style="padding: 0;background-color:rgb(158, 198, 255);" class="no-border" colspan="2">
<center><b> 4214214 </b></center>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>

<div class="footer">
Cash Unit's Copy
</div>
</div>
<br>
</div>




I have tried to keep your original code as much as possible, but I have removed extra cells which cause extra columns.

我已经尽可能地保留了您的原始代码,但我已经删除了导致额外列的多余单元格。


更多回答

Just a little bit I tried to move a bit upward the AO II or being align to the GRAND Total can you make that? I mean there's no space between Lebron James and AO II?

只是一点点,我试着往上移动了一点,或者是向总分靠拢,你能做到吗?我的意思是勒布朗·詹姆斯和奥二世之间没有空间?

I have edited my answer. For aligning them I had to specify height of the tr on tables inside the bigger table.

我已经编辑了我的答案。为了对齐它们,我必须指定较大桌子内的桌子上的tr高度。

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