Displacement of <td> and <tr> - html

This should be super easy to solve. I have the following code that is not working the way I would like it to. The aim is to have something like this, with the BUTTON on the right of the "1 2 3 4 table":
1 2 BUTTON
3 4
but all I get is almost the same disposition with the button as a 3rd line. What am I missing?
<tr>
<td>
<tr>
<td>1 </td>
<td>2 </td>
</tr>
<tr>
<td>3 </td>
<td>4 </td>
</tr>
</td>
<td>
<div class="but">
<input type="button" class="button" value="BUTTON" />
</div>
</td>
</tr>

If you want to have an inner table, it needs its own set of <table> tags:
<table>
<tr>
<td>
<table>
<tr>
<td>1 </td>
<td>2 </td>
</tr>
<tr>
<td>3 </td>
<td>4 </td>
</tr>
</table>
</td>
<td>
<div class="but">
<input type="button" class="button" value="BUTTON" />
</div>
</td>
</tr>
</table>
Otherwise, your "inner" trs are actually being treated as a second and third row in your outer table, causing the displacement. The td containing the button appears in a new row after the rows with numbers. The result is a table with missing a <tr> start tag and some unexpected <td>/</td> tags. Here's your original markup re-indented and "fixed" (including the outer <table>/</table> tags that for whatever reason are not shown in the question) to show you what I mean:
<table>
<tr>
<td>
<tr>
<td>1 </td>
<td>2 </td>
</tr>
<tr>
<td>3 </td>
<td>4 </td>
</tr>
<tr>
<td>
<div class="but">
<input type="button" class="button" value="BUTTON" />
</div>
</td>
</tr>
</table>
Note that <tr> and <td> have optional end tags, which means the markup above is completely valid even though the first tr and td are missing their end tags, and is the reason why your original markup is being treated the way it is.

You should move your button to the first table row. And your HTML is not valid — you can't put <tr> into <td>, only vice versa. From the specification:
Contexts in which this element can be used:
As a child of a thead element.
As a child of a tbody element.
As a child of a tfoot element.
As a child of a table element, after any caption, colgroup, and thead elements, but only if there are no tbody elements that are children of the table element.
Check out my snippet:
td {
padding: 5px 20px;
}
<table>
<tr>
<td>1 </td>
<td>2 </td>
<td>
<div class="but">
<input type="button" class="button" value="BUTTON" />
</div>
</td>
</tr>
<tr>
<td>3 </td>
<td>4 </td>
<td></td>
</tr>
</table>

You have included eveything inside one <tr> tag. You need 2 separate <tr> tags, i.e, 2 rows and button should be outside the <table> tag.
Then using CSS you need to set the display of both table and button to inline-block and then using position property of CSS, you can position button to the desired position.
As you also want some space between two columns of the table, you can use   to add some space between two columns of your table.
To add some space between table and button, add some padding to the left side of the button.
.but {
display: inline-block;
position: relative;
top: -30px;
padding-left: 40px;
}
table {
display: inline-block;
}
<table>
<tr>
<td>1</td>
<td>  </td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>  </td>
<td>4</td>
</tr>
</table>
<div class="but">
<input type="button" class="button" value="BUTTON" />
</div>

Related

Bootstrap table rows does not fit headerrow (Angular)

I have a problem using Bootstrap tables in Angular:
My <td> tags does not fit the corresponding <th> from my tableheader: I am not sure, if it is caused due my calls to the template presenting the <td>:
Here is my code:
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Students</th>
<th>Links</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let c of tests">
<app-preview-container id={{c.id}} name={{c.name}} description={{c.description}} studentCount={{Count[c.id]}}"></app-preview-container>
</tr>
</tbody>
</table>
And thats the component which gets called (<app-preview-container>):
<td>
{{name}}
</td>
<td>
{{description}}
</td>
<td>
{{count}}
</td>
<td>
some buttons
</td>
Does anyone has a tip how I can fix that? I have tried a lot using Bootstrap width-params like w-xx or col-md-x or col-x or using scope="col"/"row". But none of these fixed it.
Tables often look that way when you change <tr> / <td> display property. HTML tables have their own unique display properties display: table-row; and display: table-cell;.
You either have done that or wrapped your <td>s with additional div.
You can inspect your table in the console, and check if <td>s are direct children of <tr> and then set by hand <tr> and <td> display property to table-row and table-cell.
An example of a broken table:
td {
border: 1px solid gray;
}
*[style] {
outline: 2px dashed red;
}
<table>
<tr>
<td>
Column 1
</td>
<td>
Column 2
</td>
<td>
Column 3
</td>
</tr>
<tr>
<tr style="display: block;">
<td>
Broken
</td>
<td>
Row
</td>
<td>
!
</td>
</tr>
<tr>
<td style="display: inline-block;">
Broken td
</td>
<td>
!
</td>
<td>
!
</td>
</tr>
<tr>
<td>
Correct
</td>
<td>
row
</td>
<td>
!
</td>
</tr>
</table>

