I have tried to display div over table using z-index. I have searched on google about z-index. The information i got that z-index will only work on an element whose position property has been explicitly set to absolute , fixed , or relative. But it is still not working for me.
Please check my code and please explain what is the issue.
.task {
position: relative;
z-index: 1;
}
#check_filter {
width: 200px;
padding: 20px;
float: left;
position: absolute;
z-index: 2!important;
margin-left: 60px;
margin-top: 7px;
box-shadow: 1px 0px 20px 1px grey;
}
#radio_filter {
width: 200px;
padding: 20px;
float: left;
position: absolute;
z-index: 2!important;
margin-left: 180px;
margin-top: 7px;
box-shadow: 1px 0px 20px 1px grey;
}
Filters: Assigned To | Done
<div id="check_filter">
<div class="checkbox">
<label><input type="checkbox" value="">Option 1</label>
</div>
</div>
<div id="radio_filter">
<div class="radio">
<label><input type="radio" name="yes">Yes</label><br>
<label><input type="radio" name="no">No</label>
</div>
</div>
<br>
<table class="task" style="margin-top:30px; width:100%!important;">
<thead>
<tr style="background-color:black;color:white;">
<th>Task id</th>
<th>Task name</th>
<th>Task description</th>
<th>Assigned to</th>
<th>Done(yes/no)</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Your DIVs are already over table. You can't notice it, because the background of DIVs is transparent... To see/understand that, add background to DIVs.
.task {
position: relative;
z-index: 1;
}
#check_filter {
width: 200px;
padding: 20px;
float: left;
position: absolute;
z-index: 2!important;
margin-left: 60px;
margin-top: 7px;
box-shadow: 1px 0px 20px 1px grey;
}
#radio_filter {
width: 200px;
padding: 20px;
float: left;
position: absolute;
z-index: 2!important;
margin-left: 180px;
margin-top: 7px;
box-shadow: 1px 0px 20px 1px grey;
}
[id$="filter"] {
background: white
}
Filters: Assigned To | Done
<div id="check_filter">
<div class="checkbox">
<label><input type="checkbox" value="">Option 1</label>
</div>
</div>
<div id="radio_filter">
<div class="radio">
<label><input type="radio" name="yes">Yes</label><br>
<label><input type="radio" name="no">No</label>
</div>
</div>
<br>
<table class="task" style="margin-top:30px; width:100%!important;">
<thead>
<tr style="background-color:black;color:white;">
<th>Task id</th>
<th>Task name</th>
<th>Task description</th>
<th>Assigned to</th>
<th>Done(yes/no)</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Related
I have a piece of CSS I am working with. Whenever I add the "display: flex" property to .student, the border suddenly doubles. I need the flex property because I want the text to be centered vertically next to the image inside of the .student table data cell. How can I get rid of this pesky double border? The double border goes away whenever I remove the display:flex property, but then the text is no longer vertically next to the image. I've tried whitespace, border collapse, and several others without any luck.
Codepin: https://codepen.io/dansbyt/pen/dyvoejG?editors=1100
CSS:
/* ------------{GRADEBOOK}------------ */
.gradebook {
position: absolute;
top: 60px; left: 0;
width: 100vw; height: calc(100vh - 126px);
overflow-y: scroll;
box-sizing: border-box;}
/* Table styling*/
table {table-layout: fixed; border-collapse: collapse;}
/* Table heading styling */
thead th {
height: 60px; width: 100px;
top: 0; z-index: 2;
position: -webkit-sticky; position: sticky;
border-right: 1px solid gray;
background-color: white;}
thead th:first-child {left: 0; z-index: 10;}
th {
padding: 10px 16px;
text-align: left;
font-weight: normal;
color: gray}
table .duedate {font-size: 14px; margin-bottom: 8px}
table .title {font-size: 18px; color: #5B7042}
/* Table data styling */
td {
text-align: center;
border: 1px solid gray;
background-color: white}
td.late{background-color: #EA5D6B}
td input {
text-align: center;
padding: 4px; margin: 0;
width: 114px;
border: none;}
/* Student Name styling */
.student {
padding: 6px;
box-sizing: border-box;
display: flex;
align-items: center}
.pic{
display: inline-block;
width: 25px;
clip-path: circle();
margin-right: 10px;}
.pic img{display: none}
/* ------------{CONTROLS}------------ */
.controls {
display: flex;
position: absolute;
bottom: 10px; left: 0;
width: 100vw; height: 56px;
border-top: 1px solid #DDDDDD}
HTML:
<link rel="stylesheet" href="../style.css">
<div class='gradebook'>
<table>
<thead>
<tr>
<th style='width: 200px'></th>
<th>
<div class='duedate'>Due Oct 08</div>
<div class='title'>Mayflower Vocabulary</div>
</th>
<th>
<div class='duedate'>Due Oct 15</div>
<div class='title'>Wax Museum</div>
</th>
<th>
<div class='duedate'>Due Oct 15</div>
<div class='title'>American Revolution</div>
</th>
<th>
<div class='duedate'>Due Oct 27</div>
<div class='title'>Jamestown</div>
</th>
<th>
<div class='duedate'>Due Nov 1</div>
<div class='title'>Comparing Colonies</div>
</th>
</tr>
</thead>
<tr>
<td class='student'>
<img class='pic' src='../pics/default.png'>
<span>Jane Doe</span>
</td>
<td><input type='text' value='-'></td>
<td class='late'><input type='text' value='10'></td>
<td><input type='text' value='9.5'></td>
<td><input type='text' value='10'></td>
<td><input type='text' value='5'></td>
</tr>
<tr>
<td class='student'>
<img class='pic' src='../pics/default.png'>
<span>John Doe</span>
</td>
<td><input type='text' value='-'></td>
<td><input type='text' value='8'></td>
<td><input type='text' value='9'></td>
<td><input type='text' value='10'></td>
<td class='late'><input type='text' value='9'></td>
</tr>
</table>
</div>
<div class='controls'>
</div>
Image of issue:
Instead of using border: 1px solid gray you can try this.
td {
text-align: center;
border: 1px solid gray;
border-bottom: 0;
border-right: 0;
background-color: white
}
tr:last-of-type td {
border-bottom: 1px solid gray;
}
td:last-of-type {
border-right: 1px solid gray;
}
/* ------------{GRADEBOOK}------------ */
.gradebook {
position: absolute;
top: 60px;
left: 0;
width: 100vw;
height: calc(100vh - 126px);
overflow-y: scroll;
box-sizing: border-box;
}
/* Table styling*/
table {
table-layout: fixed;
border-collapse: collapse;
}
/* Table heading styling */
thead th {
height: 60px;
width: 100px;
top: 0;
z-index: 2;
position: -webkit-sticky;
position: sticky;
border-right: 1px solid gray;
background-color: white;
}
thead th:first-child {
left: 0;
z-index: 10;
}
th {
padding: 10px 16px;
text-align: left;
font-weight: normal;
color: gray
}
table .duedate {
font-size: 14px;
margin-bottom: 8px
}
table .title {
font-size: 18px;
color: #5B7042
}
/* Table data styling */
td {
text-align: center;
border: 1px solid gray;
border-bottom: 0;
border-right: 0;
background-color: white
}
tr:last-of-type td {
border-bottom: 1px solid gray;
}
td:last-of-type {
border-right: 1px solid gray;
}
td.late {
background-color: #EA5D6B
}
td input {
text-align: center;
padding: 4px;
margin: 0;
width: 114px;
border: none;
}
/* Student Name styling */
.student {
padding: 6px;
box-sizing: border-box;
display: flex;
align-items: center;
margin-bottom: -1px;
}
.pic {
display: inline-block;
width: 25px;
clip-path: circle();
margin-right: 10px;
}
.pic img {
display: none
}
/* ------------{CONTROLS}------------ */
.controls {
display: flex;
position: absolute;
bottom: 10px;
left: 0;
width: 100vw;
height: 56px;
border-top: 1px solid #DDDDDD
}
<link rel="stylesheet" href="../style.css">
<div class='gradebook'>
<table>
<thead>
<tr>
<th style='width: 200px'></th>
<th>
<div class='duedate'>Due Oct 08</div>
<div class='title'>Mayflower Vocabulary</div>
</th>
<th>
<div class='duedate'>Due Oct 15</div>
<div class='title'>Wax Museum</div>
</th>
<th>
<div class='duedate'>Due Oct 15</div>
<div class='title'>American Revolution</div>
</th>
<th>
<div class='duedate'>Due Oct 27</div>
<div class='title'>Jamestown</div>
</th>
<th>
<div class='duedate'>Due Nov 1</div>
<div class='title'>Comparing Colonies</div>
</th>
</tr>
</thead>
<tr>
<td class='student'>
<img class='pic' src='../pics/default.png'>
<span>Jane Doe</span>
</td>
<td><input type='text' value='-'></td>
<td class='late'><input type='text' value='10'></td>
<td><input type='text' value='9.5'></td>
<td><input type='text' value='10'></td>
<td><input type='text' value='5'></td>
</tr>
<tr>
<td class='student'>
<img class='pic' src='../pics/default.png'>
<span>John Doe</span>
</td>
<td><input type='text' value='-'></td>
<td><input type='text' value='8'></td>
<td><input type='text' value='9'></td>
<td><input type='text' value='10'></td>
<td class='late'><input type='text' value='9'></td>
</tr>
</table>
</div>
<div class='controls'>
</div>
My assumption is that problem arises from clashing between two layout alghorithms, table and flex one. Td belongs to table one and putting flex there just make problems.
So only solution is to wrap td content with div, and put flex onto that div.
table{
border-collapse: collapse;
}
td{
border: 1px solid;
}
.flex{
display: flex;
}
<!DOCTYPE html>
<html lang="en">
<body>
<table>
<th>flex</th>
<th>flex</th>
<tr>
<td class='flex'>...</td>
<td>...</td>
</tr>
<tr>
<td>...</td>
<td class='flex'>...</td>
</tr>
</table>
<table>
<th>div flex</th>
<th>div flex</th>
<tr>
<td> <div class='flex'>...</div></td>
<td> <div class='flex'>...</div></td>
</tr>
<tr>
<td> <div class='flex'>...</div></td>
<td> <div class='flex'>...</div></td>
</tr>
</table>
</body>
</html>
I have a weird question, and perhaps it's more suitable for the CSS fans out there, but why would content inside an absolute positioned div overflow out past everything else?
The example provided here (as a picture) shows that the content overflows out the blue bordered div. The content inside this box should rightfully define the the div's height no? How can this be remedied so that my 'blue' box fits to its content?
Here's the markup in question:
* {
box-sizing: border-box;
font-family: Verdana, Arial, sans-serif;
font-size: 9pt;
}
html {
height: 100%;
}
body {
margin: 0;
padding: 0;
height: 100%;
background: rgb(105, 105, 105);
}
#table-container {
display: table;
text-align: center;
width: 100%;
height: 100%;
}
#container {
display: table-cell;
vertical-align: middle;
}
#wrapper {
padding: 25px;
}
.tabs {
position: relative;
margin: 40px 0 25px;
}
.tab {
float: left;
}
.tab label {
background: rgb(105, 105, 105);
padding: 10px;
border: 1px solid transparent;
color: #FFF;
margin-left: -1px;
position: relative;
left: 1px;
top: -26px;
}
.tab label:hover {
background: #000;
}
.tab [type=radio] {
display: none;
}
.content {
position: absolute;
top: -1px;
left: 0;
background: rgb(222, 222, 222);
right: 0;
bottom: 0;
padding: 20px;
border: 1px solid transparent;
opacity: 0;
color: rgb(58, 58, 58);
}
[type=radio]:checked~label {
background: rgb(222, 222, 222);
font-weight: bold;
border-bottom: 1px solid transparent;
color: #000;
z-index: 2;
}
[type=radio]:checked~label~.content {
z-index: 1;
opacity: 1;
}
/* CSS for Table and Field styling */
.table {
width: 100%;
padding: 0;
margin: 0;
text-align: left;
}
.table td {
border: 1px solid #000;
}
.inputbox {
border: 1px solid rgb(170, 170, 170);
width: 100%;
}
.inputbox:hover {
border: 1px solid rgb(109, 109, 109);
}
.input {
border-style: none;
border-color: inherit;
border-width: 0;
padding: 3px;
height: 20px;
}
input[type="text"],
textarea {
width: 100%;
box-sizing: border-box;
}
.input:focus {
background: rgb(255, 255, 196);
}
<div id="table-container">
<div id="container">
<div id="wrapper">
<div style="border: 1px solid red; text-align: left; font-size: 8pt; color: #fff;">Choose language/Choisissez langue:</div>
<div style="border: 1px solid blue; height: 100%;">
<div class="tabs">
<!-- TAB [1] -->
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1" checked><label for="tab-1">English</label>
<div class="content">
<table class="table">
<tr>
<td>Traveller's Name:</td>
<td colspan="2">
<div class="inputbox"><input type="text" id="tname" class="input" name="Name of Traveler" tabindex="1" /></div>
</td>
<td style="width: 15%;"></td>
<td>Tan #:</td>
<td></td>
</tr>
<tr>
<td>Destination:</td>
<td colspan="2">
<div class="inputbox"><input type="text" id="location" class="input" name="Location" tabindex="2" /></div>
</td>
<td></td>
<td>Status:</td>
<td></td>
</tr>
<tr>
<td>iTravel Trip Number:</td>
<td colspan="2">
<div class="inputbox"><input type="text" id="location" class="input" name="Location" tabindex="2" /></div>
</td>
<td></td>
<td>Date Issued:</td>
<td>
<div class="inputbox"><input type="text" id="dissued" class="input" disabled/></div>
</td>
</tr>
<tr>
<td>Event Plan ID Code:</td>
<td colspan="2">
<div class="inputbox"><input type="text" id="evt-plan-code" class="input" name="Event Plan ID Code" tabindex="4" /></div>
</td>
<td></td>
<td>Issued by:</td>
<td>
<div class="inputbox"><input type="text" id="issuer" class="input" disabled/></div>
</td>
</tr>
<tr>
<td>Dates of Travel</td>
<td>From:</td>
<td>
<div id="ddate" name="Departure Date" tabindex="5"></div>
</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td> </td>
<td>To:</td>
<td>
<div id="rdate" name="Return Date" tabindex="6"></div>
</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Trip Purpose</td>
<td colspan="3"></td>
<td></td>
<td></td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-2" name="tab-group-1"><label for="tab-2">Français</label>
<div class="content">
tab2
</div>
</div>
</div>
</div>
<div style="border: 1px solid green; text-align: left;">
<input type="button" value="Issue TAN" id="issue">
<input type="button" value="Reset form" id="issue">
<input type="button" value="Save changes" id="issue">
</div>
</div>
<!-- end of div #wrapper -->
</div>
<!-- end of div #container -->
</div>
<!-- end of div #table-container -->
The absolute-positioned div doesn't affect the container div's size since setting position to absolute removes it from the document flow. It's essentially the same behaviour as when position is set to fixed, except it stays at the same place in the page when you scroll. More info can be found here and here.
As for how to fix the height of your div, the short answer is that it can't be done with CSS unless you use a different value for position, perhaps relative in your case but that will depend on the structure of your html. This question covers some other ways that you could go about it.
This question already has answers here:
overflow:hidden not working when using tables
(4 answers)
Closed 5 years ago.
Here is some kinda complicated html table formatting I have:
http://jsfiddle.net/nyCKE/8517/
The problem is that the "Subject Areas" table does not work when I try to do overflow scroll. It has a height set to 200px, but when I add many rows to the table, it doesn't stay at 200, it just keeps extending the table. As you can see on the jsfiddle, I have tbody set to overflow-y scroll (I want the thead to be fixed). But, it refuses to scroll. The "Classes" table has no data so it stays at 200px. That is what I want the height of the subject areas table to be, but clearly it is bigger. Here is some of the relevant css:
tbody {
overflow-y scroll;
}
.subjects{
width:100%;
height: 200px;
}
.classes {
width:100%;
height: 200px;
margin-top: 5px;
}
Another thing I forgot to mention is I have 2 div's, one for left and one for right. The left div contains the subjects and classes tables. The right div contains the overview. This is for when the window is bigger and by extending the window in the fiddle, you can see that the overview table goes to the right, which is what I want. I am not sure if these div's mess up the tbody scrolling.
Does anyone know how to solve my problem?
Bug in your css:
tbody {
overflow-y scroll;
}
should be:
tbody {
overflow-y: scroll;
}
Solution to your problem: define your height directly at child and use display: block
tbody {
overflow-y: scroll;
display: block;
height: 200px;
}
body {
background: #6CD3F8;
/*background: -webkit-linear-gradient(top left, #6CD3F8 0%, #E0F7FE 100%);
background: linear-gradient(to bottom right, #6CD3F8 0%, #E0F7FE 100%);*/
}
h3 {
color: white;
text-align: left;
margin-top: 20px;
}
.scan {
padding: 0% 10%;
}
table {
background: #E0F7FE;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
}
table td,
table td * {
vertical-align: top;
}
tbody {
overflow-y: scroll;
display: block;
height: 200px;
}
th {
color: #265C82;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal;
font-size: 17px;
padding-left: 5px;
padding-top: 5px;
}
td {
padding-left: 10px;
}
::-webkit-input-placeholder {
color: #00B2F3;
}
.search {
color: #00B2F3;
border: 0px solid red;
border-radius: 10px;
width: calc(100% - 10px);
height: 35px;
margin-top: 5px
}
.select {
width: calc(100% - 10px);
}
.icon {
width: 20px;
height: 20px;
margin: 2px 8px 0px 5px;
float: left;
}
hr {
border-color: #00B2F3;
margin: 3px 0;
width: calc(100% - 5px);
}
.subjects {
width: 100%;
height: 200px;
}
.classes {
width: 100%;
height: 200px;
margin-top: 5px;
}
.sections {
width: 100%;
height: 405px;
}
.left {
width: 50%;
float: left;
margin-right: 5px;
margin-bottom: 3%;
min-width: 300px;
}
.right {
width: calc(50% - 10px);
float: left;
min-width: 300px;
margin-bottom: 3%;
}
.mid {
width: 100%;
text-align: center;
float: left;
position: relative;
}
.wrapper {
width: 100%;
text-align: right;
float: left;
position: relative;
}
.logo {
max-width: 30%;
margin: 10px 0px;
}
.links > a {
color: rgba(255, 255, 255, 0.8);
font-size: 16px;
padding: 0px 10px;
}
.links {
/*padding-left: 100px;*/
padding-bottom: 10px;
}
<body>
<div class="scan">
<h3>Summer Session A</h3>
<!-- <div class="left">
left
</div> -->
<!-- <div class="right">
right
</div> -->
<div class="left">
<table class="subjects">
<thead>
<tr>
<th>
<div>Subject Areas</div>
<hr>
</th>
</tr>
<tr>
<th>
<input type="text" class="form-control search" onkeyup="searchFunction('subjects')" placeholder="Search...">
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Computer Science</td>
</tr>
<tr>
<td>Mathematics</td>
</tr>
<tr>
<td>Engineering</td>
</tr>
<tr>
<td>Computer Science</td>
</tr>
<tr>
<td>Mathematics</td>
</tr>
<tr>
<td>Engineering</td>
</tr>
<tr>
<td>Computer Science</td>
</tr>
<tr>
<td>Mathematics</td>
</tr>
<tr>
<td>Engineering</td>
</tr>
<tr>
<td>Computer Science</td>
</tr>
<tr>
<td>Mathematics</td>
</tr>
<tr>
<td>Engineering</td>
</tr>
<!-- <select class="form-control" id="exampleSelect1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select> -->
<!-- <tr>
<td>
<select class="form-control select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</td>
</tr> -->
</tbody>
</table>
<table class="classes">
<thead>
<tr>
<th>
Classes
<hr>
</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
<div class="right">
<table class="sections">
<thead>
<tr>
<th>
Overview
<hr>
</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
You can wrap the table in a container and give the height and overflow to the container.
body {
background: #6CD3F8;
/*background: -webkit-linear-gradient(top left, #6CD3F8 0%, #E0F7FE 100%);
background: linear-gradient(to bottom right, #6CD3F8 0%, #E0F7FE 100%);*/
}
h3 {
color: white;
text-align: left;
margin-top: 20px;
}
.scan {
padding: 0% 10%;
}
table {
background: #E0F7FE;
}
table,
.tableContainer {
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
}
table td,
table td * {
vertical-align: top;
}
tbody {
overflow-y scroll;
}
th {
color: #265C82;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal;
font-size: 17px;
padding-left: 5px;
padding-top: 5px;
}
td {
padding-left: 10px;
}
::-webkit-input-placeholder {
color: #00B2F3;
}
.search {
color: #00B2F3;
border: 0px solid red;
border-radius: 10px;
width: calc(100% - 10px);
height: 35px;
margin-top: 5px
}
.select {
width: calc(100% - 10px);
}
.icon {
width: 20px;
height: 20px;
margin: 2px 8px 0px 5px;
float: left;
}
hr {
border-color: #00B2F3;
margin: 3px 0;
width: calc(100% - 5px);
}
.subjectsContainer {
height: 200px;
overflow: scroll;
}
.subjects {
width: 100%;
}
.classes {
width: 100%;
height: 200px;
margin-top: 5px;
}
.sections {
width: 100%;
height: 405px;
}
.left {
width: 50%;
float: left;
margin-right: 5px;
margin-bottom: 3%;
min-width: 300px;
}
.right {
width: calc(50% - 10px);
float: left;
min-width: 300px;
margin-bottom: 3%;
}
.mid {
width: 100%;
text-align: center;
float: left;
position: relative;
}
.wrapper {
width: 100%;
text-align: right;
float: left;
position: relative;
}
.logo {
max-width: 30%;
margin: 10px 0px;
}
.links > a {
color: rgba(255, 255, 255, 0.8);
font-size: 16px;
padding: 0px 10px;
}
.links {
/*padding-left: 100px;*/
padding-bottom: 10px;
}
<body>
<div class="scan">
<h3>Summer Session A</h3>
<!-- <div class="left">
left
</div> -->
<!-- <div class="right">
right
</div> -->
<div class="left">
<div class="subjectsContainer tableContainer">
<table class="subjects">
<thead>
<tr>
<th>
<div>Subject Areas</div>
<hr>
</th>
</tr>
<tr>
<th>
<input type="text" class="form-control search" onkeyup="searchFunction('subjects')" placeholder="Search...">
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Computer Science</td>
</tr>
<tr>
<td>Mathematics</td>
</tr>
<tr>
<td>Engineering</td>
</tr>
<tr>
<td>Computer Science</td>
</tr>
<tr>
<td>Mathematics</td>
</tr>
<tr>
<td>Engineering</td>
</tr>
<tr>
<td>Computer Science</td>
</tr>
<tr>
<td>Mathematics</td>
</tr>
<tr>
<td>Engineering</td>
</tr>
<tr>
<td>Computer Science</td>
</tr>
<tr>
<td>Mathematics</td>
</tr>
<tr>
<td>Engineering</td>
</tr>
<!-- <select class="form-control" id="exampleSelect1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select> -->
<!-- <tr>
<td>
<select class="form-control select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</td>
</tr> -->
</tbody>
</table>
</div>
<table class="classes">
<thead>
<tr>
<th>
Classes
<hr>
</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
<div class="right">
<table class="sections">
<thead>
<tr>
<th>
Overview
<hr>
</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
I am trying to create a HTML table and I want my heading to be rotated 45 degrees.
I have found a few examples on the web which I can use.
However the header row height does not resize to the text entered. The text just wraps in the cell.
How do I make the row auto adjust the cell height according to the angled text?
My Code
HTML
<div class="scrollable-table">
<table class="table table-striped table-header-rotated">
<thead>
<tr>
<!-- First column header is not rotated -->
<th></th>
<!-- Following headers are rotated -->
<th class="column criterion rotate-45" ><div><span>Column header 1</span></div></th>
<th class="column criterion rotate-45" ><div><span>Column header 2</span></div></th>
</tr>
</thead>
<tbody>
<tr>
<th class="row-header">Row header 1</th>
<td><input checked="checked" name="column1[]" type="radio" value="row1-column1"></td>
<td><input checked="checked" name="column2[]" type="radio" value="row1-column2"></td>
</tr>
<tr>
<th class="row-header">Row header 2</th>
<td><input name="column1[]" type="radio" value="row2-column1"></td>
<td><input name="column2[]" type="radio" value="row2-column2"></td>
</tr>
<tr>
<th class="row-header">Row header 3</th>
<td><input name="column1[]" type="radio" value="row3-column1"></td>
<td><input name="column2[]" type="radio" value="row3-column2"></td>
</tr>
</tbody>
</table>
</div>
</body>
CSS
.table-header-rotated th.row-header{
width: auto;
}
.table-header-rotated td{
width: 40px;
border-top: 1px solid #dddddd;
border-left: 1px solid #dddddd;
border-right: 1px solid #dddddd;
vertical-align: middle;
text-align: center;
}
.table-header-rotated th.rotate-45{
height: 80px;
width: 40px;
min-width: 40px;
max-width: 40px;
position: relative;
vertical-align: bottom;
padding: 0;
font-size: 12px;
line-height: 0.8;
}
.table-header-rotated th.rotate-45 div{
position: relative;
top: 0px;
left: 40px; /* 80 * tan(45) / 2 = 40 where 80 is the height on the cell and 45 is the transform angle*/
height: 100%;
-ms-transform:skew(-45deg,0deg);
-webkit-transform:skew(-45deg,0deg);
transform:skew(-45deg,0deg);
overflow: hidden;
border-left: 1px solid #dddddd;
border-right: 1px solid #dddddd;
border-top: 1px solid #dddddd;
}
.table-header-rotated th.rotate-45 span {
-ms-transform:skew(45deg,0deg) rotate(315deg);
-webkit-transform:skew(45deg,0deg) rotate(315deg);
transform:skew(45deg,0deg) rotate(315deg);
position: absolute;
bottom: 30px; /* 40 cos(45) = 28 with an additional 2px margin*/
left: -25px; /*Because it looked good, but there is probably a mathematical link here as well*/
display: inline-block;
width: 85px; /* 80 / cos(45) - 40 cos (45) = 85 where 80 is the height of the cell, 40 the width of the cell and 45 the transform angle*/
text-align: left;
/* white-space: nowrap; *//*whether to display in one line or not*/
}
please see
http://jsfiddle.net/ephreal/9kxd3chm/
EDIT
I made a solution which is based on Jquery.
I calculate the row height based on the pixle length of the text string.
A few other values i found could just be left static in my case. Please see my
Fiddle
Regards
You need to add white-space:nowrap; to your header style
.table-header-rotated th.rotate-45 {
height: 80px;
width: 40px;
min-width: 40px;
max-width: 40px;
position: relative;
vertical-align: bottom;
padding: 0;
font-size: 12px;
line-height: 0.8;
white-space: nowrap;
}
http://jsfiddle.net/nvucgfmk/1/
I create the following HTML page and I would align the two DIV elements (the ones with lista and scheda id, contained within parent div) to the same position, at the top of the page. Here is my code:
#tabella1,
#tabella1 td {
border: solid 1px;
}
th {
border: solid 1px;
font-style: bold;
background-color: white;
}
#tabella1 tr:nth-child(odd) {
background-color: gray;
}
#tabella1 tr:nth-child(even) {
background-color: lightgray;
}
#tabella1 tr:nth-child(n):not(:nth-child(1)):hover {
background-color: blue;
color: yellow;
cursor: pointer;
}
.titolo {
text-align: center;
font-weight: bold;
}
#lista {
display: inline-block;
margin: 30px;
position: relative;
top: 0px;
}
button {
width: 60px;
height: 20px;
}
form {
display: inline-block;
}
#msg {
font-weight: bold;
}
#scheda {
display: inline-block;
position: relative;
top: 0px;
text-align: center;
}
#tabella2 td:nth-child(even) {
border: solid 1px;
}
.cellaVuota {
width: 140px;
}
<div id="carica">
<form method="post" action="carica2.php">
<label for "n">Inserisci nome:
<input type="text" id="n" name="nome" size="10" />
</label>
<button type="submit">Invia</button>
</form>
<form method="post" action="carica2.php">
<button type="submit" name="logout">Logout</button>
</form>
</div>
<div id="parent">
<div id="lista">
<table id="tabella1">
<tr>
<th>Modello</th>
<th>27.5</th>
<th>29</th>
</tr>
<tr>
<td>Riga 1</td>
<td>Riga 2</td>
<td>Riga 3</td>
</tr>
</table>
<p class="titolo">Bici Mountain Bike</p>
</div>
<div id="scheda">
<p class="titolo">Bici selezionata</p>
<table id="tabella2">
<tr>
<td>Modello</td>
<td class="cellaVuota"></td>
</tr>
<tr>
<td>Misura 27.5</td>
<td class="cellaVuota"></td>
</tr>
<tr>
<td>Misura 29</td>
<td class="cellaVuota"></td>
</tr>
</table>
</div>
</div>
I searched and searched here before post this question (see position and ~top` properties in the CSS code), but I do not figure out how to reach my purpose.
Just add vertical-align: top; to both divs.
You can also remove position: relative; and top: 0; properties