Vertical align in bootstrap table - html

I am trying to display a table with 4 columns, one of which is an image.
Below is the snapshot:-
I want to vertically align the text to the center position, but somehow the css doesn't seem to work.
I have used the bootstrap responsive tables.
I want to know why my code doesn't work and whats is the correct method to make it work.
following is the code for the table
CSS
img {
height: 150px;
width: 200px;
}
th, td {
text-align: center;
vertical-align: middle;
}
HTML
<table id="news" class="table table-striped table-responsive">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Photo</th>
</tr>
</thead>
<tbody>
<?php
$i=0;
foreach ($result as $row)
{ ?>
<tr>
<td>
<?php echo 'Lorem Ispum'; ?>
</td>
<td>
<?php echo 'lrem#ispum.com'; ?>
</td>
<td>
<?php echo '9999999999'; ?>
</td>
<td>
<?php echo '<img src="'. base_url('files/images/test.jpg').'">'; ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>

Based on what you have provided, your CSS selector is not specific enough to override the CSS rules defined by Bootstrap.
Try this:
.table > tbody > tr > td {
vertical-align: middle;
}
In Boostrap 4 and 5, this can be achieved with the .align-middle Vertical Alignment utility class.
<td class="align-middle">Text</td>

As of Bootstrap 4 this is now much easier using the included utilities instead of custom CSS. You simply have to add the class align-middle to the td-element:
<table>
<tbody>
<tr>
<td class="align-baseline">baseline</td>
<td class="align-top">top</td>
<td class="align-middle">middle</td>
<td class="align-bottom">bottom</td>
<td class="align-text-top">text-top</td>
<td class="align-text-bottom">text-bottom</td>
</tr>
</tbody>
</table>

For me <td class="align-middle" >${element.imie}</td> works. I'm using Bootstrap v4.0.0-beta .

The following appears to work:
table td {
vertical-align: middle !important;
}
You can apply to a specific table as well like so:
#some_table td {
vertical-align: middle !important;
}

SCSS
.table-vcenter {
td,
th {
vertical-align: middle;
}
}
use
<table class="table table-vcenter">
</table>

Try:
.table thead th{
vertical-align:middle;
}

vetrical-align: middle did not work for me for some reason (and it was being applied). I used this:
table.vertical-align > tbody > tr > td {
display: flex;
align-items: center;
}

Related

How to access specific div inside td and showing different background color when hovering

I have a table and in my td, I will have div. I need know how let user see different color when hovering at specific div
My code
<div className="table-responsive">
<table className="table table-responsive table-hover table-condensed returnSpreadIndex">
<thead>
<tr>
<th>Period/Range</th>
<th>n30</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="hover1"> // LET SAY USER HOVER THIS DIV, WILL SHOW YELLOW COLOR
Apple1
</div>
<div class="hover2"> // IF USER HOVER THIS DIV, WILL SHOW ORANGE COLOR
pineApple1
</div>
</td>
<td>testing purpose</td>
</tr>
<tr>
<td>test</td>
<td>
<div>
Apple2
</div>
<div>
pineApple2
</div>
</td>
</tr>
</tbody>
</table>
</div>
after I lookup solution for this , finally can come out with this code but it is not working either
div.table-responsive table.returnSpreadIndex tbody > tr > td>div:hover .hover1 {
background-color: yellow;
}
div.table-responsive table.returnSpreadIndex tbody > tr > td>div:hover .hover2 {
background-color: orange;
}
Thank you,
.table-responsive table .hover1:hover {
background-color: yellow;
}
.table-responsive table .hover2:hover {
background-color: orange;
}
<div class="table-responsive">
<table class="table table-responsive table-hover table-condensed returnSpreadIndex">
<thead>
<tr>
<th>Period/Range</th>
<th>n30</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="hover1">
Apple1
</div>
<div class="hover2">
pineApple1
</div>
</td>
<td>testing purpose</td>
</tr>
<tr>
<td>test</td>
<td>
<div>
Apple2
</div>
<div>
pineApple2
</div>
</td>
</tr>
</tbody>
</table>
</div>
This should work perfectly for you,
PS: pay attention to your attribute if you are not using this code inside a react app because ClassName is specific attribute for react
.hover1:hover { background-color: yellow} .hover2:hover {background-color: orange}
As mentioned by #OthManE01,
first warning is for the use of the attribute ClassName, that's specific for react, but not interpreted by HTML instead.
Second mistake is in the css selector. Going up the selection in your code you're gonna make the CSS-rule for an element with class .hover1 (or .hover2)
-direct child of a div:hover
-direct child of td
-direct child of tr
-direct child of tbody of all table with .returnSpreadIndex class, an so on...
Instead you wanna select div.hover1:hover and div.hover2:hover.
So the right CSS-rule could be:
div.table-responsive table.returnSpreadIndex tbody > tr > td>div.hover1:hover {
background-color: yellow;
}
div.table-responsive table.returnSpreadIndex tbody > tr > td>div.hover2:hover {
background-color: orange;
}

