• CSS
  • HTML
  • EXCEL
  • WINDOWS10
  • TIPS
  • MAIL

【HTML】英語混じりテキスト文章を折り返せる「word-break」プロパティ

ブラウザが長い文章を表示するときに、半角のスペースや改行を入れた部分で折り返しが行われますが、英語のアルファベットの単語は基本途中で折り返しができません。

そのために英語が入っている文章は右端で折り返しができなく、段落の右端からはみ出したりして不揃いになることがあります。これを解消するにword-breakプロパティを使います。

スポンサーリンク

単語の途中で折り返しする方法「word-breakプロパティ」の値にはnormal、break-all、keep-allのいずれかを指定時ます。

セレクタ{ word-break : 値; }
normal普通英語のアルファベットの単語の途中では折り返しができません。
break-allのアルファベットの単語の途中では折り返しができます。
keep-all半角のスペースや改行を入れない限り、途中で折り返しができない。
 <style>
 .wordbreak{
     line-height:1.5em;
     word-break:break-all;
     }
 </style>
Migrants have in recent weeks been crossing back into Sweden at the Haparanda-Tornio border just an hour's drive south of the Arctic Circle, and Finnish authorities have seen a rise in the number of cancelled asylum applications."You can tell the world I hate Finland. It's too cold, there's no tea, no restaurants, no bars, nobody on the streets, only cars," 22-year-old Muhammed told AFP in Tornio...

word-break: break-all;では、言語に関係なく行の表示ボックス範囲に合わせて改行されるため、上記のサンプルのように、単語の途中で改行されることもあります。

そのため好ましくない位置で単語を折り返してしまうことがあります。たとえば英語は行ボックスの幅(右端)からはみ出そうな位置にあたると、その直前で折り返すため途中で折り返してしまい、単語の意味が分かりにくくなったりします。

word-wrapとの違い

「word-break: break-all;」は、言語に関係なく行ボックス範囲に合わせて改行しますが、単語に合わせて折り返します。

例えば、英語は行ボックスの幅(右端)からはみ出そうな位置にあたると、その直前で折り返すため途中で折り返してしまい、単語の意味が分かりにくくなったりします。

 <style>
 .wordbreak{
     line-height:1.5em;
     word-wrap:break-word;
     }
 </style>
Migrants have in recent weeks been crossing back into Sweden at the Haparanda-Tornio border just an hour's drive south of the Arctic Circle, and Finnish authorities have seen a rise in the number of cancelled asylum applications."You can tell the world I hate Finland. It's too cold, there's no tea, no restaurants, no bars, nobody on the streets, only cars," 22-year-old Muhammed told AFP in Tornio...

スポンサーリンク

スポンサーリンク

Category

 Windows 11  Windows 10  CSS  HTML  EXCEL(エクセル)  有用なTIPs  WINDOWS  MAIL(メール)

BILLION WALLET Copyright©All rights reserved