Align a table above an div - html

I have an div container where an image is displayed, above that image I would like to show an table. So, my problem is that the table isn't displayed over the image. Instead it is shown after the image? Can somebody tell me how I can align the table above the image?
<div id="foto2">
<img src="foto2.jpg" class="bg"> <span class="oben">
<table>
<tr>
<td onclick="playAudio('test.mp3')">Hamdullah</td>
<td onclick="playAudio('test2.mp3')">Was?</td>
</tr>
<tr>
<td onclick="playAudio('test.mp3')">Penner</td>
<td onclick="playAudio('test2.mp3')">Heidefick</td>
</tr>
</table>
</span>
</div>
And my css:
html, body {
margin: 0;
width: 100%;
height: 100%;
background-color:#00061c;
}
img.bg {
width: 100%;
}
.oben {
left: 0;
width: 100%;
}
#font-face {
font-family: "Hallo";
src: url(hallo.ttf);
}
table {
width:100%;
color:#FFF;
}
tr {
text-align:center;
}
td {
font-family: Hallo;
font-size: xx-large;
}

In order to see your table "above" ( I suppose you mean in the z axis.) so the image is displayed as a background of the table you can use 2 alternatives solutions
1) a background for your foto2 div.
2) an absolute positioned table
Alternative 1 : Background for your foto2 div.
I dont think you need that oben rule with a left property for a not positioned element (which actually wont work either). The span tag as well I will keep it out of the game unless you have a very particular reason for it...mmmm
This is the fiddle
This is the css for foto2 div. You may adjust the repeat and other properties at your will
#foto2 {
background:url( your image url here );
}
this is the html
<div id="foto2">
<table>
<tr>
<td onclick="playAudio('test.mp3')">Hamdullah</td>
<td onclick="playAudio('test2.mp3')">Was?</td>
</tr>
<tr>
<td onclick="playAudio('test.mp3')">Penner</td>
<td onclick="playAudio('test2.mp3')">Heidefick</td>
</tr>
</table>
</div>
Alternative 2: Absolute positioned table
With this alternative you may use a full width image and not to be constrained by the table size. its your call which alternative to use
Your foto2 div should be relative positioned.Then....
table {
position:absolute;
top:0px;
width:100%;
color:#FFF;
}
And here the fiddle for the absolute table

Have you tried putting the image after the table, like?
</table>
<img src="foto2.jpg" class="bg" />
Or put it in the lowest row of the table like:
<tr>
<td onclick="playAudio('test.mp3')">Penner</td>
<td onclick="playAudio('test2.mp3')">Heidefick</td>
</tr>
<tr>
<td><img src="foto2.jpg" class="bg"></td>
</tr>
</table>
By the way why are you using <span> and put the <table> inside it?

Try inserting it after the closing span tag
<div id="foto2">
<span class="oben">
<table>
<tr>
<td onclick="playAudio('test.mp3')">Hamdullah</td>
<td onclick="playAudio('test2.mp3')">Was?</td>
</tr>
<tr>
<td onclick="playAudio('test.mp3')">Penner</td>
<td onclick="playAudio('test2.mp3')">Heidefick</td>
</tr>
</table>
</span>
<img src="foto2.jpg" class="bg" />
</div>

Related

Adding a character on ANY position of a cell without changing the TD centering text already displayed

I have
<table>
<tr>
<td style='text-align:center'>
CENTERED
</td>
</tr>
</table>
I would like to ADD a single character either on the left or on the right of CENTERED, without affecting the x-position of the CENTERED string.
To be clear: NOT on the left of the cell, but on the left of the CENTERED string. And the CENTERED string can be anything, so I do not want to calculate something pixel-perfect and move it by some constant pixel value.
I tried fiddling with position:absolute/relative and padding-left/left but I couldn't find a working solution.
Ideally if it could be build with classes:
<table>
<tr>
<td style='text-align:center'>
<span class='centeredRegardless'>CENTERED</span>
<span class='onTheLeftWithoutAffectingThePreviousOne'>*</span>
</td>
</tr>
</table>
Then I will need those classes defined :)
Thank you
If you want some cells to have the extra character and some not you could put the extra character as content in a pseudo element positioned absolutely so it doesn't change the positioning of the actual text at all.
For a left character position is right: 100% and for a character on the right the positioning is left: 100%.
td {
position: relative;
}
td.extraChar::before {
content: '*';
position: absolute;
right: 100%;
}
<table>
<tr>
<td style='text-align:center' class="extraChar">
<span class='centeredRegardless'>CENTERED</span>
</td>
</tr>
<tr>
<td style='text-align:center'>
<span class='centeredRegardless'>CENTERED</span>
</td>
</tr>
</table>
Something like this? (remove and collapse the border when happy)
td { border: 1px solid black; min-width:20px; }
.left { text-align:left;}
.right { text-align:right;}
.center { text-align:center;}
<table>
<tr>
<td class="right">></td>
<td class="center">
CENTERED
</td>
<td class="left"><</td>
</tr>
</table>

