Table centering with table-layout - css

fiddle - here you got 2 exacly same styled tables. TD's width is auto adjusted by table-layout. It works ok, when there is only one line of text. But when there is more text and text is warped it seems like width is calculated by all the text (like it was in one line), not by the longest warped part of text.
Question is how to center content of table nr 2 the same way as it is done in 1'st table? (atm it dont look like centered at all...)
- this is how it should look (lower one) - dont needed yellow space should be cutted to allow table to be centered.

td { text-align:center }
The text in the first table isn't actually centered. It just appears that way because it has no breathing room on either side of the cell.
Making a global declaration like the above would allow additional tweaks to remaining cells.
td.first { text-align:left; font-weight:700 }, etc.
EDIT
You're not going to be able to achieve that effect without declaring a width. Tables don't act like divs by default, so I gave it display:block, width:80% and now the tables center, the td wasn't filling its parent correctly, so I gave it width:100%.
I think this is what you're after: http://jsfiddle.net/hJXb9/

I think you are looking for this.
<table style="width:60%;margin-left:20%;margin-right:20%;">
<tr>
<td style="background:green;text-align: center; vertical-align: middle;">
TADA
</td>
<td style="background:yellow;text-align:center; vertical-align: middle;">
Lorem ipsum dolorsitamet kjfldslggfh;l</td>
</tr>
</table>
Live Demo
Hope, i will helps you. Thanks. !!

Related

how to make line break based on the div width and should not break the word if it is not a long word in css

I need the line break in the div based on div width. div width is dynamic. Word should not break if it is not a long word.
I used word-break:break-all and word-wrap:break-word. Lines are break as we expect, but word are also break. But we doesn't not break the word.
Please find the attached image.
http://i.stack.imgur.com/xJesQ.png
try using css bootstrap scaffolding or responsive columns
you can also try to make css of div to
width: 100%
Use word-wrap:break-word -
DEMO
This way, only words that are wider than the full container width will break.
Yeah It is working now. I using table inside the div which have one <tr> and one <td> like <div> <table style="table-layout: fixed;width: 100%;word-wrap: break-word;"><tr><td> ....content.... </td></tr></table> </div>. Now the line break working based on the div width and also break the word if it is not a long word.

css / padding on emails

Most of the elements on my email page will line up on all email clients correctly if I give the tr and td correct height / widths and tr display inline-block. However on a certain block im having troubles getting the elements to line up without a gap / space between elements.
The first image is the rounded corners on the left and I got it to line up with the block next to it by giving the td / tr and smaller width than that of the img thats inside. However I cannot do this to the other blocks or else they just get smaller all together.
I can change my structure if needed but right now I've kinda limited myself by putting all elements as td's in one tr instead of each element being a tr
<tr>
<td>
<img left corners />
</td>
<td>
180
</td>
<td>
22
</td>
<td>
<img right corners />
</td>
</tr>
fiddle away! http://jsfiddle.net/Qh7En/1/
Thanks!
Here you go. :)
I basically altered the display property.
http://jsfiddle.net/Qh7En/7/
Also, it would probably be better if you didn't use inline CSS. Consider making a class instead.
Are you seeing this in all browsers?
It looks like a typical issue with images always having padding, unless you specifically tell CSS to remove it. Something as simple as adding "img { padding:0px }" to the CSS.
Several ways to fix this.
One is to comment out the white space between the elements.
.....
</td><!--
--><td
....
Demo http://jsfiddle.net/Qh7En/8/

Problems with positioning and resizing

