MyBB Community Forums

Full Version: how to have user avatar show up as background
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
OKAY so I am trying to customize my welcomeblock and I need each users avatar to show up as a background in a div, is there a way to do that with css?
That won't work in CSS. trying to do background-image: url(user's avatar); so there avatar shows up for them
^ you can try using code like below and add required css style
<div class="panelavatar"></div>
.panelavatar {
background: url("{$mybb->user['avatar']}");
width: 20px;
height: 20px;
}
I tried that and it doesn't work.
bumping this up. still haven't been able to find a way to do this.
You can't use variables in stylesheets but you can do it in templates with inline styling..

<div style="background: url('{$mybb->user['avatar']}');">. . .</div>

Or you could put the <style> block inside headerinclude.

That, of course, won't work as expected when user has no avatar. For that case you can use Template Conditionals: http://mybbhacks.zingaburga.com/showthread.php?tid=464

<div style="background: url('<if $mybb->user['avatar'] then>{$mybb->user['avatar']}<else>images/default_avatar.gif</if>');">. . .</div>
Okay so I tried the first thing and it did not work. Do I need that plugin for the first option to work?
You're doing something wrong then... I just tested it and it works, no plugins required.

I guess you put an empty div? It needs content like this:
<div style="background: url('{$mybb->user['avatar']}');">
~~~~~~~~~~~~~
<br />
. . . content replacement . . .
<br />
~~~~~~~~~~~~~
</div>
(result) or height/width in CSS.

And as I said, it requires avatar, otherwise 2nd solution is needed.
I am not sure what I was doing wrong before but this one worked, thank you <33