-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
publish 2024-12-06-overflow-clip-for-line-clamp
- Loading branch information
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/content/blog/2024-12-06-overflow-clip-for-line-clamp.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: 'line-clampとhanging-punctuationを併用するときはoverflow:hiddenの代わりにclipを使う' | ||
pubDate: 2024-12-06T00:40:00.000+09:00 | ||
--- | ||
|
||
CSSの`-webkit-line-clamp`プロパティを使うとき、通常は`overflow: hidden`を併用することが多い。 | ||
|
||
```css | ||
p { | ||
display: -webkit-box; | ||
-webkit-box-orient: vertical; | ||
-webkit-line-clamp: 3; | ||
width: 5.2em; | ||
overflow: hidden; | ||
} | ||
``` | ||
|
||
<figure>![](./assets/2024-12-06-overflow-clip-for-line-clamp/1.png)</figure> | ||
|
||
しかし、`hanging-punctuation`プロパティを併用する場合、`overflow: hidden`が指定されているとはみ出した役物が見切れてしまう。 | ||
|
||
```css | ||
p { | ||
display: -webkit-box; | ||
-webkit-box-orient: vertical; | ||
-webkit-line-clamp: 3; | ||
width: 5.2em; | ||
overflow: hidden; | ||
hanging-punctuation: allow-end; | ||
} | ||
``` | ||
|
||
<figure>![](./assets/2024-12-06-overflow-clip-for-line-clamp/2.png)</figure> | ||
|
||
`-webkit-line-clamp`プロパティを機能させるには、通常は`overflow-y`プロパティを使うだけで十分だ。ただし`overflow-y: hidden`を指定すると、自ずと横方向にスクロール可能な状態になってしまう。 | ||
|
||
```css | ||
p { | ||
display: -webkit-box; | ||
-webkit-box-orient: vertical; | ||
-webkit-line-clamp: 3; | ||
width: 5.2em; | ||
overflow-y: hidden; | ||
hanging-punctuation: allow-end; | ||
} | ||
``` | ||
|
||
<figure>![](./assets/2024-12-06-overflow-clip-for-line-clamp/3.png)</figure> | ||
|
||
この問題を解決するのが、`clip`である。`clip`を使うと、単方向の切り取りを実現しつつ、もう一方はスクロール不能な状態のままにできる。 | ||
|
||
```css | ||
p { | ||
display: -webkit-box; | ||
-webkit-box-orient: vertical; | ||
-webkit-line-clamp: 3; | ||
width: 5.2em; | ||
overflow-y: clip; | ||
hanging-punctuation: allow-end; | ||
} | ||
``` | ||
|
||
<figure>![](./assets/2024-12-06-overflow-clip-for-line-clamp/4.png)</figure> | ||
|
||
`hanging-punctuation`プロパティにかぎらず、横方向にコンテンツのはみ出しが発生する場面においては有効だろう。 |
Binary file added
BIN
+8.91 KB
src/content/blog/assets/2024-12-06-overflow-clip-for-line-clamp/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.47 KB
src/content/blog/assets/2024-12-06-overflow-clip-for-line-clamp/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.07 KB
src/content/blog/assets/2024-12-06-overflow-clip-for-line-clamp/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.55 KB
src/content/blog/assets/2024-12-06-overflow-clip-for-line-clamp/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.