I want to use table to do a legend for a chart. I created an example to show the problem.
https://jsfiddle.net/s3mf64gq
<div class="container">
<div class="row">
<div class="panel col-md-12">
<table class="table borderless">
<tbody>
<tr>
<td>
Jane - Software Engineer
</td>
<td>
John - Senior Marketing Executive
</td>
</tr>
<tr>
<td>
Teddy - CEO
</td>
<td>
James - Lecturer
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
I have 2 requirements:
all of the item must be align to the left
the container must be center to the parent
How to solve it? I'm stuck.
The challenge is the length of the items is not equal, otherwise I would simply do text-align center on the td then it's solved.
Since the .table class has a predefined width of 100%, you need to set it to auto so the <table> will be sized by its content.
Then by adding margin: 0 auto it will center horizontally.
.table {
margin: 0 auto; /* horizontally center */
width: auto; /* reset the built in value of 100% */
}
Updated fiddle
Stack snippet
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<style>
/* Latest compiled and minified CSS included as External Resource*/
/* Optional theme */
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
padding: 0;
}
.panel {
background: #eee;
}
.borderless td,
.borderless th {
border: none !important;
}
.table {
margin: 0 auto;
width: auto;
}
</style>
<div class="container">
<div class="row">
<div class="panel col-md-12">
<table class="table borderless">
<tbody>
<tr>
<td>
Jane - Software Engineer
</td>
<td>
John - Senior Marketing Executive
</td>
</tr>
<tr>
<td>
Teddy - CEO
</td>
<td>
James - Lecturer
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Related
I have two rows inside of a container table. Row 1, and Row 2.
I have a simple two column layout, using tables, where each row has two columns.
As an aside, the columns are implemented differently, and the media queries that would allow the columns in row 1 to stack have been removed.
So, 2 rows each with two columns.
Row 1 is my problem row. Row 2 is my stacking row.
The columns on row 2 only, should stack on smaller screens.
The tables in row 2 are declared as inline-block so they can sit next to each other.
Under certain conditions, the tables in row 2 refuse to stack on narrower screens. I narrowed it down to the padding on two table data tags inside of Row 1, my problem row.
When the two table data tags in the problem row have a combined padding of 27px or below, the nested tables in the stacking row (row 2) will stack on small screens (and specifically at a width of 604 pixels).
However if I change the padding on the two table data tags to a combined padding of 28px or more, the tables in the stacking row will no longer stack on small screens.
<body>
<center style="width: 100%;">
<div style="max-width: 650px;">
<table style="width: 100%;">
<!--Begin Problem Row-->
<tr>
<td>
<table style="width: 100%;">
<tr>
<!-- problem cell 1:
When problem cell 1 and problem cell 2 have a combined padding of greater than or equal to 28px, the tables in my "stacking row"
refuse to stack. Otherwise, they stack fine.
-->
<td style="padding: 13px; width: 50%">
<table>
<tr>
<td style="text-align: center;">
<p>Title</p>
<img src="https://via.placeholder.com/275x200" alt="" width="275">
<p>Random Text</p>
</td>
</tr>
</table>
</td>
<!-- problem cell 2:
When problem cell 1 and problem cell 2 have a combined padding of greater than or equal to 28px, the tables in my "stacking row"
refuse to stack. Otherwise, they stack fine.
-->
<td style="padding: 15px; width: 50%">
<table>
<tr>
<td style="text-align: center;">
<p>Title</p>
<img src="https://via.placeholder.com/275x200" alt="" width="275">
<p>Random Text</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<!--Begin stacking row-->
<tr>
<td>
<table width="100%;">
<tr>
<td style="text-align: center;">
<!--These tables should stack -->
<table style="display: inline-block; width: 100%; vertical-align: top; max-width: 300px;">
<tr>
<td>
<table >
<tr>
<td>
<img src="https://via.placeholder.com/275x200" alt="" width="275">
</td>
</tr>
<tr>
<td>
<p>Title</p>
</td>
</tr>
<tr>
<td>
<p>This is a description of a product that you can use to describe the products that you need to describe</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--These tables should stack -->
<table style="display: inline-block; width: 100%; vertical-align: top; max-width: 300px;">
<tr>
<td>
<table >
<tr>
<td>
<img src="https://via.placeholder.com/275x200" alt="" width="275">
</td>
</tr>
<tr>
<td>
<p>Title</p>
</td>
</tr>
<tr>
<td>
<p>This is a description of a product that you can use to describe the products that you need to describe</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</center>
</body>
In my internal stylesheet, the padding on all td's is set to 0 and the border spacing on all tables is set to 0.
I've included my entire stylesheet since it's fairly small.
/* General Resets
The following resets will eliminate all default margin, padding and border for all
clients. The capital M in Margin on the body reset is recommended for Outlook. Also, we will give
the area outside our email frame a neutral background color.
*/
body, .body {
Margin: 0;
padding: 0;
background-color: #f6f9fc;
}
.backHover:hover{
background-color: #ffffff !important;
}
table {
border-spacing: 0;
background-color: black;
}
.centering {
width: 100%;
table-layout: fixed;
background-color: #f6f9fc;
padding-bottom: 40px;
}
td {
padding: 0;
background-color: aqua;
}
img {
border: 0;
}
p {
margin: 0;
}
a {
text-decoration: none;
}
table, td, div, h1, p {font-family: Arial, sans-serif;}
</style>
I don't know why this behavior is happening.
The problem stems from the max-width: 300px on your second row. Your initial row is adding up to 606px in width ((275 * 2) + (13 * 2) + (15 * 2)) while the max width of the second row is 600px (300 + 300) so it won't ever stack.
I'm not sure what your intended finished email is supposed to look like, but there's some alignment issues between the images in the two columns. I would start using a framework (like DML or Foundation for Eamils) or a pre-built template and modify that. That way you're not debugging email client issues on top of manually aligning tables.
I need to insert into a table cell (TD) a bootstrap panel, like this:
<tr>
<td>
......Here the panel......
</td>
</tr>
The panel can stays over others divs (like calendar appointment). To do it, I declared the table with relative position and the note with absolute position.
It works if I insert the panel directly into the TD element, like this:
https://jsfiddle.net/0kktvptj/
But if I insert it into Bootstrap grid class as row and col-sm-12, the panel overflows 30px on the right, like this: http://jsfiddle.net/r0L71dbv/.
I don't understand why it happens and how can I resolve the problem.
I'm not sure I understand what you want. Anyway, tables have problems with position:relative. When you want to use it on a td, make a div inside the td with width: 100%;height:100%;position:relative; and it works.
Is this what you wanted?
.note {
width: 100%;
float: left;
}
table.table-bordered.calendario td {
padding: 0;
width: 33.33%;
height: 50px;
}
table.table-bordered.calendario td .row {
display: inline-block;
max-height: 45px;
width: calc(100% + 30px);
position: relative;
}
td .row .panel {
border-radius: 0 0 4px 4px;
}
td .row .panel-heading {
border-radius: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<table class="table table-bordered calendario" style="margin-top: 20px;">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<div class="row">
<div class="col-sm-12">
<div class="panel panel-success note">
<div class="panel-heading">Titolo</div>
<div class="panel-body">
Austin next level tilde, pug mlkshk actually helvetica banjo truffaut
sartorial drinking vinegar mumblecore kogi. Franzen microdosing vegan,
kale chips chillwave cliche beard.</div>
</div>
</div>
</div>
</td>
<td></td>
</tr>
</table>
A row should always be a child of a container or a column. The Bootstrap team make this clear in the docs. Define your layout structure, then drop in the content.
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<table class="table table-bordered calendario" style="margin-top: 20px;">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<div class="panel panel-success note " style="height: 50px; overflow: scroll; overflow-x: hidden;">
<div class="panel-heading">Titolo</div>
<div class="panel-body" style="overflow: hidden">Corpo del testo</div>
</div>
</td>
<td></td>
</tr>
</table>
</div>
</div>
</div>
Demo
I applied this solution: https://jsfiddle.net/rr6ju1no/1/
table.table-bordered.calendario td
{
padding: 0;
height: 50px;
position: relative;
}
table.table-bordered.calendario td .row
{
width: 100%;
}
table.table-bordered.calendario td .panel
{
overflow: scroll;
overflow-x: hidden;
border-radius: 0 0 4px 4px;
}
td .row .panel-heading {
border-radius: 1px;
}
.note
{
position:absolute;
width:100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-bordered calendario" style="margin-top: 20px;">
<tr><td></td><td></td><td></td></tr>
<tr>
<td></td>
<td>
<div class="row">
<div class="col-sm-12">
<div class="panel panel-success note " style="height: 50px;">
<div class="panel-heading">Titolo</div>
<div class="panel-body">Corpo del testo</div>
</div>
</div>
</div>
</td>
<td></td>
</tr>
</table>
When you resize the browser, columns maintain the same width better.
I have a table within a div using the span12 class from twitter bootstrap which is contained within a row class div all surrounded by a footer tag as follows:
<footer class="footer">
<div class="row">
<div class="span12">
<table>
<tr>
<td> <!-- Contact Us -->
<table>
<tr>
<td><b>Contact Us</b></td>
</tr>
<tr>
<td>Tel: 01234 567897</td>
</tr>
<tr>
<td>E-mail: info#email.com</td>
</tr>
</table>
</td>
<td> <!-- Useful Links -->
<table>
<tr>
<td><b>Useful Links</b></td>
</tr>
<tr>
<td>Contact Us</td>
</tr>
<tr>
<td>About Us</td>
</tr>
<tr>
<td>Copyright Information</td>
</tr>
<tr>
<td>Terms & Conditions</td>
</tr>
</table>
</td>
<td> <!-- Social -->
<table>
<tr>
<td><b>Connect With Us</b></td>
</tr>
<tr>
<td>Facebook</td>
</tr>
<tr>
<td>Twitter</td>
</tr>
<tr>
<td>Google Plus</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</footer>
I have the following CSS applied:
/* Table Style */
.footer table {
table-layout:fixed;
margin-right: auto;
margin-left: auto;
width: 100%
}
.footer td b {
vertical-align:top;
color: #ccc2a0;
}
.footer td {
vertical-align:top;
color: #a8a8a8;
}
I have tried to get the space between the left side of the footer and the first table data to be the same as the space between the right side of the footer and the last table data however it always has a bigger gap on the right side.
Can anyone see a problem with the CSS I am using?
Thanks
EDIT:
Here is the code for trying to achieve this using divs:
<footer class="footer">
<div class="row" style="background-color:red;">
<div class="span12" style="background-color:orange;">
<div class="span4" id="leftFooter">
</div>
<div class="span4" id="middleFooter">
</div>
<div class="span4" id="rightFooter">
</div>
</div>
</div>
</footer>
The CSS simply colours the boxes so I can see what is going on and adds some height to the divs.
The grey box is the footer div, the red box is the row and the orange box is the span12. The rest are the 3 content divs of span4. Not sure why they don't stay on the same row.
I changed some of it and stripped all styling out (sorry), but your spacing should be fixed horizontally. You can apply whatever else you want styling wise. Also, I got rid of all the embedded tables because it was so cumbersome...I can adjust the vertical spacing if you want, but I just threw this together to give you an idea for horizontal spacing.
http://jsfiddle.net/YYZwY/1/
HTML:
<footer class="footer">
<table>
<td>
<div id="ContactUS" class="information">Contact Us</div>
<div id="Telephone" class="information">Tel: 01234 567897 </div>
<div id="email" class="information">Email: info#email.com</div>
</td>
<td>
<div class="links">Useful Links</div>
<div class="links">Contact Us</div>
<div class="links">About Us</div>
<div class="links">Copyright Information</div>
<div class="links">Terms & Conditions</div>
</td>
<td>
<div class="connect"><b>Connect With Us</b></div>
<div class="connect">Facebook</div>
<div class="connect">Twitter</div>
<div class="connect">Google Plus</div>
</td>
</footer>
CSS:
.links {
padding-left: 10px;
padding-right: 10px;
position: relative;
}
.connect {
padding-left: 10px;
padding-right: 10px;
position: relative;
}
.information {
padding-right: 10px;
}
CSS:
.span12 {
text-align: center;
}
This solution works if we don't mind the text alignment.
Result [CodePen] : http://codepen.io/loxaxs/pen/kilLG
A different solution:
CSS:
.span12 {
padding-left: 15%;
}
Result [CodePen] : http://codepen.io/loxaxs/pen/izIHq
Whats the best way to split up a table element <td>? I don't really want to use nested tables. I need the internal element to have two elements one that is left justified and the other to be right justified with no border.
For example:
<table>
<tr>
<td>LEFT, RIGHT</td>
</tr>
</table>
any other ways to do this besides the following?
<table>
<tr>
<td>LEFT</td>
<td>RIGHT</td>
</tr>
</table>
I want the internal element to be a <span> or whatever is best for this.
<table>
<tr>
<td>
<div style="float:left">LEFT</div><div style="float:right">RIGHT</div>
</td>
</tr>
</table>
I would do something like:
<td><div class="left>LEFT</div><div class="right">RIGHT</div></td>
then my css would resemble:
td{position: relative;}
td .left{position: absolute; text-align: left; left: 0;}
td .right{position: absolute; text-align: right; right: 0;}
... or something along those lines.
You could do it like this, although spans and divs are much better imo.
<table width="100%">
<tr width="100%">
<td width="100%">
<span style="float:left;">left</span>
<span style="float:right;">right</span>
</td>
</tr>
</table>
The floats didn't seem to look right so I used flexbox:
https://jsfiddle.net/6rc8w709/
.td-content{
display:flex;
}
.child{
flex:1;
}
.right{
text-align:right;
}
HTML:
<table>
<tr>
<td>
<div class="td-content">
<div class="child">
LEFT
</div>
<div class="child right">
RIGHT
</div>
</div>
</td>
</tr>
</table>
Flexbox is the right approach since it is now supported by all major browsers. This is an alternative approach if you need to target an older browsers or you don't like the drawbacks of floats. With this approach you can control the overflow of the left and right segment better and you can easily add a centered segment if you need one.
CSS:
table{
width: 100%;
}
.container{
width: 100%;
display: table;
}
.cell{
display: table-cell;
}
.cell .left{
text-align: left;
}
.cell.right{
text-align: right;
}
HTML:
<table>
<tr>
<td>
<div class="container">
<span class="cell left">LEFT</span>
<span class="cell right">RIGHT</span>
</div>
</td>
</tr>
</table>
I have a table with two columns. I want to center the right-most column with the page so the left column would hang off to the left.
<table width="960" border="0" cellpadding="0">
<tr>
<td width="100"><!--COLUMN TO HANG TO LEFT--></td>
<td><!--COLUMN TO BE CENTER WITH PAGE--></td>
</tr>
</table>
I'm assuming the solution will be CSS.
You are right - CSS is the way to go. Give the column an id or class that you can target and and in your CSS center it. Assuming your table width is where you want it, give it a width of your table subtracting the other column that is to the left.
Something like this:
HTML:
<table width="960" border="0" cellpadding="0">
<tr>
<td width="100"><!--COLUMN TO HANG TO LEFT--></td>
<td class="center"><!--COLUMN TO BE CENTER WITH PAGE--></td>
</tr>
</table>
CSS:
td.center {
text-align: center;
width: 860px;
}
Edit: Based on the comments below, here is a sample layout just using div's instead of a table
http://jsfiddle.net/willyrybone/8eR6G/
HTML:
<div id="page-wrap">
<div id="sidebar">
<p>this is some</p>
<p>sidebar content</p>
</div>
<div id="main-content">
<p>This is some</p>
<p>centered main content</p>
</div>
<div>
CSS:
#page-wrap {
width: 960px;
margin: auto;
}
#sidebar {
float:left;
width: 100px;
background: #eee;
}
#main-content {
text-align:center;
background:#bbb;
}
You'll have to wrap your table in a div, and center that:
<div style="width:1060px; margin: auto">
<table width="960" border="0" cellpadding="0">
<tr>
<td width="100">COLUMN TO HANG TO LEFT</td>
<td style="background: #ccc">COLUMN TO BE CENTER WITH PAGE</td>
</tr>
</table>
</div>
http://jsfiddle.net/9HgpM/embedded/result/