I am trying to make a css styling for a harvey ball with an image inside, but so far I haven’t figure out a way to do it right. This is what I have now:
.three {width: 43px;
border-radius: 100%;
border-style: solid;
border-width: 4px;
border-left-color: #dadad9;
border-top-color: #009ee3;
border-right-color: #009ee3;
border-bottom-color: #009ee3;
width:40px;
height:40px;
}
.lead-name {
font-size: 16px;
font-family:Symantec Sans;
color:#424242;
font-weight: 600;
margin-bottom:0px;
}
.lead-title {
font-size: 14px;
font-family:Symantec Sans;
color:#424242;
margin-top: -3px;
margin-bottom: 10px;
}
<div class="lead-designer">
<img class="three" src="http://orig09.deviantart.net/09e7/f/2008/159/0/1/side_profile_vector_by_sruphil.png"/>
<div style="display:inline-block; margin-bottom:0px; margin-top:5px;">
<p class="lead-name">Designer Name</p>
<p class="lead-title">Messaging PO</p>
</div>
</div>
https://jsfiddle.net/yiluka/dtauydrz/
What I want is something like
As you can see, I want the circle to be divided straight and have part of the image grey scaled.
I have a lot of them and I really want to do it in code instead of photoshop to save some labor.
3
Answers
I just created a div that has the shape of a quarter circle
And absolutely positioned that div on top of your image. It’s got a transparent gray background and a top and left border with your blue. Both are now contained within an wrapper div so that the quarter circle would have something to be relative to.
Here’s where the quarter circle css came from: http://1stwebmagazine.com/css-quarter-circle (I changed the class names because they seemed backwards to me).
And here’s the updated fiddle: https://jsfiddle.net/ingridly/dtauydrz/1/
UPDATE:
I incorporated the idea from the other answers of filling another element with the image and grayscale-ing that, and now I think this answer does everything:
https://jsfiddle.net/ingridly/dtauydrz/6/
You can also do it using the pseudo element
::after
– https://jsfiddle.net/dtauydrz/3/The HTML:
The CSS:
After an hour of messing with it, I finally finished my solution.
TL;DR
JSFiddle Demo
JSFiddle Demo with a kitten(pick this one)
JSFiddle Demo with the unhappy king of all kittens(Actually this one is amazing)
This solution, after being implemented, renders this(minus, of course, the amazing hand-drawn circle):
This solution doesn’t require square images, playing with the background-image placement, and is quite easy to implement.
Let’s get started!
First of all, we take your nice
<img>
HTML element, and replace it with this monstrosity of HTML(It really isn’t that bad):Now for a little explanation. We use two different image elements so we can gray-scale one of them. We do not use a background image, since this requires a massive amount of changes if you want to make the icon bigger, or the images are different sizes.
.image-wrapper
is the container div, the elements inside are positioned relative to it. It’s CSS is stupid simple:(If you can’t understand that CSS, go read HTML5 and CSS3 for dummies. That’s how I started with css… #destroying_my_reputation)
.main
is, of course, the main image in color. It’s CSS is a little mor complicated, but still very basic:The width can be changed to whatever you want, if you do change the width, make sure you also change the width of the
.gray
image.border-radius:100%
makes a circle, andborder
obviously adds a border.Now on to the more complicated CSS(It’s all pretty simple)!
.grayscale
is the div used to hold the gray-scale image. If you know CSS, you can probably tell what is happening.The div is positioned absolute at the top-left corner of
.image-wrapper
. Anything overflowing it is hidden. It’s top-left corner is given aborder-radius
of 100%, making it into the quarter-circle shape. Instead of a border, we change it’s background color, and add a padding. This is because if we use a border, it is added to all sides, messing up the desired shape.And then the
.gray
img:Simple, the image is changed to gray-scale using the
grayscale()
CSS filter. Make sure the width is the same as.main
. And a border radius to add the round effect.That’s a wrap!
And here is the long awaited demo, with all the code