Need to show a text just above particular table headings - html

I have a table to list the vehicles, i need to show one message over the last three table headings only always above the three headings without exceeding the table heading width (total width of three headings).
I have implemented tried:
<div class="col-md-12">
<h2>Vehicle List</h2><br>
<h2>To be Sold</h2>
<div class="table-responsive">
<div class=" col-md-6 alert-warning" id="vechicle_msg_div">Documents pending for these
vehicles</div>
<table class="table table-bg m-t-sm">
<thead>
<tr>
<th width="30">No</th>
<th>Owner Name</th>
<th>Place</th>
<th>Name</th>
<th>Brand</th>
<th>color</th>
</tr>
</thead>
<tbody *ngIf="vehicleList != null">
<td>{{ vehicleList.length +i }}</td>
<td>{{ list.ownername }}</td>
<td>{{ list.place }}</td>
<td>{{ list.name }}</td>
<td>{{ list.brand }}</td>
<td>{{ list.color }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
#vechicle_msg_div {
position: relative;
top: 1px;
padding: 10px;
width:auto;
float: right;
text-align: center;
border: 1px dashed;
}
Now what happens is the width of the text in vechicle_msg_div is not properly aligned and also the width of the text div changes based on the content of any of the td width varies.
I want to display the vechicle_msg_div in same width of last three <th></th> what ever the content's width is..

You can create another table header row and use the the colspan attribute to let its table data cells span multiple columns like this:
<table>
<thead>
<tr>
<td colspan="3"></td>
<td colspan="3">Documents pending for these vehicles</td>
</tr>
<tr>
<th width="30">No</th>
<th>Owner Name</th>
<th>Place</th>
<th>Name</th>
<th>Brand</th>
<th>color</th>
</tr>
</thead>
</table>
Check out the mdn pages around https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td#attr-colspan for more details.

Related

Why is table not respecting my CSS command?

