Xavier
Xavier

Reputation: 871

Rails image_tag width attribute to use a percentage / auto value?

image_tag('batman.png' size:'100%xauto')

The size 100% x Auto is ignored as it does not follow the convention outlined in the Rails API.

Is there a way to do this in rails without the need of a global / specific css class?

Upvotes: 10

Views: 26654

Answers (4)

Kashiftufail
Kashiftufail

Reputation: 10885

best way is

  <%= image_tag avatar , height: 'value' , width: 'value can be auto or 30' %>

Upvotes: 0

sandypockets
sandypockets

Reputation: 409

This works:

<%= image_tag 'image_url', style: 'height:100%; width:auto;' %>

But if you don't want to write your styles inline, then you can use a class instead:

<%= image_tag 'image_url', class: 'some-class-name' %>

Upvotes: 0

avr-girl
avr-girl

Reputation: 557

<%= image_tag('batman.png', :size => '100%xauto') %>

Upvotes: 0

raviture
raviture

Reputation: 1059

size is spitted across the 'x' and on both side it finds for numbers. checkout the code You can use 'style' option for image_tag.

UPDATE:

You can use the image tag with style as followed

= image_tag 'image_url', style: 'height:100%;width:auto;'

Upvotes: 21

Related Questions