Float an icon or div inside a dynamically generated html table that spans a certain number of rows

I'm working with a html table that's generated dynamically and trying to place an icon/image in a column on the left side that spans the length of multiple table rows. In my example, I would like to place a single image in the colored shaded areas. This needs to be done using html & css. I'll be using the same icon in each block:
Here's a sample of the table structure:
<table border="0">
<tbody>
<tr>
<td>
{dynamic title}
</td>
</tr>
<tr>
<td>
{dynamic description}
</td>
</tr>
<tr>
<td>
{dynamic archives}
</td>
</tr>
</tbody>
</table>
Here's my icon div that needs to go in the shaded areas:
<div class="icon"><i class="far fa-newspaper"></i></div>
Obviously, this ain't gonna work:
<table border="0">
<tbody>
<div class="icon"><i class="far fa-newspaper"></i>
<tr>
<td>
{dynamic title}
</td>
</tr>
<tr>
<td>
{dynamic description}
</td>
</tr>
</div>
<tr>
<td>
{dynamic archives}
</td>
</tr>
</tbody>
</table>
td {
width: 100px;
background: green;
}
<table>
<tr>
<td rowspan=2>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
</table>
You could use rowspan from table to span multiple rows.

Prevent an HTML sub-table from getting cascade style

If I have the HTML below I want to find a single CSS class definition that will effect the outermost table but not the sub tables. Without changing the HTML can I get .myClass to do this:
I was playing around with the not selector but couldn't get it to work.
.myClass tr td div :not(table) {
background-color: red;
}
<body>
<div class="myClass">
<table>
<tr>
<td>
<div>My</div>
</td>
</tr>
<tr>
<td>
<div>
<table>
<tr>
<td>Hello</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div>
<table>
<tr>
<td>World</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</body>
No you cannot do this with pure css without changing your html.
You can do it with jQuery or by simply putting the 'My' inside of a span, because text is not accesible by a selector.
But in all fairness your question was partly answered by #Pangloss. To access the outer table, just use >. Your problem lies in the fact that on the 2nd and 3rd rows, you still have the outer table present. Your question should actually be something like "What's the selector for an element that does not have a specific child type", and then you would find that you cannot target a parent of an element on css yet.
The first cell is the first div inside the first tr, we can target this using the following:
tr:first-child div:first-child{
background:red;
}
Full snippet:
tr:first-child div:first-child {
background: red;
}
<body>
<div class="myClass">
<table>
<tr>
<td>
<div>My</div>
</td>
</tr>
<tr>
<td>
<div>
<table>
<tr>
<td>Hello</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<div>
<table>
<tr>
<td>World</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</body>

Chrome table extends when wraps