Here is a part of my HTML code.
<link rel="stylesheet" href="{% static "css/mystyle.css" %}"/>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>Here are your patient records:</h1>
<h2>Go to /formpage to fill the form</h2>
{% if patients %}
<table>
<thead>
<th>Patient Name</th>
<th>Identity Document Number</th>
<th>Date of Birth</th>
<th>Date Case Confirmed</th>
<th>Case Number</th>
</thead>
{% for pat in patients %}
<tr>
<td>{{ pat.name }}</td>
<td>{{ pat.idn }}</td>
<td>{{ pat.date_of_birth }}</td>
<td>{{ pat.confirm_day }}</td>
<td>{{ pat.case_no }}</td>
</tr>
{% endfor %}
</table>
I want to edit the table according to my CSS rules.
h1{
color: red;
}
table, td, th{
border: 1px solid black;
}
table {
border-collapse: collapse;
}
However, the table does not respect the changes from CSS. Funny thing is, h1 header is actually following the CSS rule and is red.
What am I missing?
Try to inspect element the table and check if your border: 1px solid black; applies to the element (on inspect element window, on css box, make sure the text isn't in strikethrough), if the text is in strikethrough, try adding !important keyword next to black and before ;.
Your CSS gets applied to the table elements, you can check it with the developer tools in your browser.
Also a running example of your table:
h1 {
color: red;
}
table,
td,
th {
border: 1px solid black;
}
table {
border-collapse: collapse;
}
<h1>Here are your patient records:</h1>
<h2>Go to /formpage to fill the form</h2>
<table>
<thead>
<th>Patient Name</th>
<th>Identity Document Number</th>
<th>Date of Birth</th>
<th>Date Case Confirmed</th>
<th>Case Number</th>
</thead>
<tbody>
<tr>
<td>name</td>
<td>idn</td>
<td>date_of_birth</td>
<td>confirm_day</td>
<td>case_no</td>
</tr>
<tr>
<td>name</td>
<td>idn</td>
<td>date_of_birth</td>
<td>confirm_day</td>
<td>case_no</td>
</tr>
<tr>
<td>name</td>
<td>idn</td>
<td>date_of_birth</td>
<td>confirm_day</td>
<td>case_no</td>
</tr>
</tbody>
</table>

How to prevent my td stacking below each other?

I am trying to make a table responsive when the screen size gets smaller. It is a table-responsive class inside a col-6, but when the screen gets smaller, the td's and th's get stacked below each other..
I want the table to get smaller, or just wider in some way.
I tried some bootstrap responsive classes, but on a table it seems to be quite hard.
<div class="col-6 col-lg-6 col-xl-6">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Dealtype</th>
<th>Start date</th>
<th>End date</th>
<th>Investment</th>
<th>Price per review</th>
<th>Logistics costs</th>
<th>#Reviews</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ $deal->dealtype }}</td>
<td>{{ $deal->startdate }}</td>
<td>{{ $deal->enddate }}</td>
<td>€ {{ number_format(round($deal->amount, 2), 2) }}</td>
<td>€ {{ number_format(round($deal->reviewprice, 2), 2) }}</td>
<td>€ {{ number_format(round($deal->logisticsamount, 2), 2) }}</td>
<td> {{ $deal->quantity }}</td>
</tr>
</tbody>
</table>
</div>
</div>
I expect the table width to resize with the screen, but obviously the col-6 makes the content stack below each other.
here is a picture of the problem

How to change each column's width individually?

In JavaScript, one style width value is set for all columns, and I can't resize them one by one. I need to resize columns one by one, not all at once:
<table class="table table-striped table-bordered dataTable" id="detailed">
<thead>
<tr>
<th>C1</th>
<th>C2</th>
<th>C3</th>
<th>C4</th>
<th>C5</th>
<th>C6</th>
</tr>
</thead>
<tfoot>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tfoot>
<tbody>
{% for col in cols %}
<tr>
<td>{{ col.name1 }}</td>
<td>{{ col.name2 }}</td>
<td>{{ col.name3 }}</td>
<td>{{ col.name4 }}</td>
<td>{{ col.name5 }}</td>
<td>{{ col.name6 }}</td>
</tr>
{% endfor %}
</tbody>
</table>
Use nth-child to change individual column's width. JSFiddle
tr>td:nth-child(1){
width:100px;
}
tr>td:nth-child(4){
width:450px;
}
You will have to assign an id (or class if you want to change some cells but not all.) to the tags. Then of course use normal CSS to change width, height or padding, etc.
PS. On my phone right now, hard to provide any sample code. Feel free to suggest edit.
Add to table
width: 100%
Next you can add something like this to each TH :
<th style="width: 10%; padding: 5px;">C1</th>
Or (best option i think) add to th class and set there a css
<th class="nameClass">C2</th>
Style CSS:
.nameClass {
width: 10%; // could be other value in px, inc etc.
padding: 5px;
}
Better options to make this is from user below :P

Align thead with td in tbody

I have trouble aligning the thead with the td in tbody. I've tried adjusting the thead using display: table-header-group;. I also found out from here: Why isn't padding applied to table elements?, that padding does not work on 'table-header-group'. Thus when I tried providing padding-left to my th via CSS, nothing is happening. I've also tried using more <th></th> before my <th>Quantity</th> <th>Amount</th> <th>Total</th> so that 'more space' is added. However, I am still not able to align the thead with my content in tbody.
Does anyone know how to fix this issue? If possible, please also let me know if I am not doing things right. Any help is much appreciated.
Thank you!
Screenshot and code is provided below:
thead is too left
Here is my code:
<div class="table-responsive col-lg-12 " ng-show="ngCart.getTotalItems() > 0">
<table class="table-responsive table-striped ngCart cart summaryTable " >
<thead >
<tr cellpadding="10">
<th>Item</th>
<th>Quantity</th>
<th>Amount</th>
<th>Total</th>
</tr>
</thead>
<tfoot>
<tr ng-show="ngCart.getTax()">
<td></td>
<td></td>
<td>Tax ({{ ngCart.getTaxRate() }}%):</td>
<td>{{ ngCart.getTax() | currency }}</td>
</tr>
<tr ng-show="ngCart.getShipping()">
<td></td>
<td></td>
<td>Shipping:</td>
<td>{{ ngCart.getShipping() | currency }}</td>
</tr>
<tr>
<td></td>
<td></td>
<td>Total:</td>
<td>{{ ngCart.totalCost() | currency }}</td>
</tr>
</tfoot>
<tbody>
<tr ng-repeat="item in ngCart.getCart().items track by $index">
<td>{{ item.getName() }}</td>
<td>{{ item.getQuantity() | number }}</td>
<td>{{ item.getPrice() | currency}}</td>
<td>{{ item.getTotal() | currency }}</td>
</tr>
</tbody>
</table></div>
what you did was correct. all you need is to center the text alignment of your thead. or just align the tbody left.

how to set position of div according to table height

i make a table in which rows are dynamically inserted and then i make a div below table when table height increase due to more rows the div does not show ho i set the position of a div when increase table height the div automatically below the table?
here is my code:
<div id="table">
<table class="table table-bordered">
<thead>
<tr>
<th>Description</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
{% for invoice in invoices %}
<tr>
<td style="color:black;">{{ invoice.description }}</td>
<td style="text-align:right; color:black;">{{ invoice.quantity }}</td>
<td style="text-align:right; color:black;">{{ invoice.unitPrice }}</td>
<td style="text-align:right; color:black;">{{ invoice.linetotal }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div style="width:243px; height:67px; float:right; margin:0px 215px 0; border:1px solid black;">
<h5> Invoice Total(USD) {{invoiceamount}}</h5>
<h5> Paid to date {{paidamount}}</h5>
<div class="horizontalRule2" runat="server"></div>
<h5> Invoice Total(USD) {{balanceamount}}</h5>
</div>
and here is table css:
#table{
float: right;
height: 110px;
margin: 4px 215px 0;
width: 686px;
}
here is screenshot i want div show below the table:
I think in this case I think you should stick with a table for those 2 cells as well, since somehow they are part of the tabulated data.
That means you could you just add them at
<div id="table">
<table class="table table-bordered">
<thead>
<tr>
<th>Description</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
{% for invoice in invoices %}
<tr>
<td style="color:black;">{{ invoice.description }}</td>
<td style="text-align:right; color:black;">{{ invoice.quantity }}</td>
<td style="text-align:right; color:black;">{{ invoice.unitPrice }}</td>
<td style="text-align:right; color:black;">{{ invoice.linetotal }}</td>
</tr>
{% endfor %}
<td colspan="3" style="text-align:right;"><h5>Invoice Total(USD)</h5></td>
<td style="text-align:right;"><h5>{{invoiceamount}}</h5></td>
<td colspan="3" style="text-align:right;"><h5>Paid to date(USD)</h5></td>
<td style="text-align:right;"><h5>{{balanceamount}}</h5></td>
</tbody>
</table>
</div>
Try clearing the div#table or the totals div that is below:
div#table {
clear:both;
}