0
1

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.

link_toメソッドのクリックできる部分を拡大させたい

Posted at

はじめに

link_toメソッドを使って、ページ遷移をしているが、クリックできる部分が文字のところだけだったことに不満を感じたので、調べて実装しました。

CSSでブロック要素に変えて、padding

link_toメソッドにクラス名をつけます。
つける時はclass: "クラス名"
そのクラス名に対して、CSSでdisplay: block;のスタイルをつけます。
さらに、paddingで範囲を広げると、クリックできる部分が拡大します。

ちなみに、marginしてもクリックできる部分は広がりません。

erb
<ul>
  <li class="menu-list">
    <%= link_to 'マイページ', hoge_path, class: "menu-name" %>
  </li>
  <li class="menu-list">
    <%= link_to 'カレンダー', hoge_path, class: "menu-name" %>
  </li>
</ul>
css
.menu-list {
  margin: 30px auto;
  border: black 3px solid;
  padding: 0px;
}
.menu-name {
  display: block; 
  padding: 30px;
}

display: block;とpaddingが大事な部分です。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?