Keep inner div from expanding beyond fixed height outer div - html

I need my last div ("content"), whose height can vary, to expand to fill the container div but not expand beyond it. If the content div's contents won't fit, it should simply scroll with overflow-y: auto
However, I can't seem to contain the content div. I've tried a host of css without success and would appreciate some help.
UPDATE
I see I left out one important piece of info. I do not want to specify a fixed height of the "content" div since the height of the container can vary (it is resizable). I would have to calculate and adjust the height of the content with each mousemove (which I am trying to avoid).
Here is a fiddle
#container {
max-height: 350px;
width: 200px;
border: 2px solid black;
display: block;
position: absolute;
}
#title {
height: 100px;
width: 100%;
border: 2px solid red;
}
#tabs {
height: 100px;
width: 100%;
border: 2px solid green;
}
#content {
height: 100%;
width: 100%;
border: 2px solid blue;
overflow-y: auto;
}
<div id="container">
<div id="title">
Title
</div>
<div id="tabs">
Tabs
</div>
<div id="content">
<table>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
</table>
</div>
</div>

Explanation:
Added overflow: hidden; to #container and added
overflow-y: auto; to #content attribute
Scroll-Demo
#container {
max-height: 350px;
width: 200px;
border: 2px solid black;
display: block;
position: relative;
overflow: hidden;
}
#title {
height: 100px;
width: 100%;
border: 2px solid red;
}
#tabs {
height: 100px;
width: 100%;
border: 2px solid green;
}
#content {
height: 100px;
width: 100%;
border: 2px solid blue;
overflow-y: auto;
}
<div id="container">
<div id="title">
Title
</div>
<div id="tabs">
Tabs
</div>
<div id="content">
<table>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
<tr>
<td>
<label>ABC
</label>
</td>
</tr>
</table>
</div>
</div>

height:100% is preventing that. Specify height, for example, in pixels.
Or use height: calc(100% - 208px);, to calculate the dynamic height. Don't forget to change max-height to height.
#container {
height: 350px;
width: 200px;
border: 2px solid black;
display: block;
position: absolute;
}
#title {
height: 100px;
width: 100%;
border: 2px solid red;
}
#tabs {
height: 100px;
width: 100%;
border: 2px solid green;
}
#content {
height: calc(100% - 208px);
width: 100%;
border: 2px solid blue;
overflow-y: scroll;
}
<div id="container">
<div id="title">
Title
</div>
<div id="tabs">
Tabs
</div>
<div id="content">
<table>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
</table>
</div>
</div

Here is a bit of a more fun way to do it. Removed your need for putting width 100% all over the place as well!
#container {
max-height: 350px;
width: 200px;
border: 2px solid black;
display: flex;
flex-direction: column;
position: absolute;
}
#title {
flex: 0 0 100px;
border: 2px solid red;
}
#tabs {
flex: 0 0 100px;
border: 2px solid green;
}
#content {
flex: 1 1 auto;
border: 2px solid blue;
overflow-y: auto;
}
<div id="container">
<div id="title">
Title
</div>
<div id="tabs">
Tabs
</div>
<div id="content">
<table>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
</table>
</div>
</div>

You can do that using display: flex.
#container {
max-height: 350px;
width: 200px;
border: 2px solid black;
position: absolute;
display: flex; /* Added */
flex-direction: column; /* Added */
}
#title {
height: 100px;
width: 100%;
border: 2px solid red;
}
#tabs {
height: 100px;
width: 100%;
border: 2px solid green;
}
#content {
height: 100%;
width: 100%;
border: 2px solid blue;
overflow-y: auto;
flex: auto; /* Added, this container should stretch in the remaining space */
}
Working Fiddle

You wanted only the last table to scroll, right?
#container {
max-height: 350px;
width: 200px;
border: 2px solid black;
display: block;
position: absolute;
margin-bottom: 15px; /*just to see the bottom*/
}
#title {
height: 100px;
width: 100%;
border: 2px solid red;
box-sizing: border-box;
}
#tabs {
height: 100px;
width: 100%;
border: 2px solid green;
box-sizing: border-box;
}
#content {
max-height: 138px;
box-sizing: border-box;
width: 100%;
border: 2px solid blue;
overflow-y: auto;
}
<div id="container">
<div id="title">
Title
</div>
<div id="tabs">
Tabs
</div>
<div id="content">
<table>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
</table>
</div>
</div>

