mobile web app with very long strings - css

I'm trying to build web app designed for mobiles. But I have some links which are extremely large. What i want to do is break these strings if the text doesn't fit, and use the entire string if it fits.
I tried using word-wrap:break-word:
.breakWord {
width: 100%
word-wrap: break-word;
}
My html is:
<table>
<tr>
<td rowspan="2" style="width:10%" >picture</td>
<td colspan="2" style="width:90%" class="breakWord">link</td>
</tr>
<tr>
<td style="width:80%">info1</td>
<td style="width:10%">info2</td>
</tr>
<tr>
</tr>
</table>
This code doesn't fit on the page - a horizontal scroll bar appears.
How can I make the text fit?

If you correct the errors in your source, it will work.
Remove the width:100% from the style block. It conflicts with the inline style in the td, and misses a semicolon
colpan should be colspan
Also, I believe that some browsers can get confused when encountering a colspanned td with a width style. You can safely remove the style="width:90%", since the two tds below set the width correctly already.
Edit:
So it doesn't work everywhere. According to the answers to this question, the problem is with the table: first, the width of the table is calculated, and then the 10% and 90% are taken as the calculated width instead of the available width on the screen.
So a possible solution is to give the table a specific width, and set its table-layout to fixed.
<table style="width:100%; table-layout:fixed">

Related

<tr>/<td> heights being ignored? [duplicate]

Why does the CSS property overflow:scroll; not work in <td>, while overflow:hidden; works well?
<table border="1" style="table-layout:fixed; width:100px">
<tr>
<td style="overflow:scroll; width:50px;">10000000000000000000000000000000000</td>
<td>200</td>
<td>300</td>
</tr>
</table>
From the CSS specs1,2, I can't see why.
You have to wrap it in a div, that will work:
<table border="1" style="table-layout:fixed; width:500px">
<tr>
<td style="width:100px;"><div style="overflow:scroll; width:100%">10000000000000000000000000000000000</div></td>
<td>200</td>
<td>300</td>
</tr>
</table>
Firstly provide desired height to td and then Apply "float: left" property to respective "td" you want scrollbar to appear.
I got something from here!
Andrew Fedoniouk wrote:
This is actually my question:
"One technical reason is that the overflow property does not apply to
tables." - why? What is this reason?
I'm no expert, but I believe this is
just for backward compatibility with
legacy table behavior. You can check
the "automatic" table layout
algorithm in the spec. I'm pretty
sure that this layout algorithm is
incompatible with the overflow
property (or, more accurately, the
layout algorithm will never result in
the need for any value of overflow
except 'visible').
Yep, this is why I am asking. Seems like there are no formal reasons
why or should not be scrollable but seems like
UA vendors reached some silent agreement in this area. So is the
question.
The spec agrees with you with respect
to elements. Table cells are
supposed to respect overflow, although
Mozilla, at least, appears not to do
so. I can't answer your question in
this instance, although I would still
guess the answer is still tied to
legacy rendering.
The main thread is here.
<table border="1" style="table-layout:fixed; width:500px">
<tr>
<td style="width:100px;"><div style="overflow:scroll; width:100%">10000000000000000000000000000000000</div></td>
<td>200</td>
<td>300</td>
</tr>
</table>

CSS: how to make the widths of the columns as wide as the longest text

I open this post after I looked at this post without success: How to set table column widths to the longest value, excluding header
I want to draw a table, and I want that the width of each column will be compatible to the longest text in this column. For example, if the following values lie in column A: "abc", "abcd", "abcde", the width of column A will be 5 characters long.
I tried:
td {
white-space: nowrap;
overflow: hidden;
}
How can I do it?
I think that's the default behavior of tables. Have made a simple table that just behaves as you want it (refer this JSFiddle). The column width is equal to the longest text in them.
<table>
<thead>
<th>Column A</th>
<th>Column B</th>
</thead>
<tbody>
<tr>
<td>abc</td> <td>abcdefghijklm</td>
</tr>
<tr>
<td>abcdefghijklmno ddsp</td> <td>ab</td>
</tr>
<tr>
<td>ab</td> <td>ab</td>
</tr>
</tbody>
</table>
Not sure if you wanted to ask something else ?
Add this styling to your table and td:
table {
table-layout:fixed;
}
td {
width:1px;
white-space:nowrap;
}
If this doesn't work, make sure that these are the only styling attributes being set to your table and td. This will help you figure out if other styling attributes are causing conflicts ruining the mentioned styling you want to achieve.
On a similar issue happened with me, these styling attributes weren't working with me because I was setting width attribute to the table with them. When I removed it, everything worked good as expected.
A quote from the original post I got the solution from:
If the text is non wrapping text then you set the cell to width:1px and use white-space:nowrap. The text in that column will then determine the width of the cell.
It's a technique commonly used for images and captions (without the white-space:nowrap) and allows text to wrap at the limits of an image automatically.
Try styling the text to not wrap:
{
white-space: nowrap;
overflow: hidden;
}
And do not set width settings on your table, tr and td elements.
See if that works.

