Using "word-wrap: break-word" within a table [duplicate] - css

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Word-wrap in a html table
This text behaves exactly the way I want on Google Chrome (and other modern browsers):
<div style="border: 1px solid black; width:100%; word-wrap: break-word;">
<p>
aaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
</p>
</div>
When the browser is wide enough, a+ and b+ are on the same line.
aaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
As you narrow the browser, a+ and b+ are put on separate lines.
aaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
When b+ can no longer fit, it is broken and put on two lines (for a total of three lines).
aaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbb
That's all great.
In my situation, however, this is not a div but a table, like so:
<table style="border:1px solid black; width:100%; word-wrap:break-word;">
<tr>
<td>
<p>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
</p>
</td>
</tr>
</table>
In this case, #1 and #2 happen, but not #3. That is, the table stops narrowing after step 2 and step 3 doesn't ever happen. The break-word doesn't seem to be filtering down.
Does anyone know how make #3 happen? The solution only need work in Chrome, but it it also worked in other browsers that would be even better.
P.S. "Don't use tables" is not helpful.

table-layout: fixed will get force the cells to fit the table (and not the other way around), e.g.:
<table style="border: 1px solid black; width: 100%; word-wrap:break-word;
table-layout: fixed;">
<tr>
<td>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
</td>
</tr>
</table>

You can try this:
td p {word-break:break-all;}
This, however, makes it appear like this when there's enough space, unless you add a <br> tag:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
So, I would then suggest adding <br> tags where there are newlines, if possible.
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
http://jsfiddle.net/LLyH3/3/
Also, if this doesn't solve your problem, there's a similar thread here.

Related

How to make a title span over two columns in html?