I'm having trouble with the layout of one of my pages (http://jsfiddle.net/NeonGuilmon/pghtZ/5/)
I'm trying to create the interface of a chatroom, with the section room in the top-left of the screen, (100% - 200px) in width and height, section users in the top-left, 50% height and 200px width, section friends in the bottom left with the same dimensions ad users, and chat-bar in the bottom right, 200px in height and (100% - 200px) in width.
As you can see from my fiddle, I messed up pretty badly, and I have no idea where to go next. Can anyone help me with this?
I really recommend reading the following two links:
http://www.w3.org/TR/CSS2/visuren.html
http://www.w3.org/TR/CSS2/box.html
Correctly understanding how position/display work and the difference between margin/ etc is key.
You are currently working with display:block. This basically means that each element will be placed under the next one.
You are using right-margin. This will force a white margin on the right of the element and will not allow anything to sit in that space
Finally if you want to align 4 block elements side by side using a table can ease a lot of the problem (don't go overboard with tables though).
So the easiest way to set something like this up: (I placed the layout on the html but you can put it in the css. Also remove all the positioning and height hints you currently have on your sections. they should just take all the space they can inside the table cell
<table height="100%" border=1>
<tr height=50%>
<td width=100%><section id="room">room</section></td>
<td width=200px><section id="users">users</section></td>
</tr>
<tr height=50%>
<td><section id="friends">friends</section></td>
<td><section id="chat-bar">chatbar</section></td>
</tr>
</table>
Solved my problem: I didn't realize CSS calc was so widely supported: http://caniuse.com/#search=calc

How do I line up two tables without having their content overlap?

I'm using the latest version of Firefox and Chrome on Win XP. I want to display two tables on the same horizontal plane. However, I'm having a problem. Right now I have:
<table width="100" style="display: inline-block;">
...
</table>
<table width="100" style="display: inline-block;">
...
</table>
However, right now, the two tables overlap because the content of the first table is bigger than 100 pixels. Without changing the width, does anyone know how I can change/add to the styles so that the second table will appear to the right of the first table but clear all of the first table's contents?
In principle you could just set overflow: hidden on the first table, but IE (even IE 9) does not implement it properly in this case. The workaround is to wrap your tables in div elements and set the relevant properties on them:
<style>
.tablediv { display: inline-block; width: 100px; overflow: hidden }
</style>
<div class=tablediv>
<table>
...
</table>
<div class=tablediv>
<table>
...
</table>
This way, the content in one of the tables that does not fit into the allocated width is complete absent from the rendering. So it might be more effective than desired, but the question was not quite clear in this respect.
If you are sure the first table never is wider than 100 pixels, you can leave the first table as is and give the second table an absolute position.
Don't change the display property, it will disrupt things.

Why does IE7 move DOM elements on mouseover?

So I have a table with only two columns and one row. The second td holds an image, and the first holds text. I would like the td containing the image to be at the minimum size possible with that image inside, and the first td to fill the remaining space. The following works in every browser except IE7 (we are not doing IE6):
<table> <tr><td style="width:100%;">TEXT</td><td><img src="jpg" alt="jpg" /></td></tr> </table>
What happens is this:
The page renders correctly, then when you mouse over the table, the first td expands to fill the entire table, pushing the image off the edge.
I could fix this with some jQuery to measure the width of the image and calculate remainder for the first td; but that solution is full of LAME!
Please help. I do not understand why IE7 feels the need to redraw the way it does.
Try the following code instead. Instead of explicitly declaring too much width, try explicitly declaring too little (because the image will push the width beyond 1% anyway.)
I am writing this off the top of my head without actually having looked in IE7, but I have IE7 in a Virtual Machine at home and so I'll comment back later if I find a different solution.
<table style="width: 100%;" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>TEXT</td>
<td width="1%" style="width: 1%;"><img src="http://www.google.com/intl/en_com/images/srpr/logo2w.png" alt="Google Logo" /></td>
</tr>
</table>
There are a couple of things that you could try:
Make sure you're using a reset.css stylesheet to reset all of the browser defaults and accommodate any browser quirks. That's especially important with Internet Explorer.
Only use tables for tabular data — I'm not sure what the rest of your table contains, but unless there's going to be rows of data, it would be much easier to use a container div with a p and img floated.
Set the width and height on the img.
Use CSS position: relative; float: left; to see if it helps with positioning issues on hover. I see hover issues a lot with jQuery scripts and browser hacks like CSS3 PIE — if you're using those, try removing them.
Try setting the style="zoom:1" on the element.
I am not sure but looking at
<table> <tr><td style="width:100%;">TEXT</td><td><img src="jpg" alt="jpg" /></td></tr> </table>
from what I can see is that there is no table width on this, so IE does not know how to scale the td appropriately.
Another guess is because you're are declaring width as 100% on the first one IE interprets this to shove it off. Which is my guess, you can not have a width of 100% on the first cell because it means to take up 100% of the full table width.
clear you browser cache, specify a width and height on your image
i have seen the most weird stuff on ie7, like pagebreaks \n and such causing this effect, ie:
<a href="#>
<img src="jpg" />
</a>
to fix just put everything on the same line and without spaces (like your table with a space on the right)
also avoid using inline style, use a stylesheet (css)

Resources