How to display Table and Image using inline-block in Html? - html

How can I display my image and the table on the same level? This is really depressing me because I can't get "inline-block" to work. :(
<p id="play">
hey
</p>
<div id="menu">
<table>
<tr>
<td>Models</td>
</tr>
<tr>
<td>Cars</td>
</tr>
<tr>
<td>Modern Houses</td>
</tr>
<tr>
<td>Vacation Spots</td>
</tr>
<tr>
<td>Sports and Outdoors</td>
</tr>
<tr>
<td>Books</td>
</tr>
<tr>
<td>Abandoned Houses</td>
</tr>
<tr>
<td>Summer Wear</td>
</tr>
<tr>
<td>Makeups</td>
</tr>
<tr>
<td id="site">Site Info</td>
</tr>
</table>
</div>
<img src="C:\Users\Elexie\Documents\Downloads\faki2.jpg"/>
body {
background: #181818;
margin: 0;
padding: 0;
}
/* set body display to inline-table*/
#play {
background: black;
color: white;
margin: 0;
padding: 0;
height: 35px;
}
table,td {
color: white;
border: 1px solid white;
border-collapse: collapse;
width: 160px;
padding: 10px;
font-family: ;
}
table {
}
#site {
height: 350px;
}
img {
float: right;
}
I changed the picture, but it's of similar size
http://jsfiddle.net/w6d5g/

In your css code:
table{
float:left;
}
Should do the trick.
Read more: http://www.w3schools.com/css/css_float.asp

Check this fiddle: http://jsfiddle.net/Mohamed_nabil/F8MKp/
/*******Added style******/
img
{
/*165px is your Menu width with borders*/
max-width: calc(100% - 165px);
/*For cross browser*/
-webkit-max-width: calc(100% - 165px);
-moz-max-width: calc(100% - 165px);
-o-max-width: calc(100% - 165px);
-ms-max-width: calc(100% - 165px);
display: inline-block;
vertical-align: top;/* Can be middle, bottom */
}
#menu{
display: inline-block;
}

Firstly, wrap your image tag with a div. Name this div anything you want. Let's name it: "image-test".
<div class="image-test">
<img src="(URL for IMAGE)">
</div>
Next, let's say you want your table to take up 50% of the width and your image to take up the other 50%. We are also going to float these div elements so they are not in the flow of the document.
#menu{
float:left;
width:50%;
}
.image-test{
float:left;
width:50%;
}
You'll notice your image is larger than the containing div, so let's set a max width on all images to avoid future problems.
img {
max-width:100%;
}

Related

center table in page HTML

