0

So I'm making a user profile page for my app. However I want the user's avatar to have an inset white box-shadow. Therefore using <img /> isn't an option since it doesn't support inset shadows (or at least not in Chrome). So instead I'm using a <div> with some inline css to set the image. Here's kinda what I want but of course it wont work.

<div id="avatar" style="background: <%= @person.avatar %>"></div>

Can anyone point me in the right direction for doing this?

2 Answers 2

3

Is avatar the actual URL of the image? In that case:

<div id="avatar" style="background-image: url('<%= current_person.avatar %>')"></div>

Make sure that the width and height match the image dimensions in the CSS.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah yeah, I was just missing the = in <%= ... %> Thanks :)
0

This should work pretty well

<div id="avatar" style="background:url(<%= current_person.avatar %>) no-repeat;" width="<%= User.AVATAR_WIDTH %>" height="<%= User.AVATAR_HEIGHT %>"></div>

User.AVATAR_WIDTH and User.AVATAR_HEIGHT should be defined in your app/models/user.rb as something like:

class User
  AVATAR_WIDTH = 250
  AVATAR_HEIGHT = 250
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.