199
191

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.

二行目の最後を「...」をクロスブラウザで実現

Last updated at Posted at 2015-09-01

文字が溢れたら「...」を出すのは text-overflow: ellipsis がありますが、一行の場合にしか利用できません。二行目に「...」を出すのは、 -webkit-line-clamp というのがありますが、クロスブラウザでは利用できません。

CSSだけで実現するのは不可能だと思ってたんですけど、出来ちゃいました。

Screen Shot 2015-09-01 at 9.38.24 PM-minishadow.png

実物はこちらでご確認ください。

css
.lineclamp {

  /* config */
  line-height: 1.5;
  height: 3em;
  background-color: #fff;
  /* config end */

  position: relative;
  padding-right: 1em;
  overflow: hidden;
}

.lineclamp:before {
  content: "...";
  position: absolute;
  right: 0;
  bottom: 0;
  display: inline-block;
  width: 1em;
}

.lineclamp:after {
  content: "";
  position: relative;
  right: -1em;
  float: right;
  width: 1em;
  height: 100%;
  background-color: inherit;
}

IE8はなぜかダメでした。IE9からで。

199
191
3

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
199
191

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?