Can overlapping colspan on table cells shrink-to-fit?

I can’t figure this one out for the life of me. Take a table that has 2 rows, each with 2 cells. The top-right and bottom-left cells are set to colspan="2" (so the table really has 3 columns). If the non-colspan cells have a 100×100 image inside, and the colspan cells have a 200×100 image, you’d expect the table width to be something like 300, right? Nope nope nope! It’s more like 400.
See this pen: http://codepen.io/sandwich/pen/apYPdL
It seems like the colspan’d cells are greedy for width, which goes contrary to typical table sizing of shrinking the cells to fit the content.
Can anyone shine a light on this behavior? In the pen, the desired result is for the first two rows to size themselves like they do when the third row is added, but without the third row having to be added.
If the non-colspan cells have a 100×100 image inside, and the colspan cells have a 200×100 image, you’d expect the table width to be something like 300, right?
Well probably if the <table> had border-collapse:collapse but as it is separate and 20px left and right borders , that's 80px extra for 2 columns. that's 380px at minimum.
Try table-layout:fixed the default is auto. Using fixed will allow you more control of a table's behavior.
CODEPEN
SNIPPET
// Toggle visibility of 3rd row, which has no spanned cells.
$(".toggle_3rd_row").click(function() {
$(".row_3").fadeToggle();
});
// Toggle applying CSS widths to <td>s
$(".toggle_widths").click(function() {
$("table").toggleClass("defined_sizes");
})
body {
padding: 20px;
}
img {
display: block;
}
table {
width: 400px;
margin: 20px 0;
table-layout: fixed;
}
table.defined_sizes .cell_1-1 {
width: 100px;
}
table.defined_sizes .cell_1-2 {
width: 220px;
}
table.defined_sizes .cell_2-1 {
width: 220px;
}
table.defined_sizes .cell_2-2 {
width: 100px;
}
table .row_3 {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="toggle_3rd_row">Toggle third row</button>
<button class="toggle_widths">Toggle cell widths in CSS</button>
<table border="1" cellpadding="0" cellspacing="20">
<caption>Why do the cells only size properly with the colspan-less third row present??</caption>
<tr>
<td class="cell_1-1">
<img src="http://placehold.it/100x100?text=100w">
</td>
<td colspan="2" class="cell_1-2">
<img src="http://placehold.it/222x100?text=222w">
</td>
</tr>
<tr>
<td colspan="2" class="cell_2-1">
<img src="http://placehold.it/222x100?text=222w">
</td>
<td class="cell_2-2">
<img src="http://placehold.it/100x100?text=100w">
</td>
</tr>
<tr class="row_3">
<td>
<img src="http://placehold.it/100x100?text=100w">
</td>
<td>
<img src="http://placehold.it/100x100?text=100w">
</td>
<td>
<img src="http://placehold.it/100x100?text=100w">
</td>
</tr>
</table>

How to put 3 of these tables into the correct spot with CSS

I have 3 tables that I use. I want :
one on the page left
one on the page in the center and
one on the right
All on the same height
The tables can expand and when I use float the expanding goes over the content under it due to the float and I dont want that.
Table code is:
<table id="budget">
<tr>
<th>Project name</th>
<th>Deadline</th>
<th></th>
</tr>
<tr>
<td>Project 1</td>
<td>24/1/2014</td>
<td><div class="arrow"></div></td>
</tr>
<tr><ul>
<td colspan="5">
<li> Your total hours: 3:00</li>
<li>Budget left: €100</li>
</ul>
</td>
</tr>
</table>
OR is there maybe a better way to place these tables? I am open for new suggestions.
A 3 column layout
HTML
<div id="container">
<div class='left third'>
<table>
</table>
</div>
<div class='centre third'>
<table>
</table>
</div>
<div class='right third'>
<table>
</table>
</div>
</div>
CSS
div.third{
width:33%;
}
div.left{
float:left;
}
div.right{
float:right;
}
div.centre{
float:right;
}
/* This will centre the middle table */
div.centre table{
width:#####px
margin: 0 auto;
}
Notes:
1) Width is 33%, not 33.3% to prevent come browsers from wrapping the right column.
2) DO NOT set margins for the columns
3) If possible, use a standard library such as Bootstrap
you can just use margins in css such as:
margin-left:.....
margin-right:....
margin-top:.....
margin-bottom:....
to do it this way you may have to give your td's and th's different id's so you can control them separately
I think you are saying you need three rows/columns in one table whose content is bound to expand.
In header append the stylesheet using
<link rel="stylesheet" href="q1.css" type="text/css">
CODE
<table >
<tr >
<th >Project name</th>
<th>Deadline</th>
<th></th>
</tr>
<tr >
<td>Project 1</td>
<td>24/1/2014</td>
<td><div class="scroll">You can use the overflow property when you want to have better control of the layout. The default value is visible.</div></td>
</tr>
<tr>
<td colspan="5">
<ul>
<li> Your total hours: 3:00</li>
<li>Budget left: €100</li>
</ul>
</td>
</tr>
</table>
css code
table,th,td
{
border : 1px solid black;
border-collapse : collapse;
}
td{
width:10px;
height:10px;
overflow:auto;
}
div.scroll
{
background-color:#00FFFF;
width:100px;
height:100px;
overflow:scroll;
}
If the table is overlapping other contents in the page then you could you css
clear:both;
The clear property specifies which sides of an element other floating elements are not allowed.

