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?

【フロントエンド1000本ノック】0035_::before, ::after疑似要素を使い、テキストの前後にアイコンや装飾を追加するスタイルを実装せよ。

Posted at

この記事は人間が書きました

はじめに

こんにちは、赤神です!
この記事は、「1000本ノック」という取り組みの中のフロントエンドのための課題の1つです。

「1000本ノックとは」
https://qiita.com/sora_akagami/items/c8da4296dea3823376ca

擬似要素とは?

疑似要素は、要素の特定の部分にスタイルを適用するためのものです。::before::after は、CSS だけで HTML に存在しない要素を、要素の前や後ろに追加できる非常に強力な機能です。

  • ::before:要素の内側の、コンテンツの直前に要素を追加する
  • ::after:要素の内側の、コンテンツの直後に要素を追加する

重要なルール:content プロパティ

::before::after を使う際には、必ず content プロパティを指定する必要があります。このプロパティで、追加する要素の中身を定義します。

content には、テキストや画像、あるいは空文字("")などを指定できます。

作成したコード

index.html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>フロントエンド1000本ノック 0035</title>
    <style>
      .decorated-link::before {
        content: "🔗";
      }
      .decorated-link::after {
        content: "";
        display: block;
        width: 100%;
        height: 2px;
        background-color: blue;
      }
    </style>
</head>
<body>
    <main>
      <h1>擬似要素</h1>

      <a href="#" class="decorated-link">サンプルリンク</a>

    </main>
    <footer>
      <p>Copyright 2025</p>
      <p>フロントエンド1000本ノック</p>
    </footer>

</body>
</html>
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?