1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

2011/04/05 チェックボックスとラベルの間で改行させないCSS例

Posted at

昔書いた社内ブログ記事です。


20110405.gif

<一番上>

外側のボックスの幅が決まっているとき、
英数字の連続文字が枠をつきやぶってしまうことがありますよね。

<真ん中>

下のCSSを追加してみたんですが、ブラウザによって改行したりしなかったり。

CSS
word-wrap: break-word;
word-break: break-all;

IE8 → ○
FF3 → ×
Chrome → ○
Opera → ×
Safari → ○

<一番下>

最後は苦肉の策でした。

HTML
<div style="
 width:120px;
 border:1px solid #333;
 word-wrap: break-word;
 word-break:break-all;">
  <input type="checkbox" id="cb" name="cb" value="1" style="
   position:absolute;" />
  <label for="cb" style="
   padding:0 0 0 1.5em;">this_is_a_label_for_the_checkbox</label>
</div>

labeldisplay: block; にして text-indent を設定してもいけますね。

他にも案あったら教えてください(人´ω´)♪

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?