adding logic in PHP for printing

I am just starting with PHP and having trouble of getting my page result to print right. I call the page below from index.php. It looks ok if I displayed the page on a monitor but when I print the page and it is more than one page, the section at the end of the page got cut off and continue on the second page. I am looking for a way so that when I print the page, it will look if the section (each item number) will fit the whole section (repair desc, common cause, etc) in that page. If it does not then just print on the next page.
I also included the CSS file. Basically what it does is forcing the width of page to fit a letter-size paper. Thank you in advance.
<?php include_once $_SERVER['DOCUMENT_ROOT'] .
'/fms/includes/helpers.inc.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Print Repair Form</title>
<link rel='stylesheet' type='text/css' href='/fms/css/letter-size.css' />
</head>
<body>
<div id="page-wrap">
<table>
<tr>
<td rowspan = "3" id="logo"><img src="/fms/images/flex_no_address_256.jpg" /></td>
<td rowspan = "3" id="address">Address<br />
City, State Zipcode <br />
Phone number <br />
website address
</td>
<td>
<table>
<tr>
<td id="repairinfo" class="theading" colspan = "2">Repair Detail</td>
</tr>
<tr>
<td><?php htmlout($custno); ?></td>
<td width="100px">WO: <?php htmlout($wonum); ?></td>
</tr>
<tr>
<td><?php htmlout($custname); ?></td>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<?php foreach($items as $item): ?>
<table border ="1">
<tr>
<td class="theading">Type of Repair</td>
<td class="theading">Repair ID</td>
<td class="theading">Fault Picture</td>
</tr>
<tr>
<td class="tablepadding"><?php htmlout($item['repairtype']); ?></td>
<td class="tablepadding"><?php htmlout($item['itemno']); ?></td>
<td rowspan="7" align="center">
<img src="/fms/images/wo_items/<?php htmlout($item['filename']); ?>" width="256" />
</td>
</tr>
<tr>
<td class="theading" colspan="2">Repair Description</td>
</tr>
<tr>
<td class="tablepadding" colspan="2"><?php htmlout($item['repairdesc']); ?>
</td>
</tr>
<tr>
<td class="theading" colspan="2">Common Causes</td>
</tr>
<tr>
<td class="tablepadding" colspan="2"><?php htmlout($item['commoncause']); ?>
</td>
</tr>
<tr>
<td class="theading" colspan="2">Preventive Measures and Maintenance</td>
</tr>
<tr>
<td class="tablepadding" colspan="2"><?php htmlout($item['maintenance']); ?>
</td>
</tr>
</table>
<br />
<?php endforeach; ?>
</div>
</body>
</html>
CSS:
* { margin: 0; padding: 0;}
body {
font: 12px/1.4 Georgia, serif;
}
a img {
border: none;
}
#page-wrap {
width: 800px;
margin: 0 auto;
}
table {
width:100%;
}
#logo {
width: 256px;
}
#address {
width: 170px;
}
#repairinfo {
border-bottom: solid 1px;
text-align: center;
}
.theading {
font-weight: bold;
padding: 3px;
}
table tr td.tablepadding {
padding: 3px;
}
It should be achieved through CSS and no PHP, although you can use php as well as a workaround, google for css media.
There are some tricks for the CSS of your printing: http://slodive.com/web-development/css-print-page-tricks/
Can't give you specific details because I haven't worked too much with printings but it all comes to testing the total height that fits on the paper, and looking for a measure in php (maybe lines?) so if the size is bigger than the one you set, it creates another Table.
You could also use Javascript as you can detect element's (for example a table's) height, and call some function when the max height is reached.
Also I want to suggest you not using tables if it's not totally necesary, It's a very old-school approach and troublesome to modify, with more different behaviour across browsers, and with a lot more of unnecesary code.
Your issue is not with PHP but with CSS.
You need to include a print specific stylesheet as this will be different to your computer monitor styles.
Here's a good blog post about print CSS
http://www.webcredible.co.uk/user-friendly-resources/css/print-stylesheet.shtml
In your html the print stylesheet <link> element will need a media="print" attribute
Then in your print stylesheet you can specify a width

Changing the color of a cell in a html table when I hover over it

