Is there any theme or style for Bootstrap Table? - css

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

Related

How do I make table row have the same height and not depend on the size of the images?

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.

Why isn't my 'Text' in my css isn't inline with my input i cant figure this out

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>

Padding-left not working

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>

Draw blocks around form elements and add headings using CSS pseudo elements

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;
}

CSS Float fails for HTML5 Input Elements

I'm running into an issue when using HTML5 form input types (number, date, email, etc) with the CSS float property. I'm trying to float these to the right, but they are not honoring that setting.
Here's a snippit where I put the CSS inline during testing:
<div class="center" style="width: 100%">
...
<div style="width: 90%" class="textfont">
...
<table style="width:100%;">
<thead>
<tr class="tableHeading">
<td style="width: 50%; text-align: center;">
Unit Types
</td>
<td style="text-align: center;">
Number of Units
</td>
</tr>
</thead>
<tbody>
<tr>
<td style="border-right: 1px;">
Single-Family Detached
</td>
<td>
<input type="number" name="txtDetached" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td style="height: 32px">
Townhouse, Row, or Cluster
</td>
<td style="height: 32px">
<input type="number" name="txtCuster" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td>
Garden
</td>
<td>
<input type="number" name="txtGarden" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td style="height: 43px">
Mid-rise (3-5)
</td>
<td style="height: 43px">
<input type="number" name="txtMidrise" style="width:25%; float:right" />
</td>
</tr>
<tr>
<td>
High-rise (6+)
</td>
<td>
<input type="number" name="txtHighRide" style="width:25%; float: right" />
</td>
</tr>
<tr>
<td>
Other
</td>
<td>
<input type="text" name="txtOther" style="width: 80%; float: right;" />
</td>
</tr>
</tbody>
</table>
...
</div>
...
</div>
Yes, I know tables are frowned upon...
Here's the overall CSS:
.Header
{
font-size: 30px;
font-family: Cambria;
color: White;
background: #254117;
text-align: center;
font-weight: bold;
width: 90%;
}
.subHeading
{
font-family: Arial;
font-size: 11px;
text-align: left;
}
.container
{
display: table;
width: 90%;
border-collapse: collapse;
}
.heading
{
font-weight: bold;
display: table-row;
background-color: #C91622;
text-align: center;
line-height: 25px;
font-size: 14px;
font-family: georgia;
color: #fff;
}
.table-row
{
display: table-row;
text-align: center;
}
.col
{
display: table-cell;
border: 1px solid #CCC;
}
.tableHeading
{
font-family: Arial;
background: #99C68E;
font-size: 18px;
text-align: left;
}
.textfont
{
font-size: 15px;
font-family: Arial;
text-align: left;
}
input[type=text]
{
width: 100%;
height: 22px;
}
textarea
{
width: 98%;
}
table
{
border-collapse: collapse;
border: 1px solid black;
border-spacing: 10px;
}
tr
{
border-collapse: collapse;
border: 1px solid black;
}
td, th
{
padding: 5px;
}
.center
{
margin-left: auto;
margin-right: auto;
}
Here's what this displays:
As you can see the input element with type="text" works without an issue, however when type="number" it remains at the default, left justified.
This behavior exists in IE 10, FireFox, and Chrome.
I discovered the workaround is to wrap the HTML5 input types in a div and then set the CSS to float the div right, and then this works without issue. I had issues finding information for this on the net, but is this a known issue? Is the workaround actually the proper way of handling this?
EDIT: Added full CSS (minus stuff I moved inline for testing). Added entire table and the div's they are wrapped in. If I copy all of this to jsFiddle it works properly, so I'm obviously doing something wrong here...
OK, the problem related to floating elements inside <td>, use text-align can fix it.
<td style="text-align:right;">
...
</td>
More can be read here DIV in <td> float right

Resources