ASP.NET Web Form not taking up entire screen in FireFox and Chrome but does in IE

We have an asp.net master page that defines our web application layout using Tables. The goal is to have the content page take up the entire available screen real estate after having displayed the header and footer. This works for us fine in IE but does not work as intended in Chrome or FireFox.
What happens with Chrome and FireFox is that the content section expands only to wrap the content, which, in instances like a welcome screen ends up taking only a small portion of the screen leaving a big blank section at the bottom of the screen.
Here is a basic example of how our layout is structured:
<table style=height:80%;width:100%" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td colspan="2">
<!--Header Banner goes here This displays fine-->
</td>
</tr>
<tr style="height:100%" valign="top">
<!--Content Goes Here. Problem is that page only expands
as much as its content section vs filling up the whole page. -->
</tr>
<tr>
<!--Footer Goes here. This works fine!!-->
</tr>
</tbody>
</table>
Your problem is that you're using tables for layout. This would be easily achieved with proper HTML using something like a sticky footer (http://ryanfait.com/sticky-footer).
I'd recommend grabbing the HTML5 boilerplate or similar (http://html5boilerplate.com) and working from there.
If this is an existing web app that you can't change the HTML of then Javascript might be a solution...
There is no good way to specify in CSS that a element should be at least as high as the screen. You have to resort to JavaScript.
Since determining the height of the client are of the screen is again something that every browser version might do slightly differently, it is safest to use jQuery:
// tableID is the ID of your element that you want to take up the space
$("#tableID").height($(window).height());
You are missing some <td></td> and " in your code.
Also add
html,body {
height:100%;
min-height:100%;
}
to the StyleSheet. And HTML is
<table style="height:80%;width:100%;background-color:yellow" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td colspan="2" style="background-color:red">
Header Banner goes here This displays fine
</td>
</tr>
<tr valign="top">
<td style="background-color:green;height:100%">Content Goes Here. Problem is that page only expands as much as its content section vs filling up the whole page.</td>
</tr>
<tr>
<td style="background-color:blue">Footer Goes here. This works fine!!</td>
</tr>
</tbody>
</table>
Live preview >> jsfiddle
Set margin-top:0px in your content tr tag

Floating table cells in IE7

I am currently re-styling a site but unforunately I am unable to edit any of the markup, which leads me to the following problem...
I have a table, similar to this:
<table>
<tr>
<td>Some content</td>
<td>Some content</td>
</tr>
<tr>
<td>Some content</td>
<td>Some content</td>
</tr>
<tr>
<td>Some content</td>
<td>Some content</td>
</tr>
</table>
and I want to display all the table cells on one line. In good browsers, I'm using:
table tr {
display: inline;
float: left;
}
to achieve this. However, this doesn't work in IE7. Is there any other CSS I can use to achieve the same effect? I have to stress that I have no access to the markup whatsoever and none of the table rows or cells have any way of accessing them directly so there's no way I can position absolutely.
You can't do that, I believe.
A tr is a table row and I'd expect the unexpected when trying to float one.
Besides, any element floated is instantly a block level element, so display: inline is redundant.
(The only exception when using it to prevent double margin bug in IE6 - but only if you have a margin set).
You could restructure the HTML with JavaScript, but I would not recommend you do that:)
I agree with #Pekka that this is illegal. The best course of action here would be to add small js to transform table into somethings else. If you have access to just css you can still do that for IEs by adding a behavior and for other browser if that work - just use your solution.
You can attempt inline-block but styling table elements with things such as float is a sin. You can attempt hiding the entire table and insert some load of loading icon while you extract the table info and display it with semantic markup.
Best course of action in this case is to ask for access. Just say you can't do the work without access to the markup. If they won't let you, just don't do the work.

Padding on a table not working

I'm trying to give even spacing all around images I have in a table, and it's not working too well.
Look at the page. I tried margin, padding, everything I could on lots of different types of properties, but no luck. Any help?
The table has been created in an unusual way by photoshop - resulting in dodgey markup.
There a differing amount of <td>'s in the first row compared to the others
There are several spacer images which have been created by photoshop; which are redundant
There should be no need for the use of rowspans in your <td>'s
To fix this issue I would suggest modifying your table so the structure looks like this:
<table cellpadding="5">
<tr>
<td><img src="images/index_01.png" width="463" height="200" alt=""></td>
<td ><img src="images/index_02.png" width="465" height="200" alt=""></td>
</tr>
....
Then keep adding blocks of table rows e.g.:
<tr>
<td>... </td>
<td>...</td>
</tr>
with your links and images replacing the '...'. then finally close the table:
</table>
Hope this helps.
The problem is your rowspan="2" on your second cell... remove that and the spacing evens out. You may also want the following CSS (tested with Firefox/firebug rewrites)
<style>
#Table_01,#Table_01 a {margin:0;padding:0;}
#Table_01 img {padding:1em;}
</style>
Try specifying value for cellpadding attribute for the table.
Your markup is all wrong. You have TDs using rowspan when its not needed and i see some spacer gifs. Fix the markup and you wont have any issues with using cellpadding

Resources