I'm trying to construct 3-columned page like this:
Is it possible to make a title to span over only two columns?
Using exclusions gives no result=( I'm stuck!
I need to do 3 columns with floating text:
-webkit-column-count: 3;
-webkit-column-gap: 1em;
-webkit-column-rule: 2px solid #B8B8B8;
so using table is not a solution
CSS3 offers column-count specifically for this purpose but unfortunately it's not supported in old browsers.
.newspaper
{
-moz-column-count:2; /* Firefox */
-webkit-column-count:2; /* Safari and Chrome */
column-count:2;
}
DEMO
You can use DIV with style float:left to place 2 columns next to each other. And the DIV with title could go above them.
Demo: http://jsfiddle.net/6cttL/
I needed the solution to this exact problem and found this at kmsm.ca:
Spanning columns
If we want an element, say a headline, to span across multiple columns we can make use of the new column-span property.
column-span has two possible values: all, and regular numbers (e.g. 1,2,3). Defining column-span as all means that the given element will span across the whole multi-column block, while assigning it a regular number will limit its span to that number of columns:
h2 {
-webkit-column-span:all;
-moz-column-span:all;
column-span:all;
}
hope that helps
update - this worked in Chrome but not Firefox
What about using a table with colspan?
<table>
<tr>
<td colspan="2" id="title">
</td>
</tr>
<tr>
<td id="firstcolumn">
</td>
<td id="secondcolumn">
</td>
</tr>
</table>
I'm not sure what your document structure is beneath that image, but a common technique is to place a 'wrapper' div around blocks of content to simplify their layout.
So, you'd place the far right content in a div, then everything on the left in a div. Within the left div, you'd have your heading, then below it, a div that contained the two columns.
<div id="rightMain">...</div> &lt!--Float right-->
<div id="leftMain">
<h2>Article Title</h2>
<div id="article">
<div id="leftArticleCol">...</div>
<div id="rightArticleCol">...</div>
</div>
</div>

:before pseudo-element causes gap in border

I have this piece of HTML that I want to style.
The html is a table (and actual table), which I want to give a border.
The element also had a :before pseudo-element, which I use to put a small triangle in the top corner.
The JSFiddle is here.
I hope it makes sense. I stripped down the markup and the CSS as much as possible, because it's actually a small part of a big site.
http://jsfiddle.net/GolezTrol/28yDb/2/
Now the problem is that the combination of having 2 columns, having border-collapse: collapse; on the table and the :before pseudo element, cause the top border of the element to partially disappear. It's only there for the length of the first column.
You would assume that it is the pseudo element that is on top of the border, but this element is very small, and as far as I can tell, this could not be the problem. I added visibility: hidden; to the pseudo element to be sure, and I can tell that the triangle is gone, but the border is still incomplete.
Unfortunately I cannot change the markup, since this is outputted by MediaWiki, but I do have full control over the CSS.
The HTML:
<div id="globalWrapper">
<div id="column-content">
<div class="thumb tright">
<table class="infobox vcard" style="">
<tbody>
<tr>
<th colspan="2" class="fn org" style=""> Example text</th>
</tr>
<tr>
<th>Row head</th>
<td>Content</td>
</tr>
The CSS:
/* Generic table styling */
table {
border-collapse: collapse;
/*border-spacing: 0;*/ }
/* The box */
.thumb.tright table.infobox.vcard {
border: 3px solid #fae104;
position: relative;
}
/* Triangle */
.thumb.tright table.infobox.vcard:before {
content: "";
position: absolute;
width: 0;
height: 1px;
border-top: 5px solid transparent;
top: -7px;
border-left: 10px solid #555;
visibility: hidden;
right: -1px; }
I already found out that it works when I remove border-collapse: collapse;, but I'm not sure that is a proper solution, and even if it is, I would really like an explanation of what is going on.
Btw. I got this problem both in Chrome 29 and in Internet Explorer 10. Haven't tested other browsers.
Update
Instead of using -or not using- 'border-collapse' to fix the problem, I found out that this also works:
.thumb.tright table.infobox.vcard tbody {
display: block;
}
So the table itself is still a table, the pseudo element is still on the table, as is the border, positioning etc. The tbody, which was unstyled before, is now a block and the problem is solved in both browsers. I found this by trial and error, and still wouldn't know the reason behind it.
Updated fiddle: http://jsfiddle.net/GolezTrol/28yDb/9/
Being a newbie to StackOverflow and jsFiddle I updated the Fiddle with that I think is the solution. I didn't change the CSS except for moving the pseudo class from the table itself to the table header, and changing it into :after. Works for me in Firefox and Chrome!
/* Triangle */
.thumb.tright table.infobox.vcard th:after { }
Border-collapse: seperate is not supported in IE8 but I think this will be.
edit: nevermind ;)
It is a problem only occur on Webkit browsers I think. It can be considered a "browser bug" imo.
th should be inside thead, not tbody:
<thead>
<tr>
<th colspan="2" class="fn org" style=""> Example text</th>
</tr>
</thead>
<tbody>
<tr>
<th>Row head</th>
<td>Content</td>
</tr>
<tbody>
And I think this is the correct solution. You are putting an element where it is not advised to be, so it should be normal for a problem to occur.
Edit: as thirtydot pointed out, changing the th to td doesn't change the result. It only work when I moved the th to the thead section. At this point I am at a loss, I can't find a way to solve this.
But at least I think I can provide my speculation on the cause of this problem:
:before create a pseudo element inside the target element. What kind of element is unknown to me, but I suspect that the browser create a td. If that is true, then after rendering your html should look like this:
<table>
<td></td> /*the pseudo element*/
<tbody>
<tr>
<th colspan="2" class="fn org" style=""> Example text</th>
</tr>
<tr>
<th>Row head</th>
<td>Content</td>
</tr>
<tbody>
</table>
Needless to say this look weird. And if you try the above html out you can see the result is similar to your problem. border-collapse:collapse will merge 2 borders together where there are 2 cells next to each other, or a cell is next to the table's border. So I suspect in this case, the pseudo element - which doesn't have appropriate colspan - last only 1 column, the rest of that row is empty: nothing's there. This is where I think caused the bug: because there's no cells next to the table border there, no border is created at all.
The real reason may be a little bit more complicated ("why doesn't the bug occur when I put in a thead?"), but I think my answer is not too far off the mark. :)
The only reasonable explanation I can think of is pseudo-element :before not being compatible with the display: table of the table in collapsed mode. That is why border-collapse: separate; solves the problem. Suddenly, the browser can display the top border not caring about the pseudo element.
If you look closely, you can clearly see that the missing part of the border is the width of the second column. If you change it to after pseudo element, the border is missing in the bottom-right corner, again due to the fact that the borders of the table and the pseudo-element are collapsed.
If you change the border-bottom of th to be 3px solid red in collapsed mode, the th overpowers the table and the border is red. I presume, the power of after and before follow the same rule. It would be nice if someone who knows the specs better came to answer that.
Thinking this way, I do not believe there can be any other solution than:
using separate borders
putting the pseudo element on the parent div
What I inspected is that the pseudo element is actually rendered as block and can be change to table and list-item. However, none of these change the behaviour.
Very random stuff that is actually compliant with Av Avt's answer about where the pseudo element is rendered in regards of the DOM.
If I append the :beofre like this, the border stays:
.thumb.tright table.infobox.vcard tr:before
Obviously, it creates as many new pseudo element as there are rows.

CSS - bottom border around a TD gets cut off when browser is resized

