HTML to adjust the width
You may have a problem when you adjust width HTML (pre tag , table tag).
It might be a very rudimentary thing. However, you may not be able to clear its problem.
Following content might help you.
Table width problem
In general, It might be thought that it only has to set it because table tag has attribute of width.
TABLE is, width (width), so it can be specified, can be fixed?
In fact, I also had thought so before. ()
For example, let’s think following sample code.
|
Example
Column 1 | Column 2 | Column 3 |
Data | Data 2 | Data 3 |
Do you think what occur by next sample ?
|
Example
Column 1 | Column 2 | Column 3 |
Data | Data 2 | 012345678901234567890123456789012345678901234567890123456789 |
So, table width inflates according to characters width.
This problem will clear if you set table style like a following code.
|
style = "table-layout: fixed;" just added.
Example
Column 1 | Column 2 | Column 3 |
Data | Data 2 | 012345678901234567890123456789012345678901234567890123456789 |
So, table width was fixed without any relation to character width.
However, characters exceeds table width.
Problem that characters exceeds any width (wordwrap of no blank characters )
As shown in the table where we have fixed Hami出character would.To avoid this, set to be avoided as follows.
If you set either of the following code, this problem will be cleared.
- Embed <wbr> or blank where you may wrap.
- Add style = "word-break: break-all;" (IE only)
|
Following sample is code that embedded <wbr> where you may wrap.
Example
Column 1 | Column 2 | Column 3 |
Data | Data 2 | 0123456789 |
Following sample is code that embedded blank where you may wrap.
Example
Column 1 | Column 2 | Column 3 |
Data | Data 2 | 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 |
|
Following sample is code that embedded
|
(only IE).
Example
Column 1 | Column 2 | Column 3 |
Data | Data 2 |
012345678901234567890123456789012345678901234567890123456789 |
This method is not necessarily the best.
You may find also methods that clear this problem ( ex) Web server setting… ), by Google search.
Problem that characters exceeds any width (pre wrapping tag)
The problem still remains.
Following sample is code that characters exceeds any width with pre tag.
|
Example)
Column 1 | Column 2 | Column 3 |
Data 1 | Data 2 |
0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 |
Characters with pre tag will exceed any width even if you embed blank where you may wrap.
This problem will clear if you set a following code.
style = "white-space:-moz-pre-wrap;" (FireFox for),
style = "word-wrap: break-word;" (IE for),
style = "white-space:-pre-wrap;" (Opera 4-6 for),
style = "white-space:-o-pre-wrap;" (Opera 7 for),
style = "white-space: pre-wrap;" (CSS3 for / FireFox 3.0 or higher for)
|
例)(FireFox)
Column 1 | Column 2 | Column 3 |
Data 1 | Data 2 |
0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 |
Example) (IE)
Column 1 | Column 2 | Column 3 |
Data 1 | Data 2 |
0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 |
Check points is a following 2 points.
The point is the following two points.
- Embed style = "table-layout: fixed;" with table tag.
-
Embed a following code in CSS fils with pre tag.
pre { white-space: -moz-pre-wrap; /*(FireFox)*/ word-wrap: break-word; /*(IE)*/ white-space: -pre-wrap; /*(Opera 4-6)*/ white-space: -o-pre-wrap; /*(Opera 7)*/ white-space: pre-wrap; /*(CSS3/FireFox 3.0+)*/ };
You might also like:
Comments
Leave a Reply