I have a DIV with multiple tables that are being filled by a database search and thus will differ in the amount of table that show.
I want the tables to be next to each other and this works for the first few rows but then something is pushing the fourth row of tables down and out of order.
Here is a fiddle: https://jsfiddle.net/tcanfarotta22/yn4s6cpv/
<table id='scholarship' style='float:left;' align='center'>
<th colspan='2'>
<h3>University of Michigan--Dearborn</h3>
<h5>MI, Public</h5>
<h5>Competitive</h5></th>
<tr>
<td style='text-align:center;'>
<h3>$11,524 in-state $23,866 out-of-state</h3>
<br>
<h5>Tuition</h5></td>
<td style='text-align:center;'>
<h3>63.60%</h3>
<br>
<h5>Acceptance Rate</h5></td>
</tr>
<tr>
<td>Scholarship Annual Amount: Full Tuition</td>
<td>Eligibility: In-state</td>
</tr>
<tr>
<td colspan='2' style='text-align:center;'>
<h3>Required Test Scores</h3></td>
</tr>
<tr>
<td>SAT: 970 CR+M</td>
</tr>
<tr>
<td>ACT: 21</td>
</tr>
<tr>
<td>GPA: 3</td>
</tr>
<tr>
<td colspan='2'>Mid 50% SAT Score: SAT Math 498-660 SAT Critical Reading not reported SAT Writing 470-600 </td>
</tr>
<tr>
<td colspan='2'>Mid 50% ACT Score: 22-27 </td>
</tr>
<tr>
<td colspan='2'>Is this Scholarship Available for International Students? .</td>
</tr>
<tr>
<td colspan='2'>US News Ranking: not on the list</td>
</tr>
<tr>
<td colspan='2'>Forbes Ranking: #437 Best Colleges</td>
</tr>
<tr>
<td colspan='2'>Money Ranking: </td>
</tr>
<tr>
<td colspan='2' style='text-align:center;'><a href='http://umdearborn.edu/fa_morefreshmanscholarships' target='_blank'>Click Here to Visit Site</a></td>
</tr>
<tr>
<td colspan='2'>
<input type='checkbox' value='ARLUJ' name='cell[]'>Check the Box to Save</td>
</tr>
<tr>
<td colspan='2' style='text-align:center;'>Scholarship Details</td>
</tr>
<tr>
<td colspan='2'>Detroit Compact Scholarship awards renewable full-tuition scholarships to qualified students from the Detroit Compact High Schools. Students are selected to participate in this program by school administrators. Students are required to have a recalculated GPA of 3.0 and a minimum composite ACT of 21 or SAT combined score of 970.</td>
</tr>
</table>
Edit: I would like them displayed as 4 items on each line.
You shouldn't use float if you want them to be always in one row.
Instead you could do this, make the form as table, and the divs inside as table cell.
form {
display: table;
}
form > div {
display: table-cell;
vertical-align: top;
}
https://jsfiddle.net/yn4s6cpv/2/
Or using flexbox, just add the following style:
form {
display: flex;
}
https://jsfiddle.net/yn4s6cpv/3/
Edit: in order to display 4 items each row. You can set clear:left on every 5th item.
form > div:nth-child(4n+1) {
clear: left;
}
https://jsfiddle.net/yn4s6cpv/4/
Related
Table with 3 rows. the first row span 1.5 column each
I am 2 months into learning html and i came across a task where i have no idea of where to start from. I want to implement a html table with 3 rows, the first row however should have two equal parts of columns and the other two to have 3 equal parts. Please help.
Here is a rough code for it:
<table>
<tr>
<td>one</td>
<td>two</td>
</tr>
<tr>
<td>three</td>
<td>four</td>
<td> five</td>
</tr>
<tr>
<td>six</td>
<td>seven</td>
<td> eight</td>
</tr>
</table>
You can use colspan. The colspan attribute defines the number of columns a table cell should span.
table, th, td {
border: 1px solid black;
}
<table>
<tr>
<td colspan='3'>one </td>
<td colspan='3'> two </td>
</tr>
<tr>
<td colspan='2'>three</td>
<td colspan='2'>four</td>
<td colspan='2'> five</td>
</tr>
<tr>
<td colspan='2'>six</td>
<td colspan='2'>seven</td>
<td colspan='2'> eight</td>
</tr>
</table>
I have a table structure like this
And the html structure is this
<table class="table table-bordered">
<thead>
<tr>
<th>Hierarchy</th>
<th>Operations</th>
</tr>
</thead>
<tbody>
<tr>
<td class="history-hierarchy" rowspan="4">
<div><!-- Tree structure is loaded here dynamically --></div>
</td>
</tr>
<tr>
<td class="history-text">
Equipment A700/005 is added.
</td>
</tr>
<tr>
<td class="history-text">
System instance SYSI/0002 is added.
</td>
</tr>
<tr>
<td class="history-text">
Equipment 7100/001 is replaced with 7100/002
</td>
</tr>
</tbody>
</table>
If you see the image, the Operations columns height is adjusting itself based on the Hierarchy columns height, I am looking for some way if possible to have the heights of operation column fixed say 10px and whatever space is left the last row's operation column should consume it.
So the operations column will not looke weird having so much height.
Is it possible?
the approach you are using is correct, you can use rowspan="2" on the last row as shown in my snippet.
table {height: 600px}
table td {border:1px solid red; vertical-align:top}
td.history-text {height: 20px}
<table class="table table-bordered">
<thead>
<tr>
<th>Hierarchy</th>
<th>Operations</th>
</tr>
</thead>
<tbody>
<tr>
<td class="history-hierarchy" rowspan="4">
<div>Tree structure is loaded here dynamically</div>
</td>
<td class="history-text">
Equipment A700/005 is added.
</td>
</tr>
<tr>
<td class="history-text">
System instance SYSI/0002 is added.
</td>
</tr>
<tr>
<td class="history-text" rowspan="2">
Equipment 7100/001 is replaced with 7100/002
</td>
</tr>
</tbody>
</table>
My question is that how can I make a row with different columns quantity ?
For example I want to have 2 columns in last row in this picture (the portion of each cell must be 50%).
Another question that I have is that how can I make text starts from first line in a cell (center cell , in this picture) ?
My code is :
table {
border: 1px solid black;
border-collapse: collapse;
border-spacing: 5px;
}
th,
td {
padding: 10px;
}
<table style="width:100%" border="1px" cellpadding="5" cellspacing="5" bordercolor="green" bgcolor="yellow" height="500px">
<caption>web design homework</caption>
<tr>
<th colspan="3">My Website</th>
</tr>
<tr bgcolor="#77E022" height="20px" align="left">
<td colspan="3">
home products contact us
</td>
</tr>
<tr>
<td width="25%">last post</td>
<td rowspan="2" width="50%">hello my name is mohammad ghorbani and i am studying computer enginerring in arak</td>
<td>our friends</td>
</tr>
<tr>
<td>our statics</td>
<td>24</td>
</tr>
<tr>
<td>our social pages</td>
<td>about us</td>
</tr>
</table>
There's two primary answer categories to your question.
First, the direct answer. Think of your page as a grid. You want enough squares on the grid to be divisible by both 3 and 2. Say, 6. Then use colspan to set each column to the number of grid columns that would be needed -- so, colspan=2 for 3 columns, and colspan=3 for 2 columns.
<table border=1>
<tr>
<td colspan=6>My Website</td>
</tr>
<tr>
<td colspan=6>home, products, contact us</td>
</tr>
<tr>
<td colspan=2 style="width:33%">last post</td>
<td colspan=2 rowspan=2 style="width:33%">hello my name</td>
<td colspan=2 style="width:33%">our friends</td>
</tr>
<tr>
<td colspan=2 style="width:33%">our statics</td>
<td colspan=2 style="width:33%">24</td>
</tr>
<tr>
<td colspan=3 style="width:50%">our social pages</td>
<td colspan=3 style="width:50%">about us</td>
</tr>
</table>
The other answer category is that you should avoid using tables for your layout structure. There's a LOT of Google results for this one, and it's very opinion based, so I'll just say that generally tables should be used for data, css for layouts, and using tables for layouts may be quicker but it's less flexible.
Try this, its working well, hope it will resolve your issue.
Add this class
.column{display:inline-block; width:49%;}
<table style="width:100%" border="1px" cellpadding="5" cellspacing="5" bordercolor="green" bgcolor="yellow" height="500px">
<caption>web design homework</caption>
<tr>
<th colspan="3">My Website</th>
</tr>
<tr bgcolor="#77E022"
height="20px" align="left" >
<td colspan="3" >
home products contact us
</td>
</tr>
<tr>
<td width="25%"> last post </td>
<td valign="top" rowspan="2" width="50%"> hello my name is mohammad ghorbani and i am studying computer enginerring in arak </td>
<td> our friends </td>
</tr>
<tr>
<td> our statics </td>
<td> 24 </td>
</tr>
<tr>
<td colspan="3" valign="top">
<div class="column"> our social pages</div>
<div class="column"> about us </div>
</td>
</tr>
</table>
I've been designing webpages for some time now, and for one of my webpages, I need to design a table with 6 columns and 3 rows. The first column need to have 3 rows, while the other 5 columns only need 2 rows. I can make it using this CODE:
<tr><td class="style3">7:00 AM
</td>
<td class="style3" rowspan="2">
</td>
<td class="style3" rowspan="2">
</td>
<td class="style3" rowspan="2">
</td>
<td class="style3" rowspan="2">
</td>
</tr>
<tr><td class="style3">7:30 AM
</td>
</tr>
<tr><td class="style3">7:59 AM
</td>
<td class="style3">
</td>
<td class="style3">
</td>
<td class="style3">
</td>
<td class="style3">
</td>
</tr>
How can I make it so that the bottom border of the first row of the 5 columns are exactly in the middle of the second row of the first column?
It means that the line of the bottom border of the first row of the 5 columns is in the middle of the value "7:30 AM" from the first column, second row. I know it is quite confusing but I cannot show you an image of how I want it to look like because I just join here and I don't have 10 reputations to post an image. Please understand my logic.
rowspan=2 means, the column will span two rows, hence if you are applying this to the first column of the first row, the the next row should have one less column. For every column you do a rowspan="n" on, you need to omit that column from the next "n-1" number of rows.
The following snippet will make it clear to you:
table, td {
border: 1px solid gray;
border-collapse: collapse;
}
td { padding: 8px; }
<table>
<tbody>
<tr>
<td class="style3">7:00 AM</td>
<td class="style3" rowspan="2">Event 1</td>
<td class="style3" rowspan="2">Event 2</td>
<td class="style3" rowspan="2">Event 3</td>
<td class="style3" rowspan="2">Event 4</td>
</tr>
<tr>
<td class="style3" rowspan="2"></td>
</tr>
<tr>
<td class="style3" rowspan="2">Event 5</td>
<td class="style3" rowspan="2">Event 6</td>
<td class="style3" rowspan="2">Event 7</td>
<td class="style3" rowspan="2">Event 8</td>
</tr>
<tr>
<td class="style3">7:59 AM</td>
</tr>
</tbody>
</table>
Here's my current code:
<tbody>
<tr><th colspan="7">TEST TITLE</th></tr>
<tr><td colspan="1">10-19-2014 - Test</td></tr>
<tr><td colspan="1">10-20-2014 - Test</td></tr>
<tr><td colspan="1">10-21-2014 - Test</td></tr>
<tr><td colspan="1">10-22-2014 - Test</td></tr>
<tr><td colspan="1">10-23-2014 - Test</td></tr>
<tr><td colspan="1">10-24-2014 - Test</td></tr>
<tr><td colspan="1">10-25-2014 - Test</td></tr>
<tr><td colspan="1">10-26-2014 - Test</td></tr>
</tbody>
Here's how the table is showing up:
TITLE
INFORMATION
INFORMATION
INFORMATION
INFORMATION
INFORMATION
INFORMATION
INFORMATION
This is how I want it to show up:
TITLE
INFORMATION | INFORMATION | INFORMATION | INFORMATION | INFORMATION | INFORMATION | INFORMATION
Since I've specified the column span as being 7 for the title, I thought that each of the other tds would show up as left to right instead of showing each on a new line.
What am I doing wrong here?
One posible solution without change at all your html:
table tbody tr:not(:first-child) {
float: left;
}
table tbody tr:first-child {
text-align: left;
}
table tbody tr:not(:first-child):not(:last-child) td:after {
content: "|";
padding-left: 10px;
}
<table>
<tbody>
<tr>
<th colspan="7">TEST TITLE</th>
</tr>
<tr>
<td colspan="1">10-19-2014 - Test</td>
</tr>
<tr>
<td colspan="1">10-20-2014 - Test</td>
</tr>
<tr>
<td colspan="1">10-21-2014 - Test</td>
</tr>
<tr>
<td colspan="1">10-22-2014 - Test</td>
</tr>
<tr>
<td colspan="1">10-23-2014 - Test</td>
</tr>
<tr>
<td colspan="1">10-24-2014 - Test</td>
</tr>
<tr>
<td colspan="1">10-25-2014 - Test</td>
</tr>
<tr>
<td colspan="1">10-26-2014 - Test</td>
</tr>
</tbody>
</table>
I use a combination of pseudo-elements and pseudo-class to achieve this.
This is how I do it. You create many table dividers within a single row. For the title, I give it it's own row, but make the colspan the same length as the maximum number of rows in the table. Just because you specify 7 for the colspan in the title does not mean that the <td> is automatically generated for you.
<table>
<tr>
<td colspan="7">
Title
</td>
</tr>
<tr>
<td>
Information
</td>
<td>
Information
</td>
<td>
Information
</td>
<td>
Information
</td>
<td>
Information
</td>
<td>
Information
</td>
<td>
Information
</td>
</tr>
</table>
if you don't know the total amount of columns and it needs to be dynamic, you could use a repeater inside the table to generate multiple instances of <td>
<table>
<tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<td>
Information
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</table>
<table>
<tr>
<th colspan="7">TITLE</th>
</tr>
<tr>
<td colspan="1">
INFORMATION
</td>
<td colspan="1">
INFORMATION
</td>
<td colspan="1">
INFORMATION
</td>
<td colspan="1">
INFORMATION
</td>
<td colspan="1">
INFORMATION
</td>
<td colspan="1">
INFORMATION
</td>
<td colspan="1">
INFORMATION
</td>
</tr>
</table>
To create multiple columns, you need to have rows (tr elements) with multiple cells (th or td elements). You now have just rows with one cell in each. Just specifying colspan="7" for the cell of the first row says that the table has 7 columns, but in fact it does not: all other rows have just one cell in one column, and your markup is even formally invalid (violates the HTML table model).
To fix this, just put the other cells on one row:
td + td { border-left: solid; }
<table>
<tbody>
<tr><td colspan="7">TEST TITLE</td></tr>
<tr>
<td>10-19-2014 - Test</td>
<td>10-19-2014 - Test</td>
<td>10-19-2014 - Test</td>
<td>10-19-2014 - Test</td>
<td>10-19-2014 - Test</td>
<td>10-19-2014 - Test</td>
<td>10-19-2014 - Test</td>
</tr>
</tbody>
</table>
Notes: The colspan="1" attribute is redundant; it just states the default. The cell that spans 7 columns is best defined as a td element, not th, since th elements specify headers for all columns or rows (columns in this case) in a table; some text that is just a heading for some part of a table should thus be just a data cell, td. The “how I want it to show up” part in the question suggests that there should be borders between the cells, but not elsewhere; I have added a simple CSS rule to show how this could be achieved (by setting left border on every cell except the first one in a row).