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.

[React] ボタンのCSS調整!

Posted at

はじめに

今回は、ボタンの見栄えを向上させるCSSの調整について紹介します!

1. ボタンのスタイリング

まずは、基本的なボタンのスタイリングを行います。
以下のCSSコードを使用して、ボタンの高さ、幅、フォントサイズ、影、角丸などを設定します!
また、.button:hoverを用いることで、カーソルが乗ったときのホバーも表現できます!

/* src/styles/Button.module.css */

.button {
  width: 35%;
  height: 100px;
  margin-top: 20px;
  font-size: 30px;
  padding: 15px 20px;
  border-radius: 10px;
  box-shadow: 0px 6px 3px rgba(0, 0, 0, 0.3);
  transition: box-shadow 0.3s ease-in-out, transform 0.3s ease-in-out;
  background-color: #499ef9;
}

.button:hover {
  box-shadow: 0px 10px 3px rgba(0, 0, 0, 0.5);
  transform: scale(0.98);
}

2. ボタンコンポーネントの作成

次に、このcssを適用するボタンコンポーネントを作成します!

// components/Button.jsx

import React from "react";
import styles from "../styles/Button.module.css";

const Button = () => {
  return (
    <button className={styles.button}>
      Click me
    </button>
  );
};

export default Button;

3. ボタンを使用

最後に、作成したボタンコンポーネントを使用します!

// pages/index.jsx

import React from "react";
import Button from "../components/Button";

const HomePage = () => {
  return (
    <div>
      <h1>Welcome to My App</h1>
      <Button />
    </div>
  );
};

export default HomePage;

スクリーンショット_20240214_114850.png

まとめ

今回は、ボタンの見栄えを向上させるCSSの調整について紹介しました!
記事を参考にして、自分のプロジェクトに合わせてボタンをカスタマイズしてみてください!

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?