9
4

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.

画像の貼り付け方とサイズ変更 Rails イメージタグ

Posted at

##Rubyでイメージタグを使い画像を表示する方法

.rb

image_tag(画像ファイルへのパス, [, オプション or HTML属性 or イベント属性])

image_tag "icon.png", size: "16x16", alt: "アイコン"

例1 クラス名を指定してCSSで大きさを変更する場合。

html.erb 例1

<%= image_tag 'icon.png', class:'icon' %>

application.css
.icon{
  width: 80px;
  height: 80px;
}

例2 

html.erb 例2
<%= image_tag 'dog.JPG', :size =>'320x480' %>

'320x480'のxは小文字のエックスであることに注意!

9
4
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
9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?