Bootstrap row into td overflows - html

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.

Related

tbody is not filling up the width of the table but the content

HTML:
<body class="header">
<div class="container-fluid">
<div class="container d-flex justify-content-center">
<p class="display-3">Password Vault</p>
</div>
</div>
<div class="">
<div class="d-flex justify-content-center align-items-center" style="height: 800px;">
<div class="container border t-box col-5">
<table class="table table-hover t-responsive" >
<tbody>
<tr>
<td>
Lorem ipsum dolor sit amet cons
</td>
<td class="d-flex justify-content-center">
<button type="button" class="btn btn-outline-light btn-sm">View</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
CSS:
.t-transparent{
background-color: transparent;
}
.half-opaque{
opacity: 50%;
}
.nav-t{
height: 70px;
}
.t-box{
border-radius: 10px;
padding: 10px;
}
.t-responsive{
display: block;
max-height: 300px;
overflow-y: scroll;
}
tr{
max-width: 778px;
}
I am using bootstrap 5, the issue is that in bootstrap's table class, there are lines under each row. But in this case the lines are dependent on the tbody, which wraps the content responsively. How do i fix this?
Why are you setting disaply:block to the <table> element?
.t-responsive{
display: block; // remove this
max-height: 300px;
overflow-y: scroll;
}
It is causing table to take full width of the viewport.
If you want <table> to take full width as of parent container then set width:100%, etc.

Why did my CSS widths suddenly stop working properly?

Originally, the code worked as planned. The status bars were meant to fill the entire cell and sit right next to the green square. The green box will eventually be a character portrait picture. I tried to round the edges of the green square and as soon as I did, the status bars jumped over and became shorter than the previous 400px. I deleted the border-radius from the green square css, but the status bars didn't go back to their original size/position...
...any ideas?
.header {
width: 100%;
margin: 0 auto;
text-align: center;
}
.w3-light-grey w3-round-xlarge {
width: 700px;
}
#chad {
height: 100px;
width: 100px;
background-color: green;
}
iframe {
height: 300px;
width: 504px;
border: none;
}
.button-col {
width: 252px;
}
<table align="center">
<tr>
<td align="right" colspan="2">
Welcome back, <?=$_SESSION['name']?>!
<i class="fas fa-user-circle"></i>Profile |
<i class="fas fa-sign-out-alt"></i>Logout
</td>
</tr>
<tr>
<td rowspan="3">
<div id="chad"></div>
</td>
<td>
<div class="w3-light-grey w3-round-xlarge">
<div id="hp" class="w3-container w3-round-xlarge w3-red" style="width:100">100/100</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="w3-light-grey w3-round-xlarge">
<div id="mp" class="w3-container w3-round-xlarge w3-blue" style="width:100">100/100</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="w3-light-grey w3-round-xlarge">
<div id="xp" class="w3-container w3-round-xlarge w3-yellow" style="width:100">100/100</div>
</div>
</td>
</tr>
Well...I feel silly...
just added units to the inline styles and the problem was fixed.

Make table content center but align left

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>

Image 100% height error inside table in Chrome and Safari