I have a table that I set a fixed "name" column width of 200px.
When the text in any row wraps around to the next line (making a 2 line cell,) every other column is extended. For a reproducible code snippet, see below:
<!DOCTYPE html>
<html>
<head>
<style>
table
{
border-collapse:collapse;
}
table, td, th
{
border:1px solid black;
}
tr:nth-child(even) {
background-color: #ddddff;
}
</style>
</head>
<body>
<table style="position:fixed;background-color:white;top:0;left:100px;">
<tr>
<td width="200px;">
Park Name
</td>
<td>
Park Viewed
</td>
<td>
Book Now Button
</td>
<td>
Website Button
</td>
<td>
Call Button
</td>
<td>
Email Button
</td>
<td>
Book Now Call Button
</td>
</tr>
</table>
<table style="margin-left:100px;margin-top:20px">
<tr>
<td width="200px;">
Park Name
</td>
<td>
Park Viewed
</td>
<td>
Book Now Button
</td>
<td>
Website Button
</td>
<td>
Call Button
</td>
<td>
Email Button
</td>
<td>
Book Now Call Button
</td>
</tr>
<tr>
<td>
Camp Hatteras RV Resort and Campground
</td>
<td>
1
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</body>
</html>
If you test it, shortening the park name (so that it doesn't wrap) will provide the intended behavior. The problem is that when the table gets extended, the fixed header (which is itself a table) is no longer the same size as the data table.
Edit: moved CSS into the code snippet so that it's not outside-sourced.
Put your header in the thead instead of a diff table
<table>
<thead>
<tr>
<th class="name">col1</th>
<th>col2</th>
</tr>
</thead>
<tbody>
<tr>
<td>data col1</td>
<td>data col2</td>
</tr>
</tbody>
</table>
Then style the class
th.name {width: 200px}
That should take care of the width for both the header and the data

Height of a cell according to height of the table

I have the following code :
<table>
<tr>
<td>
<!-- Black Box -->
</td>
<td>
<!-- Search Box -->
</td>
</tr>
<tr>
<td rowspan='2'>
<table>
<tr><td class='thead'>Statut</td></tr>
<tr><td><!-- THE TD TO RESIZE --></td></tr>
</table>
</td>
<td>
<table>
<tr><td class='thead'>Annonce</td></tr>
<tr><td><!-- Don't Care --></td></tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr><td class='thead'>Message</td></tr>
<tr><td><!-- Don't Care --></td></tr>
</table>
</td>
</tr>
</table>
It renders like this: http://imageshack.us/a/img689/3140/tbi4.png
But I would like the orange cell under "Statut" to fill the whole height of the containing TD. I tried to apply a height property to the table, the TR and the TD, but nothing happens, be it in HTML with height=... or in CSS with style='height: ...
Here's the render I'd like to have: http://imageshack.us/a/img560/3809/dy4w.png
One could argue that tables are not the best choice here, as they should only be used for tabular data, not for layout.
However, if you decide to go with tables, you should not nest them, but work with rowspan to achieve the deisred result. The HTML would look like this:
<table>
<tr>
<td>
<!-- Black Box -->noir</td>
<td>
<!-- Search Box -->cherche</td>
</tr>
<tr>
<td class='titre'>Statut</td>
<td class='titre'>Annonce</td>
</tr>
<tr>
<td rowspan='3'>lorem ipsum statut</td>
<td>lorem ipsum annonce</td>
</tr>
<tr>
<td class='titre'>Message</td>
</tr>
<tr>
<td>lorem ipsum message</td>
</tr>
</table>
This way you do not need to bother with heights in css (which can be a pain).
I set up a small example to demonstrate: http://jsfiddle.net/qJQdj/
Try height:100%; to make it takes the total height.
Employing min-height will do the trick for you here if you are content aware of the table.
CSS
td[rowspan="2"] > table{
min-height:80px;
}
http://jsfiddle.net/LWxK4/
changed code : convert your code to:
<table>
<tr >
<td class='thead' rowspan='2'>Statut</td>
<td class='thead'>Message</td>
</tr>
<tr><td class='thead'>Message</td></tr>
</table>
it will give you what u want for sure
EDIT: this is the concept of using rowspan.now you should use it to build your own webpage.there are few more cells as well in your code.you can do that using nested tables.my answer shows how to use rowspan properly
If you really wanted nested tables...
You can force a nested table/table-cell to have a minimum height as follows:
Add a class .statut-panel to your inner table:
<table class="wrap">
<tr>
<td>Black Box</td>
<td>Search Box</td>
</tr>
<tr>
<td rowspan='2'>
<table class="statut-panel">
<tr>
<td class='thead'>Statut</td>
</tr>
<tr class="full-size">
<td>THE TD TO RESIZE...</td>
</tr>
</table>
</td>
<td>
<table class="annonce-panel">
<tr>
<td class='thead'>Annonce</td>
</tr>
<tr>
<td>Don't Care</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td class='thead'>Message</td>
</tr>
<tr>
<td>Don't Care</td>
</tr>
</table>
</td>
</tr>
</table>
and apply the following CSS:
table td {
background-color: lightgray;
vertical-align: top;
}
table.statut-panel {
border: 1px solid blue;
height: 200px;
}
table.statut-panel .full-size td {
border: 1px dotted blue;
height: 100%;
}
Give the inner table .status-panel a fixed height, say 200px. CSS will treat this as a minimum height so you won't get into any overflow issues as the table content expands.
For the table cell that you want to expand, table.statut-panel .full-size td, simply set the height to 100%, and it will expand in height to at least 200px (or whatever is a good minimum height).
See demo at: http://jsfiddle.net/audetwebdesign/7L3Bc/