ボタンのスタイル設定
CoddyのHTMLジャーニー「CSSマスタリー」セクションの一部。レッスン 27/43。
チャレンジ
簡単このレッスンでは、コールトゥアクションボタンを目立たせ、インタラクティブに感じられるようにします。今は普通のtextのように見えますが、ホバーやクリックの効果がある本物のボタンに変えてみましょう!
CSSの課題:
.btnclassをスタイル設定して本物のボタンのように見せ、background colorを#ff9933に設定します。- ユーザーがボタンの上にカーソルを置いたときにbackground colorを変更するには、
:hoverを使用します。 - ボタンがクリックされたときにbackground colorを変更するには、
:activeを使用します。 - ホバーとアクティブの効果が滑らかに感じられるように、
transitionを追加します。 - header内の段落に
margin-bottomを追加して、ボタンに近づきすぎないようにします。
自分で試してみよう
<html>
<head>
<title>Hobby Club Landing Page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header class="hero">
<div class="container">
<h1>Welcome to Hobby Club</h1>
<p>Find your passion. Join a community. Grow your skills.</p>
<a href="#" class="btn">Get Started</a>
</div>
</header>
<section class="features">
<h2 class="section-title">Popular Clubs</h2>
<div class="cards">
<div class="feature">
<div class="icon"><img src="https://upload.wikimedia.org/wikipedia/commons/f/fa/Android_Emoji_1f4f7_red.svg" width="20px"></div>
<h3>Photography</h3>
<p>Capture the moment and share your perspective.</p>
</div>
<div class="feature">
<div class="icon"><img src="https://upload.wikimedia.org/wikipedia/commons/5/51/Emoji_u1f3a8.svg" width="20px"></div>
<h3>Art & Design</h3>
<p>Draw, paint, and bring your creative ideas to life.</p>
</div>
<div class="feature">
<div class="icon"><img src="https://upload.wikimedia.org/wikipedia/commons/e/e6/Emoji_u1f3ae.svg" width="20px"></div>
<h3>Gaming</h3>
<p>Connect with fellow gamers and play your favorite titles.</p>
</div>
</div>
</section>
</body>
</html>
CSSマスタリーのすべてのレッスン
自分で練習してみよう: Webプレイグラウンド