Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rectangular image in circle with see-through background

Tags:

html

jquery

css

I have to implement a popup window like this:

It can appear anywhere on the screen. I need to put a 50x50 rectangular Facebook profile picture inside a circle with a thick white border. So I need to trim the profile image while keeping the background showing through. The problem is that the background is an image itself, so a mask image with a solid color outside the circle wouldn't work.

Is this possible somehow with HTML/CSS/jQuery?

like image 928
Arthur Avatar asked Apr 13 '26 23:04

Arthur


2 Answers

I'd just use border-radius to create the circle, in combination with overflow:hidden to make it crop the image. Here's an example: http://jsfiddle.net/6LHNy/

The markup:

<div class="wrapper">
    <img src="http://www.petscarecenter.com/wp-content/uploads/2011/05/dog.jpg" />
</div>

​The relevant CSS:

.wrapper {height:100px; width:100px; border-radius:100px; border:4px solid white; overflow:hidden}​
like image 197
maxedison Avatar answered Apr 16 '26 23:04

maxedison


Sure, put the image as a background (with css) and use border-radius to round the corners of the containing element.

Something like this:

<div style="border: 3px solid white; border-radius: 25px;
height: 50px; width: 50px;
background: #aaa url(facebook-head.png)"></div>

Note: IE 8 and below won't round the corners: http://caniuse.com/#search=border-radius

like image 40
JasonWoof Avatar answered Apr 16 '26 22:04

JasonWoof