I tried pretty hard to find the answer to this on here, on google, and elsewhere, but it seems pretty obscure. I had to do some fancy CSS in order to create a box with a specific aspect ratio inside which a thumbnail would be centered vertically and horizontally. Those are straight-forward ideas that are actually somewhat complicated to implement in CSS. My solution works great everywhere except inside a table in Chrome with an image that has dimensions larger than the container.
Here is code that demonstrates the issue:
/*
sets aspect ratio of container by adding padding that is calculated
according to width of its parent element
*/
.aspect-ratio {
width: 100%;
display: inline-block;
position: relative;
}
.aspect-ratio:after {
padding-top: 76.19%;
display: block;
content: '';
}
/*
parent has no height, this fills the container's space
*/
.fill-container {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
font-size: 0;
}
/*
centers image horizontally and vertically
background color
*/
.image-background {
text-align: center;
background-color: #444;
height: 100%;
width: 100%;
}
.image-background::before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -0.25em;
}
img {
display: inline-block;
padding: 5px;
box-sizing: border-box;
vertical-align: middle;
}
/*
Firefox: image height fills the parent element
Chrome:
inside table - image is rendered at its natural height
outside table - image height fills the parent element as expected
*/
.fill-height {
height: 100%;
}
.fill-width {
width: 100%;
}
/* other styles */
h1, h2, h3 {
text-align: center;
}
table {
width: 100%;
}
.thumbnail-viewer {
width: 40%;
margin: 10px auto;
}
<h1>tall image</h1>
<h2>small</h2>
<h3>table</h3>
<table>
<tbody>
<tr>
<td>
<div class="thumbnail-viewer">
<div class="aspect-ratio">
<div class="fill-container">
<div class="image-background">
<img class="fill-height" src="http://www.irmaagro.com/images/d.jpg" style="height: 100%;">
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<h3>no table</h3>
<div class="thumbnail-viewer">
<div class="aspect-ratio">
<div class="fill-container">
<div class="image-background">
<img class="fill-height" src="http://www.irmaagro.com/images/d.jpg" style="height: 100%;">
</div>
</div>
</div>
</div>
<h2>large</h2>
<h3>table (works in firefox and IE, breaks in chrome and safari)</h3>
<table>
<tbody>
<tr>
<td>
<div class="thumbnail-viewer">
<div class="aspect-ratio">
<div class="fill-container">
<div class="image-background">
<img class="fill-height" src="http://www.landscapeontario.com/thumbnailer.php?image=/assets/1320240573.Twine_wrap_2.JPG&imgWH=500" style="height: 100%;">
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<h3>no table</h3>
<div class="thumbnail-viewer">
<div class="aspect-ratio">
<div class="fill-container">
<div class="image-background">
<img class="fill-height" src="http://www.landscapeontario.com/thumbnailer.php?image=/assets/1320240573.Twine_wrap_2.JPG&imgWH=500" style="height: 100%;">
</div>
</div>
</div>
</div>
<h1>wide image</h1>
<h2>small</h2>
<h3>table</h3>
<table>
<tbody>
<tr>
<td>
<div class="thumbnail-viewer">
<div class="aspect-ratio">
<div class="fill-container">
<div class="image-background">
<img class="fill-width" src="http://www.beach.com/images/activity-photo-county-londonderry-ireland-3-day-lake-district-and-hadrian-s-wall-small-group-tour-from-edinburgh-1.jpg">
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<h3>no table</h3>
<div class="thumbnail-viewer">
<div class="aspect-ratio">
<div class="fill-container">
<div class="image-background">
<img class="fill-width" src="http://www.beach.com/images/activity-photo-county-londonderry-ireland-3-day-lake-district-and-hadrian-s-wall-small-group-tour-from-edinburgh-1.jpg">
</div>
</div>
</div>
</div>
<h2>large</h2>
<h3>table</h3>
<table>
<tbody>
<tr>
<td>
<div class="thumbnail-viewer">
<div class="aspect-ratio">
<div class="fill-container">
<div class="image-background">
<img class="fill-width" src="http://www.craterlaketrust.org/pub/photo/thumb/Crater-Summer_cropto_500x200.JPG">
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<h3>no table</h3>
<div class="thumbnail-viewer">
<div class="aspect-ratio">
<div class="fill-container">
<div class="image-background">
<img class="fill-width" src="http://www.craterlaketrust.org/pub/photo/thumb/Crater-Summer_cropto_500x200.JPG">
</div>
</div>
</div>
</div>
Hopefully as you can see, in Chrome (I'm using 43.0.2357.132 64-bit) and Safari (8.0.7) the tall/large image is exceeding the boundaries of its parent and its height is being set to the natural height of the image. The wide images all work as expected, so this appears to only be an issue of height.
My question: What is a simple or straight-forward way to fix this issue in Chrome and Safari? Or is it a bug and should I look for a less-than-ideal work-around that makes it look less terrible? What is causing this issue?
Thanks!
FYI, on smaller screens (screenwidth < 650px), your first image inside the table breaks as well.
To fix it, change your img to use the absolute positioning centering trick:
img {
padding: 5px;
box-sizing: border-box;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
This also means you don't need the image-background::before declaration.
Why do you need .fill-container to have absolute positioning? If I remove the lines below from styles then everything looks fine in Chrome (I can't test in Safari):
.fill-container {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
font-size: 0;
}
You also haven't closed img tags, you have
<img class="fill-height" src="http://www.irmaagro.com/images/d.jpg" style="height: 100%;">
instead of (notice /> at the end of line)
<img class="fill-height" src="http://www.irmaagro.com/images/d.jpg" style="height: 100%;" />

center table within div

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