I have a table with cells that contain one image and one text link each, in that order. I have successfully vertically aligned the image with CSS:
.tdClass img {vertical-align:middle;}
But I can't seem to get the text link underneath it to align to the bottom of the cell. No matter what I've tried, it stays put right underneath the image. The ultimate goal here is to make the cells uniform horizontally as much as possible when my images are different heights.
<table width="100%" class="tableClass" id="tableId">
<tbody>
<tr>
<td class="tdClass">
<a href="#">
<img src="#">
</a>
<div class="divClass">
TEXT
</div>
</td>
<td class="tdClass">
<a href="#">
<img src="#">
</a>
<div class="divClass">
TEXT
</div>
</td>
</tr>
</tbody>
</table>
Consider adding a uniform height to the links around the images, enough to fit the tallest image.
.img {
height: 50px;
display: table-cell;
vertical-align: middle;
}
<table width="100%" class="tableClass" id="tableId">
<tbody>
<tr>
<td class="tdClass">
<a href="#" class="img">
<img src="http://placekitten.com/50/50">
</a>
<div class="divClass">
TEXT
</div>
</td>
<td class="tdClass">
<a href="#" class="img">
<img src="http://placekitten.com/30/30">
</a>
<div class="divClass">
TEXT
</div>
</td>
</tr>
</tbody>
</table>
add this :
td{
border: 1px solid red;
height: 350px;
}
td a:first-child,
td .divClass{
vertical-align: middle;
display: inline-block;
*display: inline; // ie7
*zoom: 1; //ie7
}
Related
My simple footer code uses table of width 100% containing a centered td with another table within it containing the links, this centres the links in the availble space. Its work fine as long as there is enough horizontal space for all the links, but if there isn't (i.e on mobile phone, portait) it does not wrap. How can I keep centred but allow wrapping as necessary ?
<footer>
<table style="width:100%">
<tr>
<td align="center">
<nav>
<table>
<tr>
<td>
<a href="/reports">
Reports
</a>
</td>
<td>
<a href="/preferences.go">
Preferences
</a>
</td>
<td>
<a href="/about.go">
About
</a>
</td>
<td>
<a href="/license.go">
License
</a>
</td>
<td>
<a href="/admin.go">
Admin
</a>
</td>
<td>
<a href="/webhelp/index_frames.html">
Help
</a>
</td>
</tr>
</table>
</nav>
</td>
</tr>
</table>
</footer>
Skip the table or just put the links all in a single td. They are inline and will wrap if necessary. Set text-align:center on the containing element to center the links.
footer nav {
text-align: center;
}
<footer>
<nav>
Reports
Preferences
About
License
Admin
Help
</nav>
</footer>
Here is a solution using Flex if the table markup is not required
.wrapper {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.flex-item {
margin: 0 10px;
}
<footer>
<div class="wrapper">
<a class="flex-item" href="/reports">
Reports
</a>
<a class="flex-item" href="/preferences.go">
Preferences
</a>
<a class="flex-item" href="/about.go">
About
</a>
<a class="flex-item" href="/license.go">
License
</a>
<a class="flex-item" href="/admin.go">
Admin
</a>
<a class="flex-item" href="/webhelp/index_frames.html">
Help
</a>
</div>
</footer>
I have used the answer provided below by:
https://stackoverflow.com/a/39417644/2079735
However this seems to add some padding to the bottom of the table row as shown here: https://www.bootply.com/8FKvHOv2S5
CSS
.table td.text {
max-width: 177px;
}
.table td.text span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
max-width: 100%;
}
display:inline-block on span causes white space to appear. Change it to display:block
/* CSS used here will be applied after bootstrap.css */
.table td.text {
max-width: 177px;
}
.table td.text span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
max-width: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2> Example no truncating</h2>
<div class="row">
<div class="col-md-10">
<table class="table table-striped table-bordered table-condensed">
<tbody>
<tr>
<td>
<span>
<a href="https://example.com">
Use Bootply to design, prototype, or test the Bootstrap framework. Find examples, share code and rapidly build interfaces for Bootstrap.
</a>
</span>
</td>
<td class="text-right">
28/04/2017 04:10:02
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h2> Example with truncating</h2>
<div class="row">
<div class="col-md-10">
<table class="table table-striped table-bordered table-condensed">
<tbody>
<tr>
<td class="text">
<span>
<a href="https://example.com">
Use Bootply to design, prototype, or test the Bootstrap framework. Find examples, share code and rapidly build interfaces for Bootstrap.
</a>
</span>
</td>
<td class="text-right">
28/04/2017 04:10:02
</td>
</tr>
</tbody>
</table>
</div>
</div>
I tried to reduce the height of bootstrap's progress bar but the issue is how can I make it in the center vertically same line as the text beside it. You can see the below sample with a reduced height progress bar that has a margin like or empty space below it.
.progress-num {
float: left;
margin-right: 1em;
}
.progress {
height: 0.5em !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table">
<tr>
<td>
<span class="progress-num">8/10</span>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%;">
<span class="sr-only"></span>
</div>
</div>
</td>
</tr>
</table>
Or just wrap the text and the bar in a containing element:
<table class="table">
<tr>
<td>
<div class="progress-stuff">
<span class="progress-num">8/10</span>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%;">
<span class="sr-only"></span>
</div>
</div>
</div>
</td>
</tr>
</table>
And the CSS (no need for magic numbers for margins):
.progress-stuff {
display: flex;
align-items: center; /* ensure all elements vertically aligned */
}
.progress-num {
margin-right: 1rem;
}
.progress {
flex: 1; /* ensure bar fills remaining horizontal space */
}
Just setting using margin-top
.progress-num {
float: left;
margin-right: 1em;
}
.progress {
height: 0.5em !important;
margin-top: 7px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table">
<tr>
<td>
<span class="progress-num">8/10</span>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%;">
<span class="sr-only"></span>
</div>
</div>
</td>
</tr>
</table>
You can also embed the text within the progress bar, in case you do not insist on having a height of 0.5em. Just remove the class sr-only from your inner span element and move the text 8/10 to that element. There is no need for adjusting the text then, because it will always be within the progress bar.
You can even omit the inner span completely, if you do not want to apply any additional styling. I kept it in my code snippet, because it keeps the code more structured:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table">
<tr>
<td>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%;">
<span>8/10</span>
</div>
</div>
</td>
</tr>
</table>
In ANY case, even if you keep your label outside of the progress bar, fill the <span class="sr-only"></span> with content, e.g. <span class="sr-only">8/10</span>. The sr-only stands for screenreader-only, i.e. visitors with visual impairments rely on the text within that element!
Even though you cannot see it on screen, other people need that information in order to tell, how far the action progressed.
I am trying make a horizontally scrollable div which has 3 sub-divisions inside. The sub-divisions have 4 image thumbnails inside them each. I am having trouble to get the this layout working.
HTML
<div class="col-xs-12">
<div class="canvas-scrollable">
<ul class="list-inline clearfix">
<li class="col-xs-12 col-sm-6 col-md-4">
<table class="item-inner">
<tr>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
</tr>
<tr>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
</tr>
</table>
</li>
<li class="col-xs-12 col-sm-6 col-md-4">
<table class="item-inner">
<tr>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
</tr>
<tr>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
</tr>
</table>
</li>
<li class="col-xs-12 col-sm-6 col-md-4">
<table class="item-inner">
<tr>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
</tr>
<tr>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
<td class="item-thumb">
<img class="img-responsive" src="images/#">
</td>
</tr>
</table>
</li>
</ul>
</div>
</div>
CSS
.canvas-scrollable{
width: 100%;
height: auto;
overflow-y: hidden;
overflow-x: auto;
}
.canvas-scrollable .item-inner{
height: 300px;
margin: 10px;
/*white-space:nowrap;*/
background: #FFFFFF;
border: 1px solid rgba(0,0,0,0.1);
-webkit-box-shadow: 0 13px 8px -10px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 13px 8px -10px rgba(0, 0, 0, 0.1);
box-shadow: 0 13px 8px -10px rgba(0, 0, 0, 0.1);
}
.item-thumb{
width: 50%;
height:50%;
padding: 4px;
border: 1px solid green;
}
.item-thumb img{
height: 100%;
object-fit: cover;
}
The images won't fit inside the container divs. the height: 100% is making images occupy the entire 300px height of the outermost div.
Please edit my JSFiddle here.
Hope I was clear enough with my question
Take a look here .Were you trying to achieve something like this??
CSS :
ul.horizontal-slide {
margin: 0;
padding: 0;
width: 100%;
white-space: nowrap;
overflow-x: auto;
}
ul.horizontal-slide li[class*="span"] {
display: inline-block;
float: none;
}
ul.horizontal-slide li[class*="span"]:first-child {
margin-left: 0;
}
Check out the updated fiddle
http://jsfiddle.net/2arvozpc/2/
#roxid : hey thanks for the solution, but the problem seems to persist.
The images are not showing up at all. I am using Bootstrap 3.3.2, so span2 doesn't exist...... I am getting something like this. The images are of size 0px X 0px !!!
When I added my own images, the list-item occupies the entire width
I feel totally stuck my friend. Not able to figure out at all what I am missing
UPDATE
Made a lot of changes and finally got this layout which adjusts dynamically
Pending Issue:
white-space: now-wrap is not working in IE10. Can someone tell me if I have to write an IE specific code for that !!
I want to display the rows of a table on a single line. This is a problem in Internet Explorer 6 and 7 because setting the float attribute to left and the display to block won't do. And changing <tr>s to <td>s won't do either as these html elements are generated by a framework's code that i am not allowed to change.
Edit: Some of you wanted the code, i dunno why it would help but here it is (specific images and classes have been edited out, the code is not available online, some-class may not be the same class everywhere)
<table class="some-class" width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr class="some-class">
<td class="some-class">
<img src=pic.jpg"/>
<div class="some-class">
<div class="some-class">
<img src=pic.jpg"/>
<p></p>
<p></p>
</div> <img src=pic.jpg"/>
</div>
</td>
</tr>
<tr class="some-class">
<td class="some-class">
<img src=pic.jpg"/>
<div class="some-class">
<div class="some-class">
<img src=pic.jpg"/>
<p></p>
<p></p>
</div> <img src=pic.jpg"/>
</div>
</td>
</tr>
<tr class="some-class">
<td class="some-class">
<img src=pic.jpg"/>
<div class="some-class">
<div class="some-class">
<img src=pic.jpg"/>
<p></p>
<p></p>
</div> <img src=pic.jpg"/>
</div>
</td>
</tr>
</table>
I'm afraid I don't think this can be done in a sane and valid manner. float: left in a table is absolutely taboo. Edit: This seems to be valid (!) and possible by taking away each element's table-* display property, but isn't well supported by IE.
The only workable solution I can think of is manipulating the table elements using JavaScript/jQuery, and making the needed conversions (trs into tds...).
The obvious downside of that is that it won't work with JavaScript turned off.
Have you thought about reformatting on the client using Javascript and/or a Javascript library like JQuery? It should be possible to manipulate the DOM to create an appropriate display structure possibly replacing the table elements with DIVs, for example.
Well, there is a css solution that is not without it's drawbacks, so I cannot say I whole-heartedly recommend it (and has not been thoroughly tested cross browser), but for purposes of "possibility" I offer it:
A slight modification of your html for illustration (added some classes to the tr tags):
<table class="some-class" border="0" cellspacing="0" cellpadding="0">
<tr class="some-class r1">
<td class="some-class">
<img src="pic.jpg"/>
<div class="some-class">
<div class="some-class">
<img src="pic.jpg"/>
<p></p>
<p></p>
</div>
<img src="pic.jpg"/>
</div>
</td>
</tr>
<tr class="some-class r2">
<td class="some-class">
<img src="pic.jpg"/>
<div class="some-class">
<div class="some-class">
<img src="pic.jpg"/>
<p></p>
<p></p>
</div>
<img src="pic.jpg"/>
</div>
</td>
</tr>
<tr class="some-class r3">
<td class="some-class">
<img src="pic.jpg"/>
<div class="some-class">
<div class="some-class">
<img src="pic.jpg"/>
<p></p>
<p></p>
</div>
<img src="pic.jpg"/>
</div>
</td>
</tr>
</table>
Some things to note before looking at the css:
I added display: block to some of the table elements for display purposes in FireFox, IE6-7 will ignore those. You may want to just target this solution to IE6-7 if you decide that it fits your purposes.
Some of this styling was illustration purposes.
This illustration uses a set and equal width to the td elements and is only valid for 3 rows. Numbers would have to change based on # of rows to display in line. Basically, my point is, this may not work for your situation, but it at least illustrative that given the right circumstances, it is possible to do what you requested with css only.
The css:
html, body {width: 100%; padding: 0; margin: 0;}
table {position: relative; table-layout: fixed; width: 33%; display: block;}
tr {position: absolute; width: 100%;}
td { border: 1px solid red; width: 100%; display: block;}
tr.r1 {left: 0;}
tr.r2 {left: 100%;}
tr.r3 {left: 200%;}
This would ideally have rows with set heights, as the table ends up with a height: 0 since the data within it is position: absolute, so setting a height to the table would be recommended if possible.