I have looked through all the answers posted but I cant seem to get this code to work correctly. I am trying to get the individual cell to change color when I hover over it, but I don't have access to the .css with the service we are using. I am being forced to drop an HTML code box that I can paste my code into specific to the element I am changing, but not the entire .css file...just that element.
Here is my code. Any help in getting the background to change to #ff0000 and the Text to change to #000000 when I roll over the cell would be greatly appreciated.
(It is ultimately my intent to add a >a href for each of the cells as well, but I am trying to do this one step at a time. The >a href will (I hope) add the selected cell to a shopping cart.)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<title></title>
<style type="text/css">
body {
background: #000;
}
#wrap {
margin: 0 auto; /* margin 0 auto will center that box in your document */
width: 780px; /*size of your box*/
background: #000;
text-align: center; /* everything will be written in that box will be centered horizontally*/
}
</style>
<div id="wrap">
<table width="780">
<tr>
<td align="center">
<table border=1>
<tbody>
<!-- Results table headers -->
<tr>
<th>Messages Per Month</th>
<th>1 Month Pricing</th>
<th>3 Month Pricing</th>
<th>12 Month Pricing</th>
</tr>
<tr>
<td>500</td>
<td>$14.95/Month</td>
<td>$12.95/Month</td>
<td>$9.95/Month</td>
</tr>
<tr>
<td>1,000</td>
<td>$24.95/Month</td>
<td>$20.95/Month</td>
<td>$17.95/Month</td>
</tr>
<tr>
<td>1,500</td>
<td>$37.95/Month</td>
<td>$31.95/Month</td>
<td>$26.95/Month</td>
</tr>
<tr>
<td>2,000</td>
<td>$49.95/Month</td>
<td>$41.95/Month</td>
<td>$35.95/Month</td>
</tr>
<tr>
<td>2,500</td>
<td>$62.95/Month</td>
<td>$52.95/Month</td>
<td>$44.95/Month</td>
</tr>
<tr>
<td>5,000</td>
<td>$119.95/Month</td>
<td>Not Available</td>
<td>Not Available</td>
</tr>
<tr>
<td>7,500</td>
<td>$179.95/Month</td>
<td>Not Available</td>
<td>Not Available</td>
</tr>
<tr>
<td>10,000</td>
<td>$219.95/Month</td>
<td>Not Available</td>
<td>Not Available</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</div>
In CSS:
td:hover {
background-color: #ff0000;
color: #000000;
}
Or you can use JavaScript/jQuery:
$(document).ready(function() {
$("td").hover(
function() {
$(this).css('background-color', '#ff0000');
$(this).css('color', '#000000');
},
function() {
$(this).css('background-color', 'none');
$(this).css('color', 'black'); // or whatever your original color was
}
);
});
Wrap the cell data with a div (class="cell_hvr") and a link around the content.
.cell_hvr {
padding: 2px;
width: 100%;
height: 100%;
}
.cell_hvr a {
display: block;
text-decoration: none;
}
.cell_hvr a:hover {
background-color: red;
}
<div class="cell_hvr"> (Your content) </div>
You can do this by giving each cell a class
<td class="a">..</td>
and then styling it
<style>
td.a { background-color:#ff0000; }
td.a:hover { background-color:#000000; }
</style>
CSS: td:hover, th:hover { background:#ff0000; color:#000; }
I was looking for the JavaScript version of the answer to this question. But, I am not using JQuery..
I have
oCell = newRow.insertCell();
oCell.style.background = tintTest(myCounts[i]);
myCounts is just an array holding an Int..
but now i just wanted to add the hover background color to my current oCell before smashing it in line and moving on with the loop......
So I found the code below as the only checked answer in a stream of 'can't be done'.. just not sure if this would even help me.
var css = 'table td:hover{ background-color: #00ff00 }';
var style = document.createElement('style');
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
document.getElementsByTagName('head')[0].appendChild(style);
EDIT!!! I just found out my issue (I hope the code snip helps with yours still) I tried to add the hover in CSS and it just isn't supported at all.

how to make a cell of table hyperlink

How can entire table cell be hyperlinked in html without javascript or jquery?
I tried to put href in td tag itself but its not working at least in chrome 18
<td href='http://www.m-w.com/dictionary/' style="cursor:pointer">
Try this:
HTML:
<table width="200" border="1" class="table">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
CSS:
.table a
{
display:block;
text-decoration:none;
}
I hope it will work fine.
Try this way:
<td> </td>
Easy with onclick-function and a javascript link:
<td onclick="location.href='yourpage.html'">go to yourpage</td>
Why not combine the onclick method with the <a> element inside the <td> for backup for non-JS? Seems to work great.
<td onclick="location.href='yourpage.html'">Link</td>
Here is my solution:
<td>
<div class="item-container">
<img class="icon" src="/iconURL" />
<p class="name">
SomeText
</p>
</div>
</td>
(LESS)
td {
padding: 1%;
vertical-align: bottom;
position:relative;
a {
height: 100%;
display: block;
position: absolute;
top:0;
bottom:0;
right:0;
left:0;
}
.item-container {
/*...*/
}
}
Like this you can still benefit from some table cell properties like vertical-align.(Tested on Chrome)
Problems:
(User: Kamal) It's a good way, but you forgot the vertical align problem! using this way, we can't put the link exactly at the center of the TD element! even with vertical-align:middle;
(User: Christ) Your answer is the best answer, because there is no any align problem and also today JavaScript is necessary for every one... it's in every where even in an old smart phone... and it's enable by default...
My Suggestion to complete answer of (User: Christ):
HTML:
<td style="cursor:pointer" onclick="location.href='mylink.html'"><a class="LN1 LN2 LN3 LN4 LN5" href="mylink.html" target="_top">link</a></td>
CSS:
a.LN1 {
font-style:normal;
font-weight:bold;
font-size:1.0em;
}
a.LN2:link {
color:#A4DCF5;
text-decoration:none;
}
a.LN3:visited {
color:#A4DCF5;
text-decoration:none;
}
a.LN4:hover {
color:#A4DCF5;
text-decoration:none;
}
a.LN5:active {
color:#A4DCF5;
text-decoration:none;
}
you can give an <a> tag the visual behavior of a table cell:
HTML:
<table>
<tr>
Cell 1
<td>Cell 2</td>
</tr>
</table>
CSS:
tr > a {
display: table-cell;
}
I have seen this before when people are trying to build a calendar. You want the cell linked but do not want to mess with anything else inside of it, try this and it might solve your problem.
<tr>
<td onClick="location.href='http://www.stackoverflow.com';">
Cell content goes here
</td>
</tr>
Not exactly making the cell a link, but the table itself. I use this as a button in e-mails, giving me div-like controls.
<a href="https://www.foo.bar" target="_blank" style="color: white; font-weight: bolder; text-decoration: none;">
<table style="margin-left: auto; margin-right: auto;" align="center">
<tr>
<td style="padding: 20px; height: 60px;" bgcolor="#00b389">Go to Foo Bar</td>
</tr>
</table>
</a>
If you want use this way in php Do the following
<?php
echo ("
<script type = 'text/javascript'>
function href() {
location.href='http://localhost/dept';
}
</script>
<tr onclick='href()'>
<td>$id</td>
<td>$deptValue</td>
<td> $month </td>
<td>100%</td>
</tr>
");
?>

Freeze Column headers in IE 6.0 and IE 7.0

This is the code sample of a simple list display with a scroll button..It is working good. But now i want to freeze first row..that is the header..Can you please help me..
<div id="user">
<table class="user_list" frame="box" bordercolor="#c1a3cf"
border="1" cellspacing="3" cellpadding="3">
<thead>
<tr>
<th style="padding-top:15px;"> Nr. </th>
<th style="padding-top:15px;"> Concession Nr. </th>
<th style="padding-top:15px;"> Action Performed </th>
<th style="padding-top:15px;"> Action by </th>
<th style="padding-top:15px;"> Action on </th>
</tr>
</thead>
<tbody>
<?php $result = get_user_actionlog($seite,$entries);
if($seite == 1) {
$number = 0;
} else {
$number = ($seite-1) * $entries;
}
while($record = odbc_fetch_array($result)) { ?>
<tr>
<td width="25" class="rtodata"><?php $number += 1;
echo $number;?></td>
<td width="150" class="rtodata"><?php echo $record['concession']; ?> </td>
<td width="400" class="rtodata"><?php echo $record['action_performed'];?></td>
<td width="75" class="rtodata"><?php echo $record['action_by'];?></td>
<td width="100" class="rtodata"><?php echo $record['action_on'];?></td>
</tr>
<?php }?>
</tbody>
</table>
</div>
and in my CSS file,
#user {width: 900px;height:800px;overflow:auto;}
EDIT:-
scrollable table with fixed header works perfectly in IE 6.0 nad in Firefox but not in IE 7.0. If any of you champs can update that...
You can do this by adding a class to the <thead> and using position: fixed; You'll need to add some padding to your div to make it display as you wish.
Example for you here.
IE isn't good at supporting anything scrolling tables. Editing a table in this way is rarely a good idea in any case. You can have one table with your TH wrapped in a div, then the rest of your info in another table, with another div with overflow auto
Another example.
It's not perfect as you have a lot on HTML visual attributes, you should get rid of those and use CSS only. But this is the basic functionality, it should work in all browsers.
Surround the table with divs with outer and then innera..check the css
.outer {
position:relative;
padding:4em 0 3em 0;
width:54em;
background:bottom;
margin:0 auto 3em auto;
}
.innera {
overflow:auto;
width:54em;
height:9.6em;
background:#eee;
border:2px gray;
}
.outer thead tr {
position:absolute;
top:2em;
height:1.5em;
left:0;
}
.outer th, .outer td {
width:10em;
text-align:left;
I tested the code and it is working. Tested in IE 6.0,7.0 ++ .The code is from internet:-)