次のようなイメージタグがあります。
<%= image_tag @user.photo.url(:large) %>
CSSでその画像の片側に境界線の色をスタイルするにはどうすればよいですか? それはどのようなhtmlを生成しますか?
次のようなイメージタグがあります。
<%= image_tag @user.photo.url(:large) %>
CSSでその画像の片側に境界線の色をスタイルするにはどうすればよいですか? それはどのようなhtmlを生成しますか?
by using "style" option:
<%= image_tag @user.photo.url(:large), :style => "border: 1px solid red" %>
for further info, please check the API.
Add a class or id to your image_tag:
<%= image_tag @user.photo.url(:large), :class => "style_image" %>
Then use css to style it:
.style_image {
border-right: 1px solid #000;
}
インラインスタイルも指定できます
<%= image_tag @user.photo.url(:large), :style => "float :left;border 1px solid #00000;" %>
それを試してみてください.....
これは簡単な方法です。
<%= image_tag("example.png", :style => 'border-right: 1px solid #000;')%>
Googleでこれに出くわした他の人のために。イメージ タグを別の方法で使用する場合でも、それに css クラスを追加できますが、構文が異なるだけです。場合によっては、外部サーバーを使用する必要があります。(Heroku へのデプロイ? => Amazon s3)
<%= image_tag("https://s3-us-west-2.amazonaws.com/mybucketname/user_photo.png", class: "style_image") %>