I have a web app that uses bootstrap to make it mobile friendly.
In an attempt to visually group 3 items together, I have created a class the puts a box / border around the table cell where these three items appear. (the three items are link4, 5 and 5)
Here's the class:
td.lights
{
border: 2px solid black;
}
And here's the problematic HTML - I've paired it down to the minimum code, just for demo purposes.
What I'm noticing is that when I simulate a mobile device (using Firefox's Responsive design view tool) the bottom of the
<table>
<tbody>
<tr>
<td>link1</td>
<td>link2</td>
<td>link3</td>
<td> </td>
<td class="lights">link4 / link5 / link6</td>
</p>
</tbody>
</table>
Immediately after this table, I have this code to create another table:
<P>
<table class="table table-bordered table-striped">
<thead>
etc...
</thead>
</table>
When i resize my browser, the border on the bottom of my in table 1 gets cut off, depending on how small by browser size gets. The other fields look fine, but then again, they don't have a border around them. To me, it looks like there's a fixed set of space above and below my text ("link4 / link5 / link6") that is not dynamically changing.
I've tried adding a height "dynamic" height property to my td like so:
td.lights
{
border: 2px solid black;
height: 1em;
}
But that didn't resolve my problem.
Any suggestions? Please and thanks!
As far as I can tell you have quite a few errors in your markup:
</p>
Should be:
</tr>
Also, should you have a:
<P>
Before your second table? I would avoid wrapping your tables with P tags as this will add unwanted padding and doesn't make sense from a semantic perspective.
Fix those first and see what happens. Secondly I would recommend - when dealing with tables - to use the following:
<table cellpadding="0" cellspacing="0" border="0">
You can also do this in CSS with the following:
table, tr, td { margin: 0; padding: 0; border: 0; }
This should make sure you have no unwanted padding in and around your cells.

Table style in CSS

I currently have a little HTML page with following HTML/CSS codes inside.
<table style="width: 300px;">
<tr style="height: 120px;">
<td width="width: 100px;">
<img src="images/lol/avatars/3.png" style="vertical-align: middle; width: 100px; height: 100px;">
<img src="images/score/3.png" style="display: block; background: #0c0c0c;" alt="3" title="5 üzerinden 3" />
</td>
<td width="width: 200px;">
aaaa bbb cccc ddddd
<h2 style="font-size: 1.6em; text-shadow: 0 -1px 1px #0c0c0c; text-transform: none; color: #fcfcfc; ">Anil wrote.<h2>
</td>
</tr>
</table>
The current output is:
(Live example is here: http://www.sobafire.com, under the right side of slider.)
The picture pretty much explains what I need, but I'll write them regardless.
The text at top (aaa bbb...) should be centered. Also, it should automatically keep centering itself if the text is long. (It shouldn't go upside or downside, it should be going upside by %50 and downside by %50.)
The "score" image with stars has a background color, which is "#0c0c0c". It should be the background color of entire bottom area, including "Anil wrote." text.
"Anil wrote." text should be aligned to right side.
I'll be glad if you can help me in this case.
Ps. There will be 3x TR in the current table, not a single like this. It won't make a difference but just a side note.
Ps 2. Live example added for users who would like to see it live.
Use two TR for this, first row has the main image and the "aaaa bbb cccc ddddd"
Second row has the stars and the "Anil wrote" info
you will probably need a rowspan=2 for the first column.
Sorry, forget about the rowspan.
Then if you have additional rows, just add them at the end, so you might have 4x TR and not 3.
Move all of your style items to a CSS style sheet
In general div is a better choice for layout, but you will find various points of view on this topic.
Tables should be used for tablular data, not for layout.
Harv
You need to add another <tr> containing two td's one with the rating and one with the 'Anil wrote' bit.
then you can add text-align: center to the comment td
I would suggest you to add another <tr> and <td> and use valign:xxx; and align:xxx;
CSS on divs and spans will work fine

CSS text over flow why isn't this working

I want the text in the header to be shortned with ellipses. but it doesn't the whole address shows in one line
<table border="0" style="font-weight:normal; position: absolute; top:45; left: 0;">
<th align="left" style="" width="10%">
<span style=" overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width:10px; font-weight:normal; white;"
onclick="dropdownResize()"><i>Address</i> <b>${bean.address}</b></span>
</th>
<tr >
<td style=" border-style:solid; border-width:0px; text-transform:capitalize; text-indent:1px;">
</br>
<br>Usual address <br><b>${bean.address}</b></br> <br> 
</td>
</tr>
</table>
You have a lot of stuff wrong with your code,
For a start you are using <b> <i> as well as using <table>s to layout your content (which is by the way a bad practise) AND you are using <br> </br> which aren't even real tags - the tag you are looking for is <br/> - It is a self closing tag as it can never contain any arguments or content.
The <span> tags you have chose to use do not support the width parameter as they just wrap the text that is contained within them and as such I have changed this to a <div> and changed all your <b> and <i> tags to <span> tags with CSS classes attached to them.
I have fixed up your coding here:
Live Demo
As for your table layout I suggest you read a few of these:
http://shouldiusetablesforlayout.com/
http://www.hotdesign.com/seybold/
http://webdesign.about.com/od/layout/a/aa111102a.htm
http://www.htmlgoodies.com/beyond/css/article.php/3642151/CSS-Layouts-Without-Tables.htm
Next up, support:
FF4 does not support the text-overflow:ellipsis as it used to in FF3.6 via a hack, see here for further info:
text-overflow:ellipsis in Firefox 4? (and FF5)
You're using a <span> which by default is an inline element and cannot receive width, height, etc like block level elements.
To change this, either use a div or add display: block; to your span's style.
Try adding display:block to the style on the span tag.
Make sure you test it in supported browsers: http://www.quirksmode.org/css/textoverflow.html
Firefox doesn't support ellipsis.

Resources