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 1 year has passed since last update.

【css】画像をアイコンで表示する方法

Posted at

## 問題
SNSなどによくある円形のアイコン画像を表示したい

方法

最終結果(ヘッダーの右側)

スクリーンショット 2024-04-18 19.06.06.png

コード

index.html
<div class="header-right">
    <button class="btn btn-success">予算</button>
    <button class="btn btn-success ml-1">予算登録</button>
    <button class="btn btn-success ml-1">支出登録</button>
    <div class="profile-picture profile-picture-header ml-1">
        <img class="img-fluid cursor_pointer" src="/assets/sample.jpg" alt="Profile Picture">
    </div>
</div>
style.scss
.profile-picture {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  overflow: hidden;
  // ⭐️アイコンを円形にリサイズして配置
  display: flex;
  justify-content: center;
  align-items: center;

  @media screen and (max-width: 430px) {
    width: 75px;
    height: 75px;
  }

  // ヘッダーアイコン
  &.profile-picture-header {
    width: 40px;
    height: 40px;
    vertical-align: middle;
    @media screen and (max-width: 430px) {
      width: 30px;
      height: 30px;
    }
  }

  img {
    // ⭐️アイコンを円形にリサイズして配置
    object-fit: cover;
  }
}

参考サイト

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?