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.

hoverで画像表示を変える

Posted at

hoverを調べたきっかけ

  • 画像をクリックすると詳細ページに遷移する機能を作ってみた
  • しかし画像上にカーソルを置いてもクリックできるかどうか見た目だけだとわからない。(アクションがない)
    → ユーザー視点から、画像をクリックできるか分かりにくい印象。
  • カーソルを画像上に置くと、クリックできるとわかるような動きが欲しい!
    調べるとhoverという機能を発見。実装したので記事にしてみました。

参照

下記サイトを参考にさせて頂きました!
大変参考になりました、ありがとうございました!
https://lab.sonicmoov.com/markup/css/hover-css/

実装したhover

ダウンロード (1).gif
このようにカーソルを画面上に置くと、画像が変化し、クリックしやすくなる

HTML

まずは画像を挿入している部分にクラス名を付ける(今回は、"button grow")

html.erb
<%= link_to public_public_golfcourse_path(golf_course.id) do %>
  <%= attachment_image_tag golf_course, :image, size: "180x120", fallback: "no_image.jpeg",class: "button grow p-2" %><br>
<% end %>

CSS

HTMLでclassをつけたら、次はCSSにhover対応を記述していく。

homes.scss
/* Default styles for the demo buttons */
.button {
  // margin: .4em;
  // padding: 1em;
  cursor: pointer;
  // background: $primaryColour;
  text-decoration: none;
  color: $secondaryColour;
}

/* 2D TRANSITIONS */

/* Grow */
.grow {
  display: inline-block;
  transition-duration: $defaultDuration;
  transition-property: transform;

  @include hideTapHighlightColor();
  @include hardwareAccel();
  @include improveAntiAlias();

  &:hover {
    transform: scale(1.1);
  }
}

クラス名と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?