I'm trying to center this header in the middle of the page. Not sure why margin-left:auto and margin-right:auto isn't working. It won't register align:center either for the table. The table is only a header. Here's the code I have for the css and table.
<style>
table {
margin-top: 2em;
margin-left: auto;
margin-right: auto;
}
table th {
background: linear-gradient(to bottom right, #6688FF, #AACCFF);
height: 4em;
text-align: center;
text-transform: capitalize;
color:white;
border:#ccc 1px solid;
}
table tr {
text-align: center;
}
table thead {
position:fixed;
}
</style>
<table class="head">
<%--header --%>
<thead>
<tr>
<th>one</th>
<th>two</th>
<th>three</th>
</tr>
</thead>
<%--body --%>
<tbody>
</tbody>
</table>
Since you're making the thead fixed, it's pulled out of the normal flow. Below, I've demonstrated one way to center it horizontally independent of its surroundings. Otherwise, you're better off making the table fixed, since semantically they should continue their parent / child relationship.
Is there a reason that you're a table for this?
table {
margin-top: 2em;
}
table th {
background: linear-gradient(to bottom right, #6688FF, #AACCFF);
height: 4em;
text-align: center;
text-transform: capitalize;
color:white;
border:#ccc 1px solid;
}
table tr {
text-align: center;
}
table thead {
position:fixed;
left: 50%;
transform: translateX(-50%);
}
<table class="head">
<thead>
<tr>
<th>one</th>
<th>two</th>
<th>three</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
remove position fixed from table thead selector and it should work

How to get rid of extra height from td?

My html markup is:
<table>
<tbody>
<tr>
<td><span class="test">This is span.</span></td>
</tr>
</tbody>
css is:
.test{
font-size : 12px;
}
My span element take a height of 12px. So td should also have a height of 12px. But if I inspect in chrome developers tool, td has a height of 21px. Where is 9px coming from? How to get rid of it? Here is my code pen
set span to display:block
.test{
font-size : 12px;
display:block;
background : rgba(255,0,0,.5);
}
for removing default margin and padding of all elements use this
*{
margin:0;
padding:0;
}
* {
margin: 0;
padding: 0;
}
td {
background: black;
padding: 0;
margin: 0;
}
.test {
font-size: 12px;
display: block;
background: rgba(255, 0, 0, .5);
}
<table>
<tbody>
<tr>
<td><span class="test">This is span.</span>
</td>
</tr>
</tbody>
</table>
Edit
the issue is because of inline-block one fix is adding font-size:0; to parent removes the white-space
demo - http://jsfiddle.net/s4ufsbd3/
td {
background: black;
padding: 0;
margin: 0;
font-size:0;
}
* {
margin: 0;
padding: 0;
}
td {
background: black;
padding: 0;
margin: 0;
font-size: 0;
}
.test {
font-size: 12px;
display: inline-block;
background: rgba(255, 0, 0, .5);
}
<table>
<tbody>
<tr>
<td><span class="test">This is span.</span><span class="test">This is span.</span>
<span class="test">This is span.</span>
<span class="test">This is span.</span>
</td>
</tr>
</tbody>
</table>
Vitorino Fernandes solution does work, but you will have issues when you have text inside td since font size : 0px;.
<table>
<tbody>
<tr>
<td>SOME TEXT HERE<span class="test">This is span.</span></td>
</tr>
</tbody>
</table>
Here's my css to fix that issue.
td{
line-height : 0;
}
.test{
font-size : 12px;
display:inline-block;
background : rgba(255,0,0,.5);
line-height : 1;
}
Just add this style to td and check style="line-height : 0;"
As suggested, the line-height is the cause of this space. Also, others suggestions may works as well, but with this you can also adjust the height over and/or bellow the text to your taste using "margin".
HTML
<table>
<tbody>
<tr>
<td><p>This is a paragraph. This paragraph is looooooooooooooooong and wants overlap.</p></td>
</tr>
</tbody>
</table>
CSS
table {
border-collapse: collapse; /*only if you don't want border space between the cells*/
}
td {
font-size:12px;
padding: 0;
margin: 0;
line-height:0;
}
p {
display:block;
line-height: 1em;
margin-top: 0px; /*adjust to your necessities*/
margin-bottom: 0px; /*adjust to your necessities*/
}

Table Header with fixed header without using div

I want table header with fixed width without using div tag outside table. I need some solution in which i just need to change css file only. i have tried by putting table in side div with style:
width:100%;overflow-x:scroll
and on minimizing the browser's height and width, it is working fine.
But this is not what i want. I want to change in css style only, to avoid change in all the jsp files in my project
PSB my code:
CSS
h3 {
font: bold 1.2em Verdana, Helvetica, Arial, sans-serif;
background: #B7BBD6;
padding: 5px;
margin: 10px 0 0 0;
clear: both;
}
.list {
float: left;
width: 100%;
color: #000099;
border: 1px solid #DEDFDE;
margin: 0 0 15px 0;
overflow-x: scroll
}
.list th, .list td {
vertical-align: top;
border: 1px solid #B7BBD6
}
.even {
background: #F1F1F1
}
/*.odd {background: #F1F1F1}*/
.odd {
background: #FFF
}
HTML
<h3>Test Table</h3>
<table class="list">
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
<th>f</th>
<th>g</th>
<th>h</th>
<th>i</th>
</tr>
<tr class="odd">
<td>98052826</a></td>
<td>Company</td>
<td>asdfsafdsa</td>
<td>asdfsadf</td>
<td>asdfsafs</td>
<td>sadfsaf</td>
<td>1234</td>
<td>asfsdf</td>
<td>asfsafdf</td>
</tr>
<tr class="even">
<td>234568992</a></td>
<td>Private</td>
<td>asfsdfaf</td>
<td>asfsaf</td>
<td>safsdafsdf</td>
<td>Some address</td>
<td>3344</td>
<td>&safsdafsda</td>
<td>sadfsaddfdaf</td>
</tr>
<table>
Please suggest??
Set the following to your css stylesheet:
table{width: 100%;table-layout: fixed;}
Edit
If you could use jQuery, its easy:
$(document).ready(function(){
/*define table class then place your class here instead of 'table'*/
var tablewidth = $('table').width();
/*define h3 class then place your class here instead of 'h3'*/
$('h3').css('width',tablewidth - 10);
});
demo
h3{
position:fixed;
width:100%
}
table{
top:60px;
position:relative;
}
demo

Responsive table

I need help with a responsive table. What's needed is to basically have it change to a 'mobile version' upon resizing, however the mobile version is a little different to the main style of it, as the image shows.
I've currently got this: http://jsfiddle.net/MLsZ8/
HTML:
<table class="crafting">
<thead>
<tr>
<th style="width:15%">Name</th>
<th style="width:20%">Ingredients</th>
<th style="width:205px;">Input > Output</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Ore Blocks</td>
<td>Gold Ingots, Iron Ingots, Diamonds and Lapis Lazuli Dye</td>
<td><img width="204" height="112" title="Crafting Ore Blocks" src="http://www.minecraftxl.com/images/crafting/Crafting-Ore-Blocks1.gif" alt="Crafting Ore Blocs from Ingots" /></td>
<td>Turn ingots or diamonds into a placeable block. Can be used for storage or to show off.</td>
</tr>
</tbody>
</table>
CSS:
td {
border:0;
}
table.crafting {
border-spacing:0;
border-collapse:collapse;
}
.crafting th {
border:2px solid #f3f3f3;
padding:5px;
}
.crafting td {
border:2px solid #f3f3f3;
padding:5px;
vertical-align:top;
}
.crafting tr {
background:#c6c6c6;
}
.crafting-name {
font-weight:bold;
border-bottom:0 !important;
background:#c6c6c6;
}
.crafting-ingredients {
border-top:0 !important;
border-bottom:0 !important;
background:#bcbcbc;
}
.crafting-img {
width:205px;
border-bottom:0 !important;
border-top:0 !important;
background:#c6c6c6;
}
.crafting-desc {
border-top:0 !important;
background:#bcbcbc;
}
If you are not opposed to changing the overall format of the HTML, I have a solution that might be a bit easier to handle...
If you change the current table structure to a series of div elements, you can nest each table row into a container div.
I'll give you an example for one "row":
<div class="tableRow">
<div class="columnOne"> content </div>
<div class="columnTwo"> content </div>
<div class="columnThree"> content </div>
<div class="columnFour"> content </div>
</div>
Then, using CSS, you could set .tableRow {width: 100%}. From here, you could set the column widths based on your needs. From your example, it looks like you could do:
.columnOne {width: 10%; float: left;}
.columnTwo {width: 15%; float: left;}
.columnThree {width: 30%; float: left;}
.columnFour {width: 45%; float: left;}
Then, when you reach your mobile view breakpoint, using a #media query, you can do the following:
.columnOne, .columnTwo, .columnThree, .columnFour {width: 100%}
This will cause the columns to effectively become rows of width: 100%.
Option 1:
Full tables
http://jsfiddle.net/2655u/
Option 2
Convert tables to div in used mediaqueries
HTML
<div class="title">
<div class="name">Name</div>
<div class="ingredients">Ingredients</div>
<div class="field">Input > Output</div>
<div class="description">Description</div>
</div>
<div class="responsive">
<div class="name">Ore Blocks</div>
<div class="ingredients">Gold Ingots, Iron Ingots, Diamonds and Lapis Lazuli Dye</div>
<div class="field">
<img width="204" height="112" title="Crafting Ore Blocks" src="http://www.minecraftxl.com/images/crafting/Crafting-Ore-Blocks1.gif" alt="Crafting Ore Blocs from Ingots" />
</div>
<div class="description">Turn ingots or diamonds into a placeable block. Can be used for storage or to show off.</div>
</div>
CSS
div {
display: table;
width: 100%;
table-layout: fixed;
}
div > div {
display: table-cell;
background : #C6C6C6;
border:2px solid #f3f3f3;
padding:5px;
vertical-align : top;
}
div.title {
text-align : center;
font-weight:bold;
}
div.name {
width : 90px;
}
div.ingredients {
width : 150px;
}
div.field {
width : 205px;
}
#media only screen and (max-width: 767px) {
.title {display:none;}
.responsive div {
display : block;
width : auto;
text-align : center;
background : white;
}
.responsive div.ingredients {background : #C6C6C6;}
.responsive div.description {background : #C6C6C6;}
}
Example: http://jsfiddle.net/2DTSG/
Well, I was also searching for the same one day. Got the following. It follows the same approach, converting columns to rows when getting viewed in smaller device.
http://css-tricks.com/responsive-data-tables/
Before moving ahead see the Live Demo
One simple solution is to have two tables: a regular table (with class full) and a mobile one (with class mobile). Then you can use a media query to switch between them at a particular screen size.
If your website isn't particularly heavy, this is an approach that will save a lot of headache.
Example fiddle: http://jsfiddle.net/QDrPb/
.mobile {
display:none;
}
#media (max-width:767px) {
.full {
display:none;
}
.mobile {
display:block;
}
}
Twitter Bootstrap is a nice thing to achieve table-responsiveness.
http://getbootstrap.com/
You have to download it from the above link and add the css file.
After that, apply like this: http://getbootstrap.com/css/#tables-responsive
I hope this may help your need.
Thanks
here simple demo please reffer this link for pure css demo fiddle
/*by Ñ££¿ Upadhyay*/
body {
font-family: "Open Sans", sans-serif;
line-height: 1.25;
}
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;a
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 18px;
margin: 10px;
}
table tr {
background: #f8f8f8;
border: 1px solid #ddd;
padding: 10px;
}
table th,
table td {
padding: 10px;
text-align: center;
}
table th {
font-size: 14px;
letter-spacing: 0;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 14px;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: 5px;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: 14px;
text-align: right;
}
table td:before {
/*
* aria-label has no advantage, it won't be read inside a table
content: attr(aria-label);
*/
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
padding-right: 70px;
}
table td:last-child {
border-bottom: 0;
}
}
<table>
<caption>Statement Summary</caption>
<thead>
<tr>
<th scope="col">Account</th>
<th scope="col">Due Date</th>
<th scope="col">Amount</th>
<th scope="col">Period</th>
<th scope="col">Period</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Due Date">04/01/2016</td>
<td data-label="Amount">$1,190</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td scope="row" data-label="Account">Visa - 6076</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Amount">$2,443</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td scope="row" data-label="Account">Corporate AMEX</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Amount">$1,181</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td scope="row" data-label="Acount">Visa - 3412</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Amount">$842</td>
<td data-label="Period">01/01/2016 - 01/31/2016</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
</tbody>
</table>
Responsive Tables JavaScript Plugin
<link rel="stylesheet" href=".../dist/css/table-fluid.css"/>
<script src=".../dist/js/table-fluid.js"></script>
<table class="table-fluid">
<thead>
...
</thead>
<tbody>
...
</tbody>
</table>
Use JavaScript function
window.tableFluid('.table-fluid');
https://www.npmjs.com/package/table-fluid
https://github.com/maestro888/table-fluid
Table cells cannot rearrange they way you want - rows and columns are locked and cannot float. All you can do is change the layout WITHIN each cell. You will need to change your mark-up completely to make that happen.