Setting the height of a table in HTML has no effect

Why does this table height not function?
<table border=1 bgcolor="green" width=80% height="30%">
<tr>
<td rowspan="2" >
This is 1st row 1st column
</td>
<td >
2
</td>
</tr>
</table>
http://jsfiddle.net/zQNS4/
just add the following to your css:
html, body{
height: 100%;
}
As other said, a table doesn't have a height-attriute, but most browsers intrepet that anyway. you can see the result on jsfiddle.
The reason you need to do this is that the parent element of anything that should have a height in % must have a height too (as Shadow Wizard said: "30% of what exactly?" - the parent has to have a height).
The table tag does not contain a height attribute. Try setting the height of the table using CSS styling.
table{
height: 30%;
}
<div style="height: 200px; overflow-y: scroll;">
<table border=1 bgcolor="green">
<tr>
<td rowspan="2" >
This is 1st row 1st column
</td>
<td>
2
</td>
</tr>
</table>
</div>
I just had the same issue.
I have table inside a container ( div config-table ), just setting height didn't work for me. I had to set overflow: auto ( for my case auto was needed ) and now work
.config-table {
height: 350px;
overflow: auto;
}

Prevent a table in overflow:auto div from shrinking

I'm having a bit of an issue getting some stylesheet behavior that I want. I'm not even sure if it's possible. Basically I'm attempting to place a table with a variable number of cells with static cell width in a DIV with overflow: auto, and my goal is that when the tables width extends past the width of the container DIV that it becomes scrollable.
This isn't the case. The cells get shrunk together. A very basic representation (with inline styles for ease on this; not actually in the application haha) of the code:
<div style="width: 1000px; overflow-x: auto;">
<table>
<tr>
<td style="width:400px;">
This
</td>
<td style="width:400px;">
Should
</td>
<td style="width:400px;">
Scroll!
</td>
</tr>
</table>
</div>
Is there anyway I can do this with CSS, or am I going to have to go back to setting the width inline on a second div containing the table through calculations?
Works if you set the width on the table itself.
<table style="width:1200px;">
The td will always shrink to the necessary size, they won't push the table wider in that situation.
using CSS can done like below but make sure you use id or class for applying css if you have more then one table or div.
<style>
div { width: 400px; overflow-x: auto; }
table { width:1200px; }
table td { width:400px; }
</style>
<div>
<table>
<tr>
<td>
This
</td>
<td>
Should
</td>
<td>
Scroll!
</td>
</tr>
</table>
</div>
This should help
<table style="width: max-content;">