HTML Code
<div id="container">
<div id="title">
Title
</div>
<div id="tabs">
Tabs
</div>
<div id="content">
<table>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
<tr>
<td>
<label>ABC</label>
</td>
</tr>
</table>
</div>
</div>
Css
#container {
max-height: 350px;
width: 200px;
border: 2px solid black;
display: block;
position: absolute;
}
#title {
height: 100px;
width: 100%;
border: 2px solid red;
}
#tabs {
height: 100px;
width: 100%;
border: 2px solid green;
}
#content {
height: 100px;
width: 100%;
border: 2px solid blue;
overflow-y: auto;
}
fiddle link

Related

Styling DIVs inside Tables

I am trying to define a weekly calendar, have a table with seven columns (one per day) and 24 rows (one per half an hour):
.cal-week {
border-collapse: collapse;
}
.cal-week-day {
width: 14%;
}
.cal-week-hour > td {
border: solid 1px #d8d8d8;
height: 2.2em;
position: relative;
}
.cal-week-hour > td > div {
position: absolute;
top: 0px;
z-index: 5;
width: 100%;
}
.item {
background-color: #494C4F;
color: #f4f4f4;
border: solid 1px #c8c8c8;
}
.item > div {
white-space: nowrap;
}
<table class="cal-week" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th class="cal-week-day">
monday
</th>
<th class="cal-week-day">
tuesday
</th>
<th class="cal-week-day">
wednesday
</th>
</tr>
<tr class="cal-week-hour">
<td>
<div/>
</td>
<td>
<div/>
</td>
<td>
<div/>
</td>
</tr>
<tr class="cal-week-hour">
<td>
<div/>
</td>
<td>
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="item" width="33.333333333333336%" >
<div>a long description</div>
</td>
<td class="item" width="33.333333333333336%" >
<div>normal desc</div>
</td>
<td class="item" width="33.333333333333336%" >
<div>short</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td>
<div/>
</td>
</tr>
<tr class="cal-week-hour">
<td>
<div/>
</td>
<td>
<div/>
</td>
<td>
<div/>
</td>
</tr>
<tr class="cal-week-hour">
<td>
<div/>
</td>
<td>
<div/>
</td>
<td>
<div/>
</td>
</tr>
<tr class="cal-week-hour">
<td>
<div/>
</td>
<td>
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="item">
<div>asdsad</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td>
<div/>
</td>
</tr>
</tbody>
</table>
I am using React, the percentage of the tds of the inner tables are calculated as 100 / numberOfItems, in this example since we have 3 items -> 33.333333%. The problem is that the divs can be wider than the tds and as you can see in the fiddler they span over the next column.
The desired output is the following:
In fact, I have to draw n boxes which have to fit the parent (td) width, which in this case is dynamic. Furthermore, it should be responsive, so I cannot use static widths.
Any hints how to achieve such a result?
You can make the .item class into an inline-block element which will fix the 33% width.
Also because the border is added after the 33% width, your item is a bit to wide (it will be 33% + 1px left-border + 1px-right border).
you should consider giving the .item class a box-sizing: border-box; so the border will be inside this 33% width.
After this you get your desired output. See fiddle: https://jsfiddle.net/d2burtaz/
I also changed your min-height from those td's from 141px to 41px so it looks more like the picture you added.
-- Can you give me an example using just divs? question by Emaborsa.
Ofcourse, I would just remove the inner table with all its table elements, also remove the empty div's. And change the <td>'s into <div>'s. The only thing I have added after this is a .w-100 class which I added to the outer div so the 33% width on the inner children works.
.cal-week {
border-collapse: collapse;
font-size: 14px;
font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
}
.cal-week-top {
font-weight: normal;
text-align: left;
color: #444;
padding: 2px;
text-transform: uppercase;
}
.cal-week-day {
width: 14%;
}
.cal-week-day-link:hover {
cursor: pointer;
text-decoration: underline;
}
.cal-week-weeksel div {
width: 16px;
}
.cal-week-weeksel:hover {
cursor: pointer;
background-color: var(--hover-light);
}
.cal-week-time00 {
text-align: right;
border-right: solid 1px #d8d8d8);
border-left: solid 1px #d8d8d8;
padding: 1px 5px 2px 5px;
}
.cal-week-hour00 > td,
.cal-week-time {
border-top: solid 1px #d8d8d8;
border-bottom: dashed 1px #d8d8d8;
}
.cal-week-hour30 > td{
border-bottom: solid 1px #d8d8d8;
}
.cal-week-time30,
.cal-week-cell {
border-right: solid 1px #d8d8d8;
border-left: solid 1px #d8d8d8;
height: 2.2em;
}
.cal-week-cell {
position: relative;
}
.cal-week-cell > div {
position: absolute;
top: 0px;
z-index: 5;
width: 100%;
}
.cal-week-today {
background-color: var(--button-border-disabled);
}
.item {
background-color: #494C4F;
color: #f4f4f4;
padding: 1px 2px 2px 2px;
border: solid 1px #c8c8c8;
display: inline-block;
box-sizing: border-box;
}
.item a {
color: #f4f4f4;
}
.item a:hover {
text-decoration: underline;
}
.w-100{
width: 100%;
}
<table class="cal-week" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th class="cal-week-top cal-week-day">
<div class="cal-week-day-link">26. Dienstag</div>
</th>
<th class="cal-week-top cal-week-day">
<div class="cal-week-day-link">27. Mittwoch</div>
</th>
<th class="cal-week-top cal-week-day">
<div class="cal-week-day-link">28. Donnerstag</div>
</th>
</tr>
<tr class="cal-week-hour00">
<td class="cal-week-cell">
<div/>
</td>
<td class="cal-week-cell">
<div/>
</td>
<td class="cal-week-cell">
<div/>
</td>
</tr>
<tr class="cal-week-hour30">
<td class="cal-week-cell">
<div/>
</td>
<td class="cal-week-cell">
<div class="w-100">
<div class="item single" title="10:30 - 14:25 Titel (Beschreibung)" style="min-height: 41px; width: 33.333336%;">
Titel
<div>Beschreibung</div>
</div><div class="item single" title="10:30 - 14:25 Titel (Beschreibung)" style="min-height: 41px; width: 33.333336%;">
Titel
<div>Beschreibung</div>
</div><div class="item single" title="10:30 - 14:25 Titel (Beschreibung)" style="min-height: 41px; width: 33.333336%;">
Titel
<div>Beschreibung</div>
</div>
</div>
</td>
<td class="cal-week-cell">
<div/>
</td>
</tr>
<tr class="cal-week-hour00">
<td class="cal-week-cell">
<div/>
</td>
<td class="cal-week-cell">
<div/>
</td>
<td class="cal-week-cell">
<div/>
</td>
</tr>
<tr class="cal-week-hour30">
<td class="cal-week-time30"/>
<td class="cal-week-cell">
<div/>
</td>
<td class="cal-week-cell">
<div/>
</td>
</tr>
<tr class="cal-week-hour00">
<td class="cal-week-cell">
<div/>
</td>
<td class="cal-week-cell">
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td class="item single" title="12:26 - 13:26 sdsdsd (asdsad)" width="100%" style="min-height: 61px;">
<div>
<div>
sdsdsd
</div>
<div>asdsad</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td class="cal-week-cell">
<div/>
</td>
</tr>
</tbody>
</table>