Table width in IE7/8

I'm getting crazy with getting my table look right on different browsers, just when I think I got in one it changes in the other. IE7/8 and Firefox are my target browsers.
Could someone please have a look at the code I just can't figure out what's the problem.
Table is generated by Javascript, I need it have fixed width of 220px, the main problem is tfoot where I have 3 tds for which I'm having problems controlling width.
Here is the relevant portion of the code:
<table class="favouritelinks" cellspacing="0" cellpadding="0" width="220" >
<thead>
<tr><td colspan="3">Your Favourite Links</td></tr>
</thead>
<tbody id="tulemused" ></tbody>
<tr>
<td width="50">Name</td><td><input type="text" id="key" name="key" value="" /></td>
<td rowspan="2"><div class="addimg"></div></td>
</tr>
<tr>
<td width="50">URL</td><td><input type="text" id="val" name="val" value="" /></td>
</tr>
</table>
and css:
.favouritelinks td{
height: 20px;
padding: 3px;
border-bottom: 1px solid white;
word-break: break-all;
}
.favouritelinks td a{
color: white;
text-decoration: none;
}
thead{
background: url(img/title5.png) no-repeat;
color: #444;
font: bold 16px Helvetica;
text-shadow: 0 1px 0 #FFF;
text-align: center;
width: 220px;
height: 36px;
}
thead tr {
height: 36px;
}
.container{
width: 220px;
margin-top: 105px;
margin-left: 10px;
}
.delimg {
background: url(img/details_close.png) no-repeat;
width: 20px;
height: 20px;
float: right;
}
.addimg {
background: url(img/details_open.png) no-repeat;
width: 20px;
height: 20px;
float: right;
}
.urls {
display: none;
}
What am I doing wrong?
Picture http://imageshack.us/photo/my-images/38/56751263.jpg/
Try this in your CSS:
table {
table-layout: fixed;
}
Remove the padding:3px from .favouritelinks td in CSS and all will be OK.
OR BETTER WAY
set td width in CSS not in HTML
I had the same problem with layout good in IE9+, but bad in IE 7/8. I found out "colspan" was the problem when this column is wider then the sum of other matching columns not colspan on other rows. I was specifiying fixed width on all columns except the one I want to be adjusted with the remaining width. But that didn't work on IE 7/8. So I end up splitting rows on different "table" to workaround that layout problem.