I'm trying to emulate the code in Responsive Data Table to reformat a table where a row is vertical. My difference is that I want only a single row (an edited row) to be vertical and the rest normal.
tr.utr {
display: block;
border: 1px solid #ccc;
}
td.utd {
display: block;
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 30%;
}
td.utd:before {
position: absolute;
top: 6px;
left: 6px;
width: 60%;
padding-right: 10px;
white-space: nowrap;
}
td.utd:nth-of-type(1):before {
content: "First";
}
td.utd:nth-of-type(2):before {
content: "Second";
}
td.utd:nth-of-type(3):before {
content: "Third";
}
<table>
<thead>
<tr>
<th>Address</th>
<th>Status</th>
<th>Query</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan=3>Copy of https://css-tricks.com/responsive-data-tables/</td>
</tr>
<tr>
<td>100 Central Ave.</td>
<td>Listings</td>
<td><input type="checkbox"></td>
</tr>
<tr class="utr">
<td class="utd">
<input type="text" value="123 Main Street" style="width:200px">
</td>
<td class="utd"><select>
<option value="1">Listings</option>
<option value="2">Solds</option>
</select></td>
<td class="utd"><input type="checkbox" checked="checked"></td>
</tr>
<tr>
<td>666 Oceanview Rd.</td>
<td>Listings</td>
<td><input type="checkbox" checked="checked"></td>
</tr>
</tbody>
</table>
Here's my Fiddle: https://jsfiddle.net/ImTalkingCode/k1pcc1nh/4/
In the fiddle, both the content label (eg. First) and the input fields are padded over by the 30% and are not aligned at all like the css-tricks example. Any help?
Screenshot with the bug
Based on the code from css tricks that you offered, I simply added the classes that we needed.
Resize your screen/browser to see the effect you wanted.
Generic Styling, for Desktops/Laptops
*/
table {
width: 100%;
border-collapse: collapse;
}
/* Zebra striping */
tr:nth-of-type(odd) {
background: #eee;
}
th {
background: #333;
color: white;
font-weight: bold;
}
td, th {
padding: 6px;
border: 1px solid #ccc;
text-align: left;
}
#media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
/* Hide table headers (but not display: none;, for accessibility) */
tr.utr { border: 1px solid #ccc;
display: flex;
flex-direction: column;}
td.utd {
/* Behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 30%;
}
td.utd:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
}
/*
Label the data
*/
td.utd:nth-of-type(1):before { content: "First"; }
td.utd:nth-of-type(2):before { content: "Second"; }
td.utd:nth-of-type(3):before { content: "Third"; }
}
<table>
<thead>
<tr>
<th>Address</th>
<th>Status</th>
<th>Query</th>
</tr>
</thead>
<tbody>
<tr>
<td>100 Central Ave.</td>
<td>Listings</td>
<td><input type="checkbox"></td>
</tr>
<tr class="utr">
<td class="utd">
<input type="text" value="123 Main Street" style="width:100%">
</td>
<td class="utd"><select>
<option value="1">Listings</option>
<option value="2">Solds</option>
</select></td>
<td class="utd"><input type="checkbox" checked="checked"></td>
</tr>
<tr>
<td>666 Oceanview Rd.</td>
<td>Listings</td>
<td><input type="checkbox" checked="checked"></td>
</tr>
</tbody>
</table>
If you don't want it to be responsive, just delete the #media query.
I think this will help you
https://jsfiddle.net/31rg4ued/.
If you adjust the width of input element based on the padding, you will get the expected output
tr.utr {
display: block;
border: 1px solid #ccc;
}
td.utd {
display: block;
border: none;
border-bottom: 1px solid #eee;
position: relative;
}
td.utd:before {
}
td.utd:nth-of-type(1):before {
content: "First";
}
td.utd:nth-of-type(2):before {
content: "Second";
}
td.utd:nth-of-type(3):before {
content: "Third";
}
<table>
<thead>
<tr>
<th>Address</th>
<th>Status</th>
<th>Query</th>
</tr>
</thead>
<tbody>
<tr>
<td>100 Central Ave.</td>
<td>Listings</td>
<td><input type="checkbox"></td>
</tr>
<tr class="utr" style="padding-left:30%">
<td class="utd">
<input type="text" value="123 Main Street" style="width:calc(100% - 30%)">
</td>
<td class="utd"><select>
<option value="1">Listings</option>
<option value="2">Solds</option>
</select></td>
<td class="utd"><input type="checkbox" checked="checked"></td>
</tr>
<tr>
<td>666 Oceanview Rd.</td>
<td>Listings</td>
<td><input type="checkbox" checked="checked"></td>
</tr>
</tbody>
</table>
Related
As you can see in the code snippet, the height of the table rows is slightly different depending on the height of the images.
I have the image tag set to height: auto; and if I change this to say 300px, the images they all get the same size, but it's not what I want because I still want to keep the aspect ratio.
table {
display: table;
table-layout: fixed;
width: 100%;
margin-bottom: 4rem;
border: 1px solid #c4c4c4;
border-collapse: collapse;
font-size: 1rem;
}
thead {
background: #fbfbfb;
border: 1px solid #c4c4c4;
}
th,
td {
height: 5rem;
padding: 1rem;
}
th {
text-align: start;
background: #fbfbfb;
}
td {
background: #fff;
}
tr {
border: 1px solid #c4c4c4;
}
.read-more {
color: #fff;
background: #005c68;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: 500;
padding: 1rem;
}
.price {
font-weight: 700;
}
img {
width: 100%;
max-width: 7em;
height: auto;
}
#media screen and (max-width: 1225px) and (min-width: 1045px) {
.priority-5 {
display: none;
}
}
#media screen and (max-width: 1045px) and (min-width: 835px) {
.priority-5 {
display: none;
}
.priority-4 {
display: none;
}
}
#media screen and (max-width: 835px) and (min-width: 300px) {
.priority-5 {
display: none;
}
.priority-4 {
display: none;
}
.priority-3 {
display: none;
}
}
#media screen and (max-width: 300px) {
.priority-5 {
display: none;
}
.priority-4 {
display: none;
}
.priority-3 {
display: none;
}
.priority-2 {
display: none;
}
}
<table>
<thead>
<tr>
<th className="priority-1">Operatör</th>
<th className="priority-2">Surfmängd</th>
<th className="priority-3">Bindningstid</th>
<th className="priority-4">Samtal</th>
<th className="priority-5">Sms</th>
<th className="priority-6">Pris</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td className="priority-1">
<img src=https://www.telia.se/.resources/discover/resources/imgs/logo236x200.png alt=logo />
</td>
<td className="priority-2">124 GB</td>
<td className="priority-3">24 mån</td>
<td className="priority-4">
Fria
</td>
<td className="priority-5">
Fria
</td>
<td className="priority-6 price">99 kr</td>
<td>
<button className="read-more" type="button">
Läs mer
</button>
</td>
</tr>
<tr>
<td className="priority-1">
<img src=https://1.bp.blogspot.com/-f39w3NL2fYM/UJrk7keg5ZI/AAAAAAAAPTM/dGo3uETNoD4/s1600/Comviq+logo+2012.png alt=logo />
</td>
<td className="priority-2">124 GB</td>
<td className="priority-3">24 mån</td>
<td className="priority-4">
Fria
</td>
<td className="priority-5">
Fria
</td>
<td className="priority-6 price">99 kr</td>
<td>
<button className="read-more" type="button">
Läs mer
</button>
</td>
</tr>
<tr>
<td className="priority-1">
<img src=https://www.telia.se/.resources/discover/resources/imgs/logo236x200.png alt=logo />
</td>
<td className="priority-2">124 GB</td>
<td className="priority-3">24 mån</td>
<td className="priority-4">
Fria
</td>
<td className="priority-5">
Fria
</td>
<td className="priority-6 price">99 kr</td>
<td>
<button className="read-more" type="button">
Läs mer
</button>
</td>
</tr>
<tr>
<td className="priority-1">
<img src=https://1.bp.blogspot.com/-f39w3NL2fYM/UJrk7keg5ZI/AAAAAAAAPTM/dGo3uETNoD4/s1600/Comviq+logo+2012.png alt=logo />
</td>
<td className="priority-2">124 GB</td>
<td className="priority-3">24 mån</td>
<td className="priority-4">
Fria
</td>
<td className="priority-5">
Fria
</td>
<td className="priority-6 price">99 kr</td>
<td>
<button className="read-more" type="button">
Läs mer
</button>
</td>
</tr>
</tbody>
</table>
Let me suggest a few options:
You could specify the aspect ratio manually, if you know what you need, using css aspect-ratio property. Then specify whatever height you need so that it fits in the table row.
You could mention the height and width, and let the image content be adjusted accordingly, using the object-fit. This could somewhat obscure the contents, so you should take it with a pinch of salt.
You could mention the max-height property for the image, along with a width=auto, so that it scales down to the required size.
There are many ways to do this, you can specify the height of the parent element.
.container {
border: 1px solid red; /* Just to visualize the parent element*/
height: 150px; /* The container height it's lower than the child */
margin: 5rem 0; /* Just some space between the containers */
}
<!-- With overflow-y visible (by default) -->
<div class="container"> <!-- style="overflow-y:visible" -->
<img src="http://via.placeholder.com/200x200"/>
</div>
<!-- With overflow-y hidden -->
<div class="container" style="overflow-y:hidden">
<img src="http://via.placeholder.com/200x200"/>
</div>
Once it's "overflowed" you ajust the image as you want.
I am using this codes below to Add data into my web :
//Codes//
.AddData input {
font-size: 15px;
padding: 2.5px;
margin-bottom: 15px;
}
.AddData [type='text'] {
font-weight: bold;
font-size: 18px:
margin-bottom: 6px;
}
.AddData button {
transform: translate(120%,-50%);
outline: 1px solid black;
width: 80px;
height: 40px;
font-size: 16px;
background: #ff267e;
display: block;
cursor: pointer;
color: #fff;
border: none;
}
.AddData tr {
margin-bottom: auto;
}
Below is my html codes i used for my website.
//Html//
<link rel="stylesheet" type="text/css" href="web.css">
<body>
<div class ="AddData">
<form action="add.php" method="POST" name="form1">
<table width="25%" border="0">
<tr>
<td>User ID: </td>
<td><input type="text" name="User_id" required autocomplete="off"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="Password" required autocomplete="off"></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="password" name="CPass" required autocomplete="off" ></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Add"></td>
</tr>
</table>
This is what it shows on my website i just need the 'User_id' to be inline as the input box.
https://i.stack.imgur.com/yBPEW.png
You have to use padding instead of margin to add space inside a td. I left some commented code for you to check what styles I removed from your code.
There will be some issues you'll have to fix like the difference in font size.
.AddData input {
font-size: 15px;
padding: 2.5px;
/* margin-bottom: 15px; */
}
.AddData [type='text'] {
font-weight: bold;
font-size: 18px; /*; was missing*/
/* margin-bottom: 6px; */
}
.AddData button {
transform: translate(120%,-50%);
outline: 1px solid black;
width: 80px;
height: 40px;
font-size: 16px;
background: #ff267e;
display: block;
cursor: pointer;
color: #fff;
border: none;
}
/* .AddData tr {
margin-bottom: 15px;
} */
.AddData td {
padding-bottom: 15px;
}
<body>
<div class ="AddData">
<form action="add.php" method="POST" name="form1">
<table width="25%" border="0">
<tr>
<td>User ID: </td>
<td><input type="text" name="User_id" required autocomplete="off"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="Password" required autocomplete="off"></td>
</tr>
<tr>
<td>Confirm Password:</td>
<td><input type="password" name="CPass" required autocomplete="off" ></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Add"></td>
</tr>
</table>
</form>
</div>
</body>
I am using Bootstrap now for creating the front-end of the website that I am working on, and Bootstrap is very nice and powerful. However, the default style and theme for the HTML table is not good that much. So is there any style or theme for it?
I was searching about it and found Bootswatch website. They have very nice free themes for the Bootstrap, However, those themes don't change the style of the table.
Twitter bootstrap table can be styled and well designed. However to make your table look beautiful and style , you need create your own css
You can follow this example
On your HTML
<table class="responsive-table responsive-table-input-matrix">
<tr>
<th>Role</th>
<th>Add to Page</th>
<th>Configure</th>
<th>View</th>
<th>Change Permissions</th>
</tr>
<tr>
<td data-th="Role">Guest</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
<tr>
<td data-th="Role">Noob</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
<tr>
<td data-th="Role">Moderator</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
<tr>
<td data-th="Role">Administrator</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
<tr>
<td data-th="Role">Owner</td>
<td data-th="Add to Page"><input type="checkbox" /></td>
<td data-th="Configure"><input type="checkbox" /></td>
<td data-th="View"><input type="checkbox" /></td>
<td data-th="Change Permissions"><input type="checkbox" /></td>
</tr>
</table>
Create own CSS
#import "compass/css3";
// More practical CSS...
// using mobile first method (IE8,7 requires respond.js polyfill https://github.com/scottjehl/Respond)
$breakpoint-alpha: 480px; // adjust to your needs
.responsive-table-input-matrix {
margin: 1em 0;
// min-width: 300px; // adjust to your needs
width: 100%;
#media (min-width: $breakpoint-alpha) {
.responsive-table-input-matrix {
width: auto;
}
}
tr {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
td {
text-align: left;
#media (min-width: $breakpoint-alpha) {
text-align: center;
}
}
& td:first-of-type {
text-align: left;
}
}
th {
display: none; // for accessibility, use a visually hidden method here instead! Thanks, reddit!
}
td {
display: block;
&:first-child {
padding-top: .5em;
}
&:last-child {
padding-bottom: .5em;
}
&:before {
content: attr(data-th)": "; // who knew you could do this? The internet, that's who.
font-weight: bold;
// optional stuff to make it look nicer
width: 9em; // magic number :( adjust according to your own content
display: inline-block;
// end options
#media (min-width: $breakpoint-alpha) {
display: none;
}
}
}
& th:first-of-type {
text-align: left;
}
th, td {
text-align: center;
#media (min-width: $breakpoint-alpha) {
display: table-cell;
padding: .25em .5em;
&:first-child {
padding-left: 0;
}
&:last-child {
padding-right: 0;
}
}
}
}
// presentational styling
#import 'http://fonts.googleapis.com/css?family=Montserrat:300,400,700';
body {
padding: 0 2em;
font-family: Montserrat, sans-serif;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
color: #444;
background: #eee;
}
h1 {
font-weight: normal;
letter-spacing: -1px;
color: #34495E;
}
.responsive-table {
background: #34495E;
color: #fff;
border-radius: .4em;
overflow: hidden;
tr {
border-color: lighten(#34495E, 10%);
}
th, td {
margin: .5em 1em;
#media (min-width: $breakpoint-alpha) {
padding: 1em !important;
}
}
th, td:before {
color: #dd5;
}
}
Hope you can learn something from this coding. :)
Bootstrap provides basic styling for tables with the .table class. There are other classes that can be added for additional, modest styling.
W3Schools article on Bootstrap tables
I have the following html which is generated by a web framework so I can't change it. I can however add my own CSS.
<table border="0" class="formlayout" role="presentation">
<tbody>
<tr>
<td align="right">Medical Aid Plan</td>
<td align="left"><input type="text"></td>
</tr>
<tr>
<td align="right">Adult Medical Aid Dependants</td>
<td align="left"><input type="text"></td>
<td align="right">Child Medical Aid Dependants</td>
<td align="left"><input type="text"></td>
</tr>
<tr>
<td align="right">Total Package</td>
<td align="left"><input type="text"></td>
</tr>
<tr>
<td align="right">Pensionable Earnings</td>
<td align="left"><input type="text"></td>
<td align="right">Pensionable Earnings Percentage</td>
<td align="left"><input type="text"></td>
</tr>
<tr>
<td align="right">Voluntary Contributions</td>
<td align="left"><input type="text"></td>
<td align="right">Voluntary Contributions Percentage</td>
<td align="left"><input type="text"></td>
</tr>
</tbody>
</table>
I would like to create sections in the form and draw blocks around these sections , complete with text section headings. In order to achieve this I was thinking of adding additional space between the table rows and then adding CSS pseudo elements for the text and section frames. How would one do this?
I would like to add the first 3 text inputs to Section 1 and the rest to Section 2.
I'm trying to achieve something like this:
It can be done. But it only works with a fixed width layout (unless you use mediaqueries) and I don't know about browser compatibility.
It would be easier to set some padding and a background image.
Here is a jsfiddle: http://jsfiddle.net/L7y5rz9j/
table.formlayout {
width: 730px;
}
table.formlayout td {
position: relative;
z-index: 2;
}
table.formlayout tr:nth-child(1) td {
padding-top: 1em;
}
table.formlayout tr:nth-child(3) td {
padding-top: 3em;
}
table.formlayout tr:nth-child(1):after, table.formlayout tr:nth-child(3):after {
content:"";
position: absolute;
left: 0;
width: 750px;
border: 1px solid;
}
table.formlayout tr:nth-child(1):after {
height: 5em;
}
table.formlayout tr:nth-child(3):after {
height: 6em;
margin-top: 2em;
}
table.formlayout tr:first-child td:first-child:after, table.formlayout tr:nth-child(3) td:first-child:after {
position: absolute;
z-index: 1;
width: 3em;
padding: 2px 5px;
margin-left: 7em;
background: white;
}
table.formlayout tr:first-child td:first-child:after {
content:"Step 1";
top: -9px;
}
table.formlayout tr:nth-child(3) td:first-child:after {
content:"Step 2";
top: 23px;
}
I am studying CSS and testing a simple drag and drop functionality which comes with HTML5.
The page I have prepared looks OK in Chrome and Opera but totally wrong in Firefox and IE 11. In IE 11 it is even not possible to drag elements from the rightmost table onto a caption Table A nor Table B.
Why is it so? How is the height for td element magically set to a high value in Firefox/IE and not in Chrome/Opera? Why does dropping not work in IE 11?
function drag(event) {
event.dataTransfer.setData("rowId", event.target.id);
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
var playerId = event.dataTransfer.getData("rowId");
var tableBody = event.target.parentNode.getElementsByTagName("tbody");
if (tableBody) {
tableBody[0].appendChild(document.getElementById(playerId));
}
}
.vbtn {
background: none repeat scroll 0 0 #fafaff;
border: 1px solid #ddd;
border-radius: 6px;
border-spacing: 0;
box-shadow: 1px 1px 1px #eee;
padding: 1px 8px;
text-shadow: 0 2px 5px rgba(120, 120, 120, 0.3);
vertical-align: baseline;
white-space: nowrap;
}
a {
color: #175bb0;
text-decoration: none;
}
#wrapper {
width: 100%;
overflow: hidden;
}
#section-b {
position: relative;
margin-left: 10px;
width: 300px;
height: 400px;
float: left;
overflow: auto;
}
#section-a {
width: 235px;
float: left;
}
#selector {
margin-top: 10px;
margin-left: 10px;
float: left;
}
table {
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
width: 100%;
border: 1px solid black;
}
th,
td {
width: 100%;
border: none;
}
thead {
background: lightgreen;
}
thead>tr {
position: relative;
}
tbody {
height: 400px;
background: none;
overflow: auto;
}
<!DOCTYPE html>
<head>
<title>Table scroll</title>
<meta charset="UTF-8" />
</head>
<body>
<div id="wrapper">
<div id="header">
<p>Header...</p>
</div>
<div id="section-a">
<table id="table-a">
<caption ondrop="drop(event)" ondragover="allowDrop(event)">Table A</caption>
<thead>
<tr>
<th>Attribute 1</th>
<th>Attribute 2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<table id="table-b">
<caption ondrop="drop(event)" ondragover="allowDrop(event)">Table B</caption>
<thead>
<tr>
<th>Attribute 1</th>
<th>Attribute 2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div id="selector">
<select>
<optgroup label="A">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
<option value="4">D</option>
</optgroup>
<optgroup label="B">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</optgroup>
</select>
</div>
<div id="section-b">
<table id="section-b-list">
<thead>
<tr>
<th>Attribute 1</th>
<th>Attribute 2</th>
</tr>
</thead>
<tbody>
<tr draggable="true" id="10" ondragstart="drag(event)">
<td>Value 1
</td>
<td>Value 2</td>
</tr>
<tr draggable="true" id="11" ondragstart="drag(event)">
<td>Value 3
</td>
<td>Value 4</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
This line should be removed:
tbody {
height: 400px;
}
The problem is
tbody {
height: 400px;
}
Try to remove it from your code and you'll see.
The problem with dragging and dropping in IE 11 was because the page was loaded from a local file! When I uploaded the file to a remote http server and accessed the file from there, the problem disappeared!