How can I make a Table mobile responsive

I am trying to make a table mobile responsive. The first thing I would love to do is to decrease the width size of the table headings and then enable the table data to have one complete row for each data.
I am trying to get my table to look like the attached picture on mobile.
.email-table table{
margin-left: 40px;
font-family: 'Roboto', sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border-top: 1px solid #dddddd;
border-bottom: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
td{
font-size: 1.2rem;
}
td:last-of-type{
font-weight: 700;
}
.attachment{
display: flex;
justify-content: center;
width: 20%;
align-items: center;
}
.first-clip span:last-of-type{
margin-right: 20px;
}
.last-clip{
margin-left: 25px;
}
.attachment span:last-of-type{
flex-shrink: 0;
}
.attachment span:first-of-type img{
width: 20px;
height: 20px;
}
.text-attachment{
display: flex;
justify-content: space-around;
}
.text-attachment span:first-of-type{
transform: translateX(-18px);
}
.second-text{
transform: translateX(5px);
}
.text-attachment span:last-of-type{
border: 1px solid #ccc;
background-color: #5E5D5D;
color: white;
border-radius: 5px;
padding: 0px 5px;
}
.second-text span:last-of-type{
transform: translateX(-10px);
}
td img{
width: 20px;
height: 20px;
transform: translateX(-30px);
}
th{
background-color: #EEEDED;
border-top: 3px solid #dddddd;
border-bottom: 3px solid #dddddd;
}
th:not(:last-child){
color: #5E5D5D;
}
.date>span img{
height: 10px;
width: 10px;
padding-left: 3px;
}
tr:not(:first-of-type):hover{
cursor: pointer;
color: blue;
background-color: #EEEDED;
}
<div class="email-table">
<table>
<tr>
<th>From</th>
<th>To</th>
<th>Subject</th>
<th class="date">Date <span><img src="./assets/icon_arrow01.svg" alt=""></span></th>
</tr>
<tr>
<td>aaa#example.com</td>
<td>zzz.zzz#example.com</td>
<td>[ HR-888 ] Notice of official announcement</td>
<td>0:20</td>
</tr>
<tr>
<td>bbb.bbbb#exam... </td>
<td>yyy#example.com</td>
<td>[web:333] "Web Contact"</td>
<td>0:10</td>
</tr>
<tr>
<td>ccc#example.com </td>
<td>
<div class="text-attachment">
<span>xxx#example.com, ...</span>
<span>+1</span>
</div>
</td>
<td>Happy New Year! Greetings for the New Year.</td>
<td>
<div class="attachment first-clip">
<span><img src="./assets/icon_clip.svg" alt=""></span>
<span>0:00</span>
</div>
</td>
</tr>
<tr>
<td>ddd.dddd#exam...</td>
<td>
<div class="text-attachment second-text">
<span>vvv.vvv#example.com, ... </span>
<span>+1</span>
</div>
</td>
<td>[HR-887(Revised: Office Expansion Project Team)] Notice of off... </td>
<td>Jan 01 </td>
</tr>
<tr>
<td>eee#example.com</td>
<td>
<div class="text-attachment">
<span>sss#example.com, .... </span>
<span>+2</span>
</div>
</td>
<td>[Github] Logout page</td>
<td>Jan 01</td>
</tr>
<tr>
<td>fff.ffff#example.c... </td>
<td>qqq.qqq#example.com</td>
<td>[dev] Postfix 3.1.12 / 3.2.9 / 3.3.4 / 3.4.5</td>
<td>Jan 01</td>
</tr>
<tr>
<td>ggg#example.com </td>
<td>ppp#example.com</td>
<td>Re: [Github] Brush-up on loading animation </td>
<td>Jan 01</td>
</tr>
<tr>
<td>hhh.hhh#examp...</td>
<td>ooo.ooo#example.com</td>
<td>Workplace Summary for sample, Inc.: Jun 2 - Jun 9</td>
<td>
<div class="attachment">
<span><img src="./assets/icon_clip.svg" alt=""></span>
<span>Jan 01</span>
</div>
</td>
</tr>
<tr>
<td>iii#example.com</td>
<td>nnn#example.com</td>
<td>I love you</td>
<td>
<div class="attachment last-clip">
<span><img src="./assets/icon_clip.svg" alt=""></span>
<span>2019/12/31</span>
</div>
</td>
</tr>
<tr>
<td>Pablo-Diego-...</td>
<td>Pablo-Diego-José-Francisc...
</td>
<td>[info:888] ABC EQUIPMENT COMPANY</td>
<td>2019/12/31</td>
</tr>
</table>
</div>
I, first of all, tried to make the header much smaller but that does not even work. I am totally lost at the steps I need to take to make this look good on mobile.
The trick for this sort of layout is to throw away the default table styling entirely.
Use display: contents to stop the tbody element from generating a box. Then use display: flex on the table to make it lay out the tr elements in a non-tabular column.
Then each tr can be styled as a CSS Grid, and the various elements positioned on that.
#media screen and (max-width: 1000px) {
body {
background: #AAA
}
table {
display: flex;
flex-direction: column;
margin: 0 10%;
background: white;
}
tbody,
tfoot {
display: contents;
}
thead {
display: none;
}
tr {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
gap: 1px 1px;
grid-template-areas: "From Date" "To Date" "Subject Date";
border-bottom: solid #aaa 1px;
}
td {
padding: 3px;
}
td:nth-child(1) {
grid-area: From;
}
td:nth-child(2) {
grid-area: To;
}
td:nth-child(3) {
grid-area: Subject;
}
td:nth-child(4) {
grid-area: Date;
text-align: right;
}
}
<div class="email-table">
<table>
<thead>
<tr>
<th>From</th>
<th>To</th>
<th>Subject</th>
<th class="date">Date <span><img src="./assets/icon_arrow01.svg" alt=""></span></th>
</tr>
</thead>
<tr>
<td>aaa#example.com</td>
<td>zzz.zzz#example.com</td>
<td>[ HR-888 ] Notice of official announcement</td>
<td>0:20</td>
</tr>
<tr>
<td>bbb.bbbb#exam... </td>
<td>yyy#example.com</td>
<td>[web:333] "Web Contact"</td>
<td>0:10</td>
</tr>
<tr>
<td>ccc#example.com </td>
<td>
<div class="text-attachment">
<span>xxx#example.com, ...</span>
<span>+1</span>
</div>
</td>
<td>Happy New Year! Greetings for the New Year.</td>
<td>
<div class="attachment first-clip">
<span><img src="./assets/icon_clip.svg" alt=""></span>
<span>0:00</span>
</div>
</td>
</tr>
<tr>
<td>ddd.dddd#exam...</td>
<td>
<div class="text-attachment second-text">
<span>vvv.vvv#example.com, ... </span>
<span>+1</span>
</div>
</td>
<td>[HR-887(Revised: Office Expansion Project Team)] Notice of off... </td>
<td>Jan 01 </td>
</tr>
<tr>
<td>eee#example.com</td>
<td>
<div class="text-attachment">
<span>sss#example.com, .... </span>
<span>+2</span>
</div>
</td>
<td>[Github] Logout page</td>
<td>Jan 01</td>
</tr>
<tr>
<td>fff.ffff#example.c... </td>
<td>qqq.qqq#example.com</td>
<td>[dev] Postfix 3.1.12 / 3.2.9 / 3.3.4 / 3.4.5</td>
<td>Jan 01</td>
</tr>
<tr>
<td>ggg#example.com </td>
<td>ppp#example.com</td>
<td>Re: [Github] Brush-up on loading animation </td>
<td>Jan 01</td>
</tr>
<tr>
<td>hhh.hhh#examp...</td>
<td>ooo.ooo#example.com</td>
<td>Workplace Summary for sample, Inc.: Jun 2 - Jun 9</td>
<td>
<div class="attachment">
<span><img src="./assets/icon_clip.svg" alt=""></span>
<span>Jan 01</span>
</div>
</td>
</tr>
<tr>
<td>iii#example.com</td>
<td>nnn#example.com</td>
<td>I love you</td>
<td>
<div class="attachment last-clip">
<span><img src="./assets/icon_clip.svg" alt=""></span>
<span>2019/12/31</span>
</div>
</td>
</tr>
<tr>
<td>Pablo-Diego-...</td>
<td>Pablo-Diego-José-Francisc...
</td>
<td>[info:888] ABC EQUIPMENT COMPANY</td>
<td>2019/12/31</td>
</tr>
</table>
</div>

