I can't seem to center align 2 in-line tables in html.
my snippet of code:
<div class="sometables" style="margin-left: auto; margin-right: auto;">
<table style="display:inline-table;float:left;width:30%;margin-right:230px;">
<tr>
<th>Application<br>Processed</th>
<th>Application<br>ID</th>
<th>Last Name</th>
<th>First Name</th>
</tr>
{% for processed in processed_data %}
<tr>
<td>{{processed[0]}}</td>
<td>{{processed[3]}}</td>
<td>{{processed[1]}}</td>
<td>{{processed[2]}}</td>
</tr>
{% endfor %}
</table>
<table style="display:inline-table;float:left;width:30%;">
<tr>
<th>Application<br>Flagged</th>
<th>Application<br>ID</th>
<th>Last Name</th>
<th>First Name</th>
</tr>
{% for flagged in flagged_data %}
<tr>
<td>{{flagged[0]}}</td>
<td>{{flagged[3]}}</td>
<td>{{flagged[1]}}</td>
<td>{{flagged[2]}}</td>
</tr>
{% endfor %}
</table>
</div>
Current output is:
How can I center align the two tables together?
Research and Due Diligence:
W3: CSS Layout
HubSpot: 11 Ways to Center Div or Text in Div in CSS
SO: How to align a to the middle (horizontally/width) of the page
As per OP request for code, not checked as it cannot be executed runtime.
Remove references to inline margin and create a basic CSS Grid parent .sometables, which gets stretched to fill its parent (assumably body) and add some convenient spacing between the two child elements (table) with column-gap (where any preferred value will do).
Notice the removal of margin definitions...
Update the CSS grid needs a grid-template-columns definition to show the tables side-by-side instead of stacked on top of eachother. Each table gets 1fr (one fraction) of the total space available.
Make sure to visit Grid by Example, well worth your time.
.sometables {
/* CSS Grid settings */
display: grid; place-items: center;
grid-template-columns: 1fr 1fr;
column-gap: 2em;
width: 100%; /* to fill full width of parent */
}
<div class="sometables">
<table style="display:inline-table;float:left;width:30%;">
<tr>
<th>Application<br>Processed</th>
<th>Application<br>ID</th>
<th>Last Name</th>
<th>First Name</th>
</tr>
{% for processed in processed_data %}
<tr>
<td>{{processed[0]}}</td>
<td>{{processed[3]}}</td>
<td>{{processed[1]}}</td>
<td>{{processed[2]}}</td>
</tr>
{% endfor %}
</table>
<table style="display:inline-table;float:left;width:30%;">
<tr>
<th>Application<br>Flagged</th>
<th>Application<br>ID</th>
<th>Last Name</th>
<th>First Name</th>
</tr>
{% for flagged in flagged_data %}
<tr>
<td>{{flagged[0]}}</td>
<td>{{flagged[3]}}</td>
<td>{{flagged[1]}}</td>
<td>{{flagged[2]}}</td>
</tr>
{% endfor %}
</table>
</div>
Related
When I am using
.right-align {
text-align: right !important;
transform: translateX(-40%);
}
The Table structure is showing below
<table>
<thead>
<tr>
<th>Bid
</th>
<th>Offer
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="right-align">
200
</div>
</td>
<td>
<div class="right-align">
221
</div>
</td>
</tr>
</tbody>
</table>
The td is overlapping the th element as seen below
How can I can make it go under the header ?
This is happening when table is scrolling
It is very hard to answer the question as it is, however, the table should keep its proportions and structure as long as you keep the code tight:
.right-align {
text-align: right !important;
}
<table>
<thead>
<tr>
<th>Bid</th>
<th>Offer</th>
</tr>
</thead>
<tbody>
<tr>
<td class="right-align">200</td>
<td class="right-align">221</td>
</tr>
</tbody>
</table>
It is nebulous why you decided to use the transform: translateX(-40%); rule in there, but it seems you may be trying to overwrite some rules that come from a theme hence the problem you are facing; If you update your question and add more pieces of code or at least what you are trying to achieve then i could be more helpful :). Also if you are using a framework or theme specify which one.
EDIT.
I saw your updates, you don't need to add a div within the td element to apply a class, you can do it directly in the td element. However, it seems that some css rules are overlapping. Maybe a screenshot of the results in a browser could be helpful.
When I use Handlebar to go through a large list with #each, it automatically makes a new page if it doesn't fit for all the entries on one page. On the new page it has no space to the margin and looks unattractive. How can I set the distance from the margin?
This is my code:
<table>
<thead>
<tr>
<th></th>
<th>{{Person.Known}}</th>
<th>{{Person.Unknown}}</th>
</tr>
</thead>
<tbody>
{{#each OriginalDocuments.Documents }}
<tr>
<td>{{this.Name}} - {{#index}}</td>
<td>
{{#if this.Known}}
<div>
<img src="person_checkmark_Known.svg"/>
</div>
{{/if}}
</td>
<td>
{{#if this.Unknown}}
<div>
<img src="person_checkmark_Unknown.svg"/>
</div>
{{/if}}
</td>
</tr>
{{/each}}
</tbody>
You can simply add this to the style section of your handlebars template:
#page {
margin: 10px 0;
}
The above will add 10px of margin to the top and bottom of each page that ends up being generated. You can style as you see fit by using #page, and that will be applied to each page.
I want to add a class to a parent DIV that affects lots of inner elemnets. But when I do this with Bootstrap, the styling gets messed up.
This code shows the problem on 2 where you can see the bottom border is missaligned. If I just do a .toggle(".second") on the element instead, it will work.
https://www.bootply.com/KOJ4VKNbOa
.second {
display: none;
}
.show-inner .second {
display: block;
}
<div id="outer">
<table class="table">
<thead>
<tr>
<th class="first">A</th>
<th class="second">B</th>
<th class="third">C</th>
</tr>
</thead>
<tbody>
<tr>
<td width="98%" class="first">1</td>
<td width="1%" class="second">2</td>
<td width="1%" class="third">3</td>
</tr>
</tbody>
</table>
</div>
<button onclick="$('#outer').toggleClass('show-inner');">Toggle .second</button>
In my project I would like to have many dependencies of that outer DIV class, so getting it to work would save me lots of code.
use display: table-cell instead of block.
.show-inner .second {
display: table-cell;
}
I have tried the code below for page break after particular row of the table while printing. It didn't break the page. All rows appeared on the same page while printing.
.page-break {
page-break-after: always;
}
<tr class="page-break">
<td>--</td>
</tr>
Not sure you can use it on an <tr> (not a block level element)
"Applies to block-level elements in the normal flow of the root element. User agents may also apply it to other elements like table-row elements."
https://developer.mozilla.org/en-US/docs/Web/CSS/page-break-after
You're missing the #media print. That media query is specific for when you're setting something to print.
https://www.w3schools.com/cssref/pr_print_pageba.asp
ANSWER UPDATE:
After some searching, #anderssonola is correct about not being able to use it with <tr>. So, you will have a couple options depending on how you've set up your page. The ones off the top of my head are below:
Option 1 = use <div> to break them apart.
For that you could do something like:
#media print {
div.page-break {page-break-after: always;}
}
<table>
<tr>
<td>Page One</td>
</tr>
</table>
<table>
<div class="page-break">
<tr>
<td>Page Two</td>
</tr>
</div>
</table>
Option 2 = use <table> to break them apart.
#media print {
.page-break {page-break-after: always;}
}
<table class="page-break">
<tr>
<td>Page One</td>
</tr>
</table>
<table class="page-break">
<tr>
<td>Page Two</td>
</tr>
</table>
Option 3 = use an HTML5 element to break them apart.
#media print {
section {page-break-after: always;}
}
<section>
Page One
</section>
<section>
Page Two
</section>
I have the following code to display comparison of items
<table>
<tr> <!-- Iterating over list of Headers -->
<td>
<div class="Header"><h4>Header Value</h4></div>
<div class="HeaderList"><span>Key</span> <!-- Iterating over list of keys-->
</td>
<td> <!-- Iterating over multiple items -->
<div class="Header"></div>
<div class="HeaderList"><span>Value</span> <!-- Displaying Value next to the key by iterating over them-->
</td>
</tr>
</table>
I want to align the divs with class "Header" and "HeaderValueList" across multiple td.
The value in Header can extend to multiple lines if needed.
I want to set a maximum height for "HeaderKeyList" and "HeaderValueList" not to cross 32px but if its less than that, the height should be dynamically variable and should align across tds.
I have the following css
.HeaderList
{
width:100%;
height:auto;
max-height:32px;
overflow: hidden;
padding-top: 0.5px;
padding-bottom: 0.5px;
}
.Header
{
width:100%;
}
When any of the value spans across multiple rows, my alignment goes awry. Please help. I am open to making changes in javascript as well.
Thanks in advance.
To group rows in a table together, you use tbody. One tbody for each of the lists. So the HTML becomes
<table>
<thead>
<tr>
<th></th>
<th>Item1</th>
<th>Item2</th>
</tr>
</thead>
<tbody>
<!-- Iterating over list of Headers -->
<tr class="Header">
<th>Header Value1</th><td></td><td></td>
</tr>
<tr>
<td><div class="HeaderKey">Key1</div></td>
<td><div class="HeaderValue">Item1Value1</div></td>
<td><div class="HeaderValue">Item2Value1</div></td>
</tr>
<tr>
<td><div class="HeaderKey">Key2</div></td>
<td><div class="HeaderValue">Item1Value2</div></td>
<td><div class="HeaderValue">Item2Value2</div></td>
</tr>
<tr>
<td><div class="HeaderKey">Key3</div></td>
<td><div class="HeaderValue">Item1Value3</div></td>
<td><div class="HeaderValue">Item2Value3</div></td>
</tr>
</tbody>
<tbody>
<!-- Iterating over list of Headers -->
<tr class="Header">
<th>Header Value2</th><td></td><td></td>
etc, with this result:
See fiddle.
I made one of the values a bit wider, to demonstrate that if you make the window narrower, the div will grow to two lines, and the cells to the left and right will remain lined up (vertically centered; but you can change that) and if you make the window narrower still, the div doesn't grow to more than two lines because of the max-height.