force line break in html table cell
up vote
19
down vote
favorite
I'm trying to find a way to force line break in table cell after text inside of it will become longer than say 50% of max allowed size.
How can I do it without any JS function, using just pure HTML with CSS?
html css
add a comment |
up vote
19
down vote
favorite
I'm trying to find a way to force line break in table cell after text inside of it will become longer than say 50% of max allowed size.
How can I do it without any JS function, using just pure HTML with CSS?
html css
@Phil its onebiglonglineoftext so ideas given here should be enough
– dantuch
Jul 27 '11 at 11:30
it will not work if it is only one single word (see jsfiddle.net/NweWX)
– Fender
Jul 27 '11 at 11:34
2
@Fender, thanks... - it works fine with added something like<td style="word-wrap: break-word" width="100">
– dantuch
Jul 27 '11 at 12:33
@dantuch can it work on IE 7+ ?
– Salman Mushtaq
Feb 20 '17 at 6:51
add a comment |
up vote
19
down vote
favorite
up vote
19
down vote
favorite
I'm trying to find a way to force line break in table cell after text inside of it will become longer than say 50% of max allowed size.
How can I do it without any JS function, using just pure HTML with CSS?
html css
I'm trying to find a way to force line break in table cell after text inside of it will become longer than say 50% of max allowed size.
How can I do it without any JS function, using just pure HTML with CSS?
html css
html css
edited Nov 26 '13 at 0:06
Simon East
32k11101100
32k11101100
asked Jul 27 '11 at 11:15
dantuch
7,12843463
7,12843463
@Phil its onebiglonglineoftext so ideas given here should be enough
– dantuch
Jul 27 '11 at 11:30
it will not work if it is only one single word (see jsfiddle.net/NweWX)
– Fender
Jul 27 '11 at 11:34
2
@Fender, thanks... - it works fine with added something like<td style="word-wrap: break-word" width="100">
– dantuch
Jul 27 '11 at 12:33
@dantuch can it work on IE 7+ ?
– Salman Mushtaq
Feb 20 '17 at 6:51
add a comment |
@Phil its onebiglonglineoftext so ideas given here should be enough
– dantuch
Jul 27 '11 at 11:30
it will not work if it is only one single word (see jsfiddle.net/NweWX)
– Fender
Jul 27 '11 at 11:34
2
@Fender, thanks... - it works fine with added something like<td style="word-wrap: break-word" width="100">
– dantuch
Jul 27 '11 at 12:33
@dantuch can it work on IE 7+ ?
– Salman Mushtaq
Feb 20 '17 at 6:51
@Phil its onebiglonglineoftext so ideas given here should be enough
– dantuch
Jul 27 '11 at 11:30
@Phil its onebiglonglineoftext so ideas given here should be enough
– dantuch
Jul 27 '11 at 11:30
it will not work if it is only one single word (see jsfiddle.net/NweWX)
– Fender
Jul 27 '11 at 11:34
it will not work if it is only one single word (see jsfiddle.net/NweWX)
– Fender
Jul 27 '11 at 11:34
2
2
@Fender, thanks... - it works fine with added something like
<td style="word-wrap: break-word" width="100">
– dantuch
Jul 27 '11 at 12:33
@Fender, thanks... - it works fine with added something like
<td style="word-wrap: break-word" width="100">
– dantuch
Jul 27 '11 at 12:33
@dantuch can it work on IE 7+ ?
– Salman Mushtaq
Feb 20 '17 at 6:51
@dantuch can it work on IE 7+ ?
– Salman Mushtaq
Feb 20 '17 at 6:51
add a comment |
5 Answers
5
active
oldest
votes
up vote
34
down vote
accepted
I think what you're trying to do is wrap loooooooooooooong words or URLs so they don't push the size of the table out. (I've just been trying to do the same thing!)
You can do this easily with a DIV by giving it the style word-wrap: break-word
(and you may need to set its width, too).
div {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
width: 100%;
}
However, for tables, you must either wrap the content in a DIV (or other block tag) or apply: table-layout: fixed
. This means the columns widths are no longer fluid, but are defined based on the widths of the columns in the first row only (or via specified widths). Read more here.
Sample code:
table {
table-layout: fixed;
width: 100%;
}
table td {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
}
Hope that helps somebody.
1
I nested a long word inside a nested table using a div styled with break-word. It did not require table-layout:fixed style. Thanks for a solution that works in IE, Chrome and FF : )
– davidjmcclelland
Dec 2 '13 at 17:26
Hi David - yes if your content is inside a DIV (which is inside a table) then the first snippet is adequate.
– Simon East
Dec 2 '13 at 21:59
thanks, changed accepted to this1
– dantuch
Dec 20 '16 at 13:38
add a comment |
up vote
10
down vote
I suggest you use a wrapper div or paragraph:
<td><p style="width:50%;">Text only allowed to extend 50% of the cell.</p></td>
And you can make a class out of it:
<td class="linebreak"><p>Text only allowed to extend 50% of the cell.</p></td>
td.linebreak p {
width: 50%;
}
All of this assuming that you meant 50% as in 50% of the cell.
2
Ah, sorry for late update, but as @Fender commented, it do not help, if I want to break single,tolonglineoftext. And that's the real issue.
– dantuch
Jul 27 '11 at 11:45
How to center this text?
– zygimantus
Jan 19 '16 at 7:39
add a comment |
up vote
3
down vote
You could put the text into a div (or other container) with a width of 50%.
http://jsfiddle.net/6gjsd/
add a comment |
up vote
1
down vote
It's hard to answer you without the HTML, but in general you can put:
style="width: 50%;"
On either the table cell, or place a div inside the table cell, and put the style on that.
But one problem is "50% of what?" It's 50% of the parent element which may not be what you want.
Post a copy of your HTML and maybe you'll get a better answer.
add a comment |
up vote
0
down vote
Try using
<table border="1" cellspacing="0" cellpadding="0" class="template-table"
style="table-layout: fixed; width: 100%">
as table style along with
<td style="word-break:break-word">long text</td>
for td
it works for normal/real scenario text with words, not for random typed letters without gaps
add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
34
down vote
accepted
I think what you're trying to do is wrap loooooooooooooong words or URLs so they don't push the size of the table out. (I've just been trying to do the same thing!)
You can do this easily with a DIV by giving it the style word-wrap: break-word
(and you may need to set its width, too).
div {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
width: 100%;
}
However, for tables, you must either wrap the content in a DIV (or other block tag) or apply: table-layout: fixed
. This means the columns widths are no longer fluid, but are defined based on the widths of the columns in the first row only (or via specified widths). Read more here.
Sample code:
table {
table-layout: fixed;
width: 100%;
}
table td {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
}
Hope that helps somebody.
1
I nested a long word inside a nested table using a div styled with break-word. It did not require table-layout:fixed style. Thanks for a solution that works in IE, Chrome and FF : )
– davidjmcclelland
Dec 2 '13 at 17:26
Hi David - yes if your content is inside a DIV (which is inside a table) then the first snippet is adequate.
– Simon East
Dec 2 '13 at 21:59
thanks, changed accepted to this1
– dantuch
Dec 20 '16 at 13:38
add a comment |
up vote
34
down vote
accepted
I think what you're trying to do is wrap loooooooooooooong words or URLs so they don't push the size of the table out. (I've just been trying to do the same thing!)
You can do this easily with a DIV by giving it the style word-wrap: break-word
(and you may need to set its width, too).
div {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
width: 100%;
}
However, for tables, you must either wrap the content in a DIV (or other block tag) or apply: table-layout: fixed
. This means the columns widths are no longer fluid, but are defined based on the widths of the columns in the first row only (or via specified widths). Read more here.
Sample code:
table {
table-layout: fixed;
width: 100%;
}
table td {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
}
Hope that helps somebody.
1
I nested a long word inside a nested table using a div styled with break-word. It did not require table-layout:fixed style. Thanks for a solution that works in IE, Chrome and FF : )
– davidjmcclelland
Dec 2 '13 at 17:26
Hi David - yes if your content is inside a DIV (which is inside a table) then the first snippet is adequate.
– Simon East
Dec 2 '13 at 21:59
thanks, changed accepted to this1
– dantuch
Dec 20 '16 at 13:38
add a comment |
up vote
34
down vote
accepted
up vote
34
down vote
accepted
I think what you're trying to do is wrap loooooooooooooong words or URLs so they don't push the size of the table out. (I've just been trying to do the same thing!)
You can do this easily with a DIV by giving it the style word-wrap: break-word
(and you may need to set its width, too).
div {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
width: 100%;
}
However, for tables, you must either wrap the content in a DIV (or other block tag) or apply: table-layout: fixed
. This means the columns widths are no longer fluid, but are defined based on the widths of the columns in the first row only (or via specified widths). Read more here.
Sample code:
table {
table-layout: fixed;
width: 100%;
}
table td {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
}
Hope that helps somebody.
I think what you're trying to do is wrap loooooooooooooong words or URLs so they don't push the size of the table out. (I've just been trying to do the same thing!)
You can do this easily with a DIV by giving it the style word-wrap: break-word
(and you may need to set its width, too).
div {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
width: 100%;
}
However, for tables, you must either wrap the content in a DIV (or other block tag) or apply: table-layout: fixed
. This means the columns widths are no longer fluid, but are defined based on the widths of the columns in the first row only (or via specified widths). Read more here.
Sample code:
table {
table-layout: fixed;
width: 100%;
}
table td {
word-wrap: break-word; /* All browsers since IE 5.5+ */
overflow-wrap: break-word; /* Renamed property in CSS3 draft spec */
}
Hope that helps somebody.
edited Dec 2 '13 at 22:03
answered Nov 26 '13 at 0:19
Simon East
32k11101100
32k11101100
1
I nested a long word inside a nested table using a div styled with break-word. It did not require table-layout:fixed style. Thanks for a solution that works in IE, Chrome and FF : )
– davidjmcclelland
Dec 2 '13 at 17:26
Hi David - yes if your content is inside a DIV (which is inside a table) then the first snippet is adequate.
– Simon East
Dec 2 '13 at 21:59
thanks, changed accepted to this1
– dantuch
Dec 20 '16 at 13:38
add a comment |
1
I nested a long word inside a nested table using a div styled with break-word. It did not require table-layout:fixed style. Thanks for a solution that works in IE, Chrome and FF : )
– davidjmcclelland
Dec 2 '13 at 17:26
Hi David - yes if your content is inside a DIV (which is inside a table) then the first snippet is adequate.
– Simon East
Dec 2 '13 at 21:59
thanks, changed accepted to this1
– dantuch
Dec 20 '16 at 13:38
1
1
I nested a long word inside a nested table using a div styled with break-word. It did not require table-layout:fixed style. Thanks for a solution that works in IE, Chrome and FF : )
– davidjmcclelland
Dec 2 '13 at 17:26
I nested a long word inside a nested table using a div styled with break-word. It did not require table-layout:fixed style. Thanks for a solution that works in IE, Chrome and FF : )
– davidjmcclelland
Dec 2 '13 at 17:26
Hi David - yes if your content is inside a DIV (which is inside a table) then the first snippet is adequate.
– Simon East
Dec 2 '13 at 21:59
Hi David - yes if your content is inside a DIV (which is inside a table) then the first snippet is adequate.
– Simon East
Dec 2 '13 at 21:59
thanks, changed accepted to this1
– dantuch
Dec 20 '16 at 13:38
thanks, changed accepted to this1
– dantuch
Dec 20 '16 at 13:38
add a comment |
up vote
10
down vote
I suggest you use a wrapper div or paragraph:
<td><p style="width:50%;">Text only allowed to extend 50% of the cell.</p></td>
And you can make a class out of it:
<td class="linebreak"><p>Text only allowed to extend 50% of the cell.</p></td>
td.linebreak p {
width: 50%;
}
All of this assuming that you meant 50% as in 50% of the cell.
2
Ah, sorry for late update, but as @Fender commented, it do not help, if I want to break single,tolonglineoftext. And that's the real issue.
– dantuch
Jul 27 '11 at 11:45
How to center this text?
– zygimantus
Jan 19 '16 at 7:39
add a comment |
up vote
10
down vote
I suggest you use a wrapper div or paragraph:
<td><p style="width:50%;">Text only allowed to extend 50% of the cell.</p></td>
And you can make a class out of it:
<td class="linebreak"><p>Text only allowed to extend 50% of the cell.</p></td>
td.linebreak p {
width: 50%;
}
All of this assuming that you meant 50% as in 50% of the cell.
2
Ah, sorry for late update, but as @Fender commented, it do not help, if I want to break single,tolonglineoftext. And that's the real issue.
– dantuch
Jul 27 '11 at 11:45
How to center this text?
– zygimantus
Jan 19 '16 at 7:39
add a comment |
up vote
10
down vote
up vote
10
down vote
I suggest you use a wrapper div or paragraph:
<td><p style="width:50%;">Text only allowed to extend 50% of the cell.</p></td>
And you can make a class out of it:
<td class="linebreak"><p>Text only allowed to extend 50% of the cell.</p></td>
td.linebreak p {
width: 50%;
}
All of this assuming that you meant 50% as in 50% of the cell.
I suggest you use a wrapper div or paragraph:
<td><p style="width:50%;">Text only allowed to extend 50% of the cell.</p></td>
And you can make a class out of it:
<td class="linebreak"><p>Text only allowed to extend 50% of the cell.</p></td>
td.linebreak p {
width: 50%;
}
All of this assuming that you meant 50% as in 50% of the cell.
answered Jul 27 '11 at 11:18
orlp
66.1k26156245
66.1k26156245
2
Ah, sorry for late update, but as @Fender commented, it do not help, if I want to break single,tolonglineoftext. And that's the real issue.
– dantuch
Jul 27 '11 at 11:45
How to center this text?
– zygimantus
Jan 19 '16 at 7:39
add a comment |
2
Ah, sorry for late update, but as @Fender commented, it do not help, if I want to break single,tolonglineoftext. And that's the real issue.
– dantuch
Jul 27 '11 at 11:45
How to center this text?
– zygimantus
Jan 19 '16 at 7:39
2
2
Ah, sorry for late update, but as @Fender commented, it do not help, if I want to break single,tolonglineoftext. And that's the real issue.
– dantuch
Jul 27 '11 at 11:45
Ah, sorry for late update, but as @Fender commented, it do not help, if I want to break single,tolonglineoftext. And that's the real issue.
– dantuch
Jul 27 '11 at 11:45
How to center this text?
– zygimantus
Jan 19 '16 at 7:39
How to center this text?
– zygimantus
Jan 19 '16 at 7:39
add a comment |
up vote
3
down vote
You could put the text into a div (or other container) with a width of 50%.
http://jsfiddle.net/6gjsd/
add a comment |
up vote
3
down vote
You could put the text into a div (or other container) with a width of 50%.
http://jsfiddle.net/6gjsd/
add a comment |
up vote
3
down vote
up vote
3
down vote
You could put the text into a div (or other container) with a width of 50%.
http://jsfiddle.net/6gjsd/
You could put the text into a div (or other container) with a width of 50%.
http://jsfiddle.net/6gjsd/
answered Jul 27 '11 at 11:19
Jamie Dixon
36.9k13103144
36.9k13103144
add a comment |
add a comment |
up vote
1
down vote
It's hard to answer you without the HTML, but in general you can put:
style="width: 50%;"
On either the table cell, or place a div inside the table cell, and put the style on that.
But one problem is "50% of what?" It's 50% of the parent element which may not be what you want.
Post a copy of your HTML and maybe you'll get a better answer.
add a comment |
up vote
1
down vote
It's hard to answer you without the HTML, but in general you can put:
style="width: 50%;"
On either the table cell, or place a div inside the table cell, and put the style on that.
But one problem is "50% of what?" It's 50% of the parent element which may not be what you want.
Post a copy of your HTML and maybe you'll get a better answer.
add a comment |
up vote
1
down vote
up vote
1
down vote
It's hard to answer you without the HTML, but in general you can put:
style="width: 50%;"
On either the table cell, or place a div inside the table cell, and put the style on that.
But one problem is "50% of what?" It's 50% of the parent element which may not be what you want.
Post a copy of your HTML and maybe you'll get a better answer.
It's hard to answer you without the HTML, but in general you can put:
style="width: 50%;"
On either the table cell, or place a div inside the table cell, and put the style on that.
But one problem is "50% of what?" It's 50% of the parent element which may not be what you want.
Post a copy of your HTML and maybe you'll get a better answer.
answered Jul 27 '11 at 11:19
Ariel
19.9k34264
19.9k34264
add a comment |
add a comment |
up vote
0
down vote
Try using
<table border="1" cellspacing="0" cellpadding="0" class="template-table"
style="table-layout: fixed; width: 100%">
as table style along with
<td style="word-break:break-word">long text</td>
for td
it works for normal/real scenario text with words, not for random typed letters without gaps
add a comment |
up vote
0
down vote
Try using
<table border="1" cellspacing="0" cellpadding="0" class="template-table"
style="table-layout: fixed; width: 100%">
as table style along with
<td style="word-break:break-word">long text</td>
for td
it works for normal/real scenario text with words, not for random typed letters without gaps
add a comment |
up vote
0
down vote
up vote
0
down vote
Try using
<table border="1" cellspacing="0" cellpadding="0" class="template-table"
style="table-layout: fixed; width: 100%">
as table style along with
<td style="word-break:break-word">long text</td>
for td
it works for normal/real scenario text with words, not for random typed letters without gaps
Try using
<table border="1" cellspacing="0" cellpadding="0" class="template-table"
style="table-layout: fixed; width: 100%">
as table style along with
<td style="word-break:break-word">long text</td>
for td
it works for normal/real scenario text with words, not for random typed letters without gaps
edited Nov 8 at 11:05
answered Nov 8 at 11:00
Vee_Sa
12
12
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6843412%2fforce-line-break-in-html-table-cell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@Phil its onebiglonglineoftext so ideas given here should be enough
– dantuch
Jul 27 '11 at 11:30
it will not work if it is only one single word (see jsfiddle.net/NweWX)
– Fender
Jul 27 '11 at 11:34
2
@Fender, thanks... - it works fine with added something like
<td style="word-wrap: break-word" width="100">
– dantuch
Jul 27 '11 at 12:33
@dantuch can it work on IE 7+ ?
– Salman Mushtaq
Feb 20 '17 at 6:51