Filling multiple td for one th

I need to make a table with answers to a question. I am putting questions in th and I need multiple answers related to that question.
The main problem is that I can not achieve that answers follow count(number and percents). I made
Codepen so that you can see what I get there. I will be filling this tables with JSON on Angular2 with *ngFor.
<div class="table-wrapper" id='table'>
<table>
<tr>
<th>Whats your gender?</th>
<th>What's your age?</th>
<th>How often do you train?</th>
</tr>
<tr>
<td>
<span>Female</span>
<span>Male</span>
</td>
<td class='flex'>
<span>15-24</span>
<span>25-34</span>
</td>
<td>
<span>Less than one a month</span>
<span>A few times a month</span>
</td>
</tr>
<tr>
<td>
<span>
573
</span>
<span>
299
</span>
</td>
<td>
<span>20%</span>
<span>68%</span>
</td>
<td>
<span>5%</span>
<span>3%</span>
</td>
</tr>
<tr>
<td>
<span>
66%
</span>
<span>
34%
</span>
</td>
<td>
<span>173</span>
<span>391</span>
</td>
<td>
<span>173</span>
<span>391</span>
</td>
</tr>
</table>
</div>
css
.table-wrapper {
width: 850px;
overflow: scroll;
}
.flex {
display: flex;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
min-width: 1000px;
}
span {
padding-right: 15px;
}
td, th {
text-align: left;
padding: 8px;
width; 40px;
}
td {
max-height: 100%;
}
tr:nth-child(even) {
background-color: #dddddd;
}
You should use colspan on the first line of your table and also make your second line with th instead of td since it's a second line of header.
.table-wrapper {
width: 850px;
overflow: scroll;
}
.flex {
display: flex;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
min-width: 1000px;
}
span {
padding-right: 15px;
}
td, th {
text-align: left;
padding: 8px;
width; 40px;
}
td {
max-height: 100%;
}
tr:nth-child(even) {
background-color: #dddddd;
}
::-webkit-scrollbar {
width: 1px;
border-radius: 2px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: #e0e0e0;
height: 2px;
}
::-webkit-scrollbar:horizontal{
height: 15px;
border-radius: 2px;
}
::-webkit-scrollbar-track:horizontal {
background: #fff;
height: 2px;
}
::-webkit-scrollbar-thumb:horizontal {
height: 2px;
}
<div class="table-wrapper" id='table'>
<table>
<tr>
<th colspan="2">Whats your gender?</th>
<th colspan="2">What's your age?</th>
<th colspan="2">How often do you train?</th>
</tr>
<tr>
<th>
<span>Female</span>
</th>
<th>
<span>Male</span>
</th>
<th class='flex'>
<span>15-24</span>
</th>
<th>
<span>25-34</span>
</th>
<th>
<span>Less than one a month</span>
</th>
<th>
<span>A few times a month</span>
</th>
</tr>
<tr>
<td>
<span>
573
</span>
</td>
<td>
<span>
299
</span>
</td>
<td>
<span>20%</span>
</td>
<td>
<span>68%</span>
</td>
<td>
<span>5%</span>
</td>
<td>
<span>3%</span>
</td>
</tr>
<tr>
<td>
<span>
66%
</span>
</td>
<td>
<span>
34%
</span>
</td>
<td>
<span>173</span>
</td>
<td>
<span>391</span>
</td>
<td>
<span>173</span>
</td>
<td>
<span>391</span>
</td>
</tr>
</table>
</div>
here i am sharing the link of JSFIDDLE
i edited your code, i think it is useful to you
<table>
<tr>
<th colspan=2>Whats your gender?</th>
<th colspan=2>What's your age?</th>
<th colspan=2>How often do you train?</th>
</tr>
<tr>
<td>Female</td>
<td>Male</td>
<td>15-24</td>
<td>25-34</td>
<td>Less than one a month</td>
<td>A few times a month</td>
</tr>
<tr>
<td>
573
</td>
<td>
299
</td>
<td>20%</td>
<td>68%</td>
<td>5%</td>
<td>3%</td>
</tr>
<tr>
<td>
66%
</td>
<td>
34%
</td>
<td>173</td>
<td>391</td>
<td>173</td>
<td>391</td>
</tr>
</table>
</div>
in css
.table-wrapper {
width:100%;
overflow: scroll;
}
th
{
text-align:center;
}
.flex {
display: flex;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
min-width: 1000px;
}
span {
padding-right: 15px;
}
td, th {
padding: 8px;
width; 40px;
}
td {
max-height: 100%;
}
tr:nth-child(even) {
background-color: #dddddd;
}
https://jsfiddle.net/p9su2je6/6/
You can use the colspan attribute on the th tags:
<div class="table-wrapper" id='table'><table>
<tr>
<th colspan="2">Whats your gender?</th>
<th colspan="2">What's your age?</th>
<th colspan="2">How often do you train?</th>
</tr>
<tr>
<td><span>Female</span></td>
<td><span>Male</span></td>
<td><span>15-24</span></td>
<td><span>25-34</span></td>
<td><span>Less than one a month</span></td>
<td><span>A few times a month</span></td>
</tr>
<tr>
<td><span>573</span></td>
<td><span>299</span></td>
<td><span>20%</span></td>
<td><span>68%</span></td>
<td><span>5%</span></td>
<td><span>3%</span></td>
</tr>
<tr>
<td><span>66%</span></td>
<td><span>34%</span></td>
<td><span>173</span></td>
<td><span>391</span></td>
<td><span>173</span></td>
<td><span>391</span></td>
</tr>

Showing two things when hoverd

I have a title and when i hoverd i would like that it would show two difrent tables. Is that possible?
I tride this one:
#ArijsLieve:hover ~ #arijslievetable ~ #arijslievefototable { display: block; }
but this only shows the #arijslievefototable.
my full code in html:
<div id="ArijsLieve">
<h3> Arijs Lieve </h3>
</div>
<table id="arijslievetable">
<tr>
<td> Kleuters 3j woensdag </td>
</tr>
<tr>
<td> Kleuters 4j woensdag </td>
</tr>
<tr>
<td> Kleuters 5j woensdag </td>
</tr>
<tr>
<td> Team acro competitie </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> E-mail: </td>
</tr>
<tr>
<td> jenskemeert#hotmail.com </td>
</tr>
</table>
<table id="arijslievefototable">
<tr>
<td> <img src="lieve_arijs.jpg" alt="lieve_arijs" width=100 height=100 /> </td>
</tr>
</table>
and css:
#ArijsLieve{background: #333; color: white; width: 100px; text-align: center; position: relative; top: -300px; left: 265px; cursor: pointer; }
`#arijslievetable{ background: #333; color: white; width: 810px; position: absolute; top: 701px; left: 273px; display: none; }
#ArijsLieve:hover ~ #arijslievetable ~ #arijslievefototable { display: block; }
#arijslievefototable{ background: #333; width: 1px; position:absolute; top: 701px; left: 976px; display: none;}
should be this
#ArijsLieve:hover ~ #arijslievetable,
#ArijsLieve:hover ~ #arijslievefototable { display: block; }

Unable To Apply CSS To Table Cell

I have table cells with class=image to which I cannot seem to apply any CSS. Here is my markup (nested tables) where the first table shows an example of a typical row:
<table class="outer">
<tr>
<td>
<table class="column" id="leftColumn">
<tr>
<td>
<table class="cell" id="t1">
<tr>
<td><asp:Literal runat="server" ID="t1r2c1" /></td>
<td class="image">
<span id="s1" runat="server">
<asp:PlaceHolder ID="p1" runat="server">
</asp:PlaceHolder>
</span>
</td>
<td><asp:Literal runat="server" ID="t1r2c3" /></td>
<td class="gray"><asp:Literal runat="server" ID="t1r2c4" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t2">
</table>
</td>
</tr>
</table>
</td>
<td>
<table class="column" id="rightColumn">
<tr>
<td>
<table class="cell" id="t3">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t4">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t5">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t6">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t7">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t8">
</table>
</td>
</tr>
<tr>
<td>
<table class="messages" id="t9">
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
Here is my CSS:
.outer
{
border: none;
margin-left: auto;
margin-right: auto;
}
.outer td
{
vertical-align: top;
}
.column
{
border: none;
}
#rightColumn table, #leftColumn table
{
width: 100%;
}
.cell
{
border-collapse: collapse;
border: 2px solid black;
margin: 5px;
}
.cell td
{
border-collapse: collapse;
border: 2px solid black;
text-align: center;
vertical-align: middle;
padding-left: 3px;
padding-right: 3px;
padding-top: 0px;
padding-bottom: 0px;
font-size: 11pt;
}
.cell .image
{
padding: 0;
margin: 0;
height: 2px;
width: 7px;
}
.messages td
{
border-collapse: collapse;
border: 2px solid #FF0000;
text-align: left;
}
h1
{
text-align: center;
font-size: 150%;
}
h2
{
text-align: center;
}
th
{
height: 24px;
background-color: #2B60DE;
color: #FFFFFF;
}
.gray
{
background-color: #AAAAAA;
}
Nothing I do to .cell .image seems to be able to shrink the images below a certain size -- which is already much smaller than the actual images so I know some shrinking is already going on.
Any advice is appreciated.
Could be the line-height or font-size preventing the td to become smaller.
Try setting the tds of the row with the image to line-height: 0px and font-size: 0px
I put together a jsfiddle of your example at http://jsfiddle.net/9xLqY/. The styles are being applied just fine when I remove the ASP components:
<span id="s1" runat="server">
<asp:PlaceHolder ID="p1" runat="server"></asp:PlaceHolder>
</span>
So it must be one of these components that is forcing the cells to be larger than you want. You'll need to add styles for #s1 and #p1.