Build a rectangle frame with a transparent circle using CSS only - html

I need to implement a design to my webpage butI am kind of newbie with CSS.
What I am trying is to add a frame above the user picture. For example, for any size of image, I want that a given profile image like:
... I want to add a rectangle with a transparent circle inside like:
... so the final result would be like:
I am currently adding this frame as an image an resizing the user's image but it decreases resolution.
I really need the frame height size to be equal the image height size and put a frame and circle according to the user image.
Any Ideas?

Here try this DEMO. To check transparency, try changing body color.
<div class="outerCont">
<div class="innerCont centerAlign">
<img src="http://i.stack.imgur.com/FjDS6.png"/>
</div>
</div>
.outerCont{
height:300px;
width:300px;
position:relative;
overflow:hidden;
}
.innerCont{
background-color:transparent;
border:150px solid rgb(186, 230, 255);
border-radius:50%;
height:200px;
width:200px;
overflow:hidden;
}
.innerCont img{
position:absolute;
height:80%;
bottom:0;
left:50%;
-webkit-transform:translateX(-50%);
transform:translateX(-50%);
}
.centerAlign{
position:absolute;
left:50%;
top:50%;
-webkit-transform:translateX(-50%) translateY(-50%);
transform:translateX(-50%) translateY(-50%);
}

Well, there are 2 ways:
1)
HTML:
<div class="profile_pic_cont">
<img src="img/profile_pic.jpg" class="profile_pic" />
</div>
CSS:
.profile_pic_cont {
width: 100px;
height: 100px;
background-color: #d2e8f7; /* light blue */
padding: 5px;
}
.profile_pic {
border-radius: 9999px;
}
or
2)
HTML:
<div class="profile_pic_cont">
<img src="img/profile_pic_frame.png" />
</div>
CSS:
.profile_pic_cont {
width: 100px;
height: 100px;
background: #fff url('./img/profile_pic.jpg') no-repeat top left;
}

HERE IS THE JSFIDDLE
.circle {
background-color:#fff;
border-radius: 50%;
width: 250px;
height: 250px;
text-align:center;
background-image:url('http://i.imgur.com/NGz1YlF.png');
background-repeat:no-repeat;
background-size:65%;
background-position:center bottom;
}

You should draw the square, then the circle on top of it and finally put the image, this will produce the result you want.
Check there for how to trace a circle in CSS.

Related

How to crop the <tr> background based on the image shape?

How to achieve something like the above image. The below gray color block is cropped in the middle with semi circle to accommodate the image. Should I use CSS animations or anything else to get this effect? So that the background of the below element can be cropped as per the image shape.
Use position:absolute; for the image icon and place it between two divs and instead of cropping you can give a background:#fff and padding so it looks like that.
See code Below:
.main{
position:relative;
height: auto;
}
.upper {
background: #eee;
height: 100px;
}
.lower {
background: #ccc;
height: 100px;
}
img.icon {
position: absolute;
top: 40%;
left:50%;
background: #fff;
border-radius:50%;
padding:2px;
}
<div class="main">
<div class="upper"></div>
<img class="icon" src="https://cdn2.iconfinder.com/data/icons/web-and-mobile-ui-volume-24/48/1200-512.png" width="50" />
<div class="lower"></div>
</div>
JsFiddle: https://jsfiddle.net/75euot8d/1/

Create radius by css

I am trying this using border-radius but it doesn't seems like this image.
If you want to create circle, give same height and width to div and add border-radius property 50%.
.circle{
width:400px;
height:400px;
background:#000;
border-radius:50%;
}
<div class="circle"></div>
If your trying to make the black one a circle then just add the following css code to the class/id of the div. If your trying the whole image then add this css code to that particular id/class.(you can change the height and width if you want.)
#circle{
width:200px;
height:200px;
background:#000;
border-radius:100%;
}
<div id="circle"></div>
set border-radius: 50%;
Below is an example css code for a div
div {
height: 500px;
border: 2px solid #a1a1a1;
padding: 10px 40px;
background: yellow;
width: 400px;
border-radius: 0% 50% 50% 0%;
}

Display image on mouseover of another image

If I hover over a image, then display another image on that same image.
Above image of plane is original image and swapped text is cross transparent image.
If I hover on image of plane then I want to show another image of swapped
The best way to achieve what you are trying to do is to use use jQuery. Please see below:
$("#ImageID").mouseover(function(){
$("#ImageID").attr("src","new/url/goes/here.jpg");
});
$("#ImageID").mouseout(function(){
$("#ImageID").attr("src","old/url/goes/here.jpg");
});
I hope this helps!
try this code:
<style type="text/css">
.izo {
background: url(http://img1.jpg) no-repeat 50% 50%;
display: block;
width: 400px;
height: 400px;
}
.izo:hover {
background: url(http://img2.jpg) no-repeat 50% 50%;
} </style>
Try using this, it allow you to show overlay image without changing original image
<div class="pic-container">
<div class="pic-box"><img src="img_original.jpg"></div>
<div class="pic-box pic-hover"><img src="img_original.jpg"></div>
</div>
& style
<style>
.pic-container{display:block; width:200px; height:200px; position:relative;}
.pic-container .pic-box{display:block; width:200px; height:200px;}
.pic-container .pic-box img{display:block; width:200px; height:200px;}
.pic-container .pic-hover{position:absolute; top:0; left:0; display:none;}
.pic-container:hover .pic-hover{display:block;}
</style>

Circular image placing bottom-middle of the div

Picture describes all. I know how to make this circular image. But still don't know the way to place the image like this. Circular Image should stay middle of the div, as the div's width change.
you have to set the parent element as relative (position:relative) the wrap your img in a div with an absolute position 50% left or right depending on you.
<figure>
<figcaption class="top">assassin's creed</figcaption>
<div><img src=http://www.pulpfortress.com/wp-content/uploads/2010/11/Ezio-Assassins-Creed.jpg /><div>
</figure>
Demo
figure{
width:400px;
height:300px;
background:#444;
position:relative;
}
figure div{
width:150px;
height:150px;
overflow:hidden;
border-radius:100%;
position:absolute;
bottom:-75px;
left:50%;
margin-left:-75px;
}
figure img{
width:100%;
height:160px;
}
figcaption{
width:100%;
text-align:center;
padding-top:40px;
color:white;
font-size:20px;
}
You could use position relative to shift the image from the bottom div over the boundary between the two.
CSS
.top {
background: grey;
height: 120px;
}
.bottom {
background: white;
text-align: center;
height: 60px;
}
.bottom > img {
position: relative;
top: -50%;
}
HTML
<div class="wrap">
<div class="top">HELLO PROGRAMMERS!</div>
<div class="bottom"><img src="image.png" /></div>
</div>

Place a background image over an image

Im trying to put a background image over an image.
Basically its to show if a 'user' has approved or denied something.
I want if approved to display a green tick over the users display image.
I tried to create it but what i have does not work.
This is what i have so far:
Html
<img class="small-profile-img accepted" src="http://www.image.com/image.gif" alt="">
CSS
.small-profile-img{
width:30px;
display:inline;
border:2px solid #000000;
}
.accepted{
background-image:url("tick.png") !important;
background-repeat:no-repeat;
background-position:right bottom;
z-index:100;
background-size:18px;
}
See jsfiddle for working example.
jsfiddle
The solution would be is to use wrapper with after pseudo element for accepted class:
.accepted:after {
content: '';
display: block;
height: 18px;
width: 18px;
position: absolute;
bottom: 0;
right: 0;
background-image:url("http://cdn1.iconfinder.com/data/icons/checkout-icons/32x32/tick.png");
background-repeat: no-repeat;
background-position: right bottom;
z-index: 100;
background-size: 18px;
}
HTML
<div class="small-profile-img accepted">
<img src="http://2.bp.blogspot.com/-KLcHPORC4do/TbJCkjjkiBI/AAAAAAAAACw/zDnMSWC_R0M/s1600/facebook-no-image1.gif" alt="">
</div>
http://jsfiddle.net/vpgjr/7/
Background images go behind foreground content. An <img> is foreground content.
The only way you could see the background image would be if the foreground image had translucent pixels over the background image.
The tick appears to be content (rather than decoration) though, so it should probably be represented as an <img> anyway.
<div class="image-container">
<img class="small-profile-img"
src="http://www.image.com/image.gif"
alt="">
<img class="approved"
src="tick.png"
alt="Approved">
</div>
.image-container {
position: relative;
}
.image-container .small-profile-img {
position: relative;
z-index: 2;
}
.image-container .approved {
position: absolute;
z-index: 3;
top: 50px;
left: 50px;
}
Why dont you use position:absolute
HMTL
<div class="wrap">
<img src="http://2.bp.blogspot.com/-KLcHPORC4do/TbJCkjjkiBI/AAAAAAAAACw/zDnMSWC_R0M/s1600/facebook-no-image1.gif" alt="">
<div class="inner"> <img src="http://cdn1.iconfinder.com/data/icons/checkout-icons/32x32/tick.png" width="18"/></div>
</div>
CSS
.wrap{
position:relative;
background:red;
height:auto; width:30px;
font-size:0
}
.wrap > img{
width:30px;
display:inline;
}
.inner{
position:absolute;
top:30%;
left:50%;
margin:-5px 0 0 -9px
}
DEMO
set
position:absolute
Then set left,top (bottom,right if needed) property.
yea, i'd go the other way around.
change the class of the img when it's accepted.
HTML:
<div class='holder'>
<img class='unaccepted' src="http://cdn1.iconfinder.com/data/icons/checkout-icons/32x32/tick.png" alt="">
</div>
CSS:
.small-profile-img{
width:30px;
display:inline;
border:2px solid #000000;
}
.holder{
width:40px;
height:30px;
background-image:url("http://2.bp.blogspot.com/-KLcHPORC4do/TbJCkjjkiBI/AAAAAAAAACw/zDnMSWC_R0M/s1600/facebook-no-image1.gif");
background-size: 100%, 100%;
background-repeat:no-repeat;
background-position:center;
text-align: center;
}
.accepted{
border:none;
display:inline;
}
.unaccepted{
display:none;
}