LoginSignup
5
7

More than 5 years have passed since last update.

indentをCSSできっちり合わせる

Last updated at Posted at 2014-01-16

字下げのindentの
・こんなかんじの
 なかぐろを使ったインデント

※1 こんなかんじの
  半角を含むインデント

(※)こんなかんじの
   かっこを含むインデント
の場合、(たぶんフォントの関係で)Win/Macでインデントずれてしまうことがあります。

解決方法(IE7△CSSハック)

左にはみ出る部分をspanに突っ込んでごにょごにょする。
はみ出る部分の中身によって微調整が必要です。
なお、IE7が対象でなければ、ハック部分は全て消してよいのでだいぶ短くなります。

<p class="indent"><span>(※)</span>インデントを指定したい<br>
あたり</p>
p.indent {
    padding-left: 3em;
    /padding-left: 2em;
    text-indent: -3em;
}

p.indent span {
    display: inline-block;
    /display: inline;
    width: 3em;
    text-indent: 0;
    /text-indent: -2em;
}

デモ:http://jsrun.it/Ituki/4llI
他のindentのコードサンプル:http://jsdo.it/Ituki/4llI

5
7
2

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
5
7