0
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.

cssで字下げするにはblock要素にtext-indentを使おう

Posted at

cssで字下げを行うにはtext-indentを使おう

字下げをするにあたり広く知られていることだと思う。しかし私が実際にtext-indentを使ってみると全く変化がなかった。何故かというと、__インライン要素にtext-indentを使っていたから__だ。

__display:block;__と書き加えてやったところ、無事字下げに成功した。

css
 a{
	text-indent: 1em;
	display:block;
	}

ここでリンクに下線をつけてやろうなどと思うと以下のようになる。スクリーンショット 2020-04-17 14.28.07.png
下線が字下げをした分の左側の余白まで、というか画面いっぱいに広がってしまっている。

dosplay:block;にする以上仕方ないのだが、リンクの装飾と字下げどちらもやりたかった私はtext-indentではなくインライン要素にしてmargin-leftを使うことにした。

css
a{
	margin-left:1em;
	border-bottom:solid 3px #999;
	text-decoration: none;
	}

結果この記事のタイトルに背くことになってしまっているがこれ以外にやり方を知らないので許してほしい。誰かいい方法を知っていたら教えてください。

0
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
0
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?