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 3 years have passed since last update.

cssで文が入り切らなかったとき

Posted at

今回はcssで一文が入り切らなかったときの方法を学習していきます。
まず、HTMLに記入していきます。

index.html
div class="form">
    <h1 class="title">ピエン</h1>
    <p>ピエンピエンピエンピエンピエンピエンピエン</p>
  </div>
style.css
.form {
  border: 4px solid black;
  width: 10%;
}


p {
  border: 2px solid pink;

}

スクリーンショット 2021-03-16 16.22.12.png

pタグのピエンが入りきっていませんね。
それでは、ここで1行で収めたいと思います。

style.css
p {
  border: 2px solid pink;
  overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

}

ブラウザで表示してみましょう。
スクリーンショット 2021-03-16 16.24.20.png

はい、入り切りましたね。

①overflow

これは、要素内に入り切らなかったときに使います。
いくつか種類がありますが、ここでは割愛していきます。
引用▶https://developer.mozilla.org/ja/docs/Web/CSS/overflow
スクリーンショット 2021-03-16 16.29.23.png

②text-overflow

これは、非表示にした部分をユーザーにどのように表示されるのかを表します。いくつか種類がありますが、今回も割愛していきます。
引用▶https://developer.mozilla.org/ja/docs/Web/CSS/text-overflow

スクリーンショット 2021-03-16 16.33.59.png

③white-space

こちらは要素内のスペースをどうするか決めることができます。
引用▶https://developer.mozilla.org/ja/docs/Web/CSS/white-space
スクリーンショット 2021-03-16 16.35.37.png

色々あるので、試してみましょう👍

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?