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

【Rails】ファイル投稿ボタンをカスタマイズ(備忘録)

Posted at

ファイルを投稿するボタンをカスタマイズする方法を残しておきます。

元の記述

new.html.erb
#省略
    <div class="field">
        <%= f.label :画像 %>
        <%= f.file_field :image %>
   </div>
#省略

変更後

new.html.erb
#省略
<div class="label-box__inner">
    <label class="mealpicture">料理画像
        <%= f.file_field :image ,class:"input-default" %>
        <div class="boxFileSelect"></div>
    </label>
</div>
#省略
SCSS
.label-box__inner{
 padding: 10px 20px 10px 20px;
  .input-default{
    display: none;
    width: 100%;
    height: 40px;
    margin: auto;
    padding: 10px 16px 8px;
    border-radius:4px;
    background: #fff;
    line-height: 1.5;
    cursor: pointer;
    outline-width: 2px;
   }
}

以上です。
お好みに合わせてCSSの値をいじったり、ラベルの文字をいじってください。

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