3

I have added an image with class "img-circle". I need to put another small image at the center of this image which is center for all devices.

Can any one tell me how to fix this issue.

3 Answers 3

1

DEMO: http://jsbin.com/IyAkoYA/2

<!-- begin image within image :: background size cover does not work in IE make sure you don't exceed the width of the actual image -->

 <div class="circle-wrapper">
  <span class="force-ratio"></span>
  <div class="img-container align-center">
   <div class="center-block-valign"></div>
   <img class="img-circle" src="http://placehold.it/250x250/000000&text=image+2" alt="">
   </div><!--img-container align-center-->
  </div><!--circle-wrapper--> 

 <!-- end image within image -->


.circle-wrapper * {
 box-sizing:content-box;
 -moz-box-sizing:content-box;
 -webkit-box-sizing: content-box 
}

.circle-wrapper {
 position: relative;
 width: 100%;
 box-sizing:content-box;
 -moz-box-sizing:content-box;
-webkit-box-sizing: content-box 
 background-image:url(http://placehold.it/400x400/ff6600/FFFFFF&text=image+1);
 background-position:50% 50%;
 background-size:cover;
 background-repeat:none;
 border-radius:50%;
 max-width:400px;
 max-height:400px;
}

 .force-ratio {
 padding-top: 100%;
 display:block;
 }

.img-container {
 position: absolute;
 top: 0;
 bottom: 0;
 left: 0;
 right: 0;
}

.align-center {
 text-align:center;
 font: 0/0 a;
}

.center-block-valign {
 display: inline-block;
 vertical-align: middle;
 height: 100%;
}

.circle-wrapper .img-circle {
 vertical-align: middle;
 display: inline-block;
 max-width:50%;
 padding:25%;
}

Much of this was found by googling "center responsive image inside another image" from this http://jsbin.com/aXiReCub/1/edit. Then, because BS3 uses a global border-box sizing, adjustments need to be made among other things.

1

Add following css code to your css file

.img-circle{position:relative}
anothor-image-selector:{position:absolute;margin:auto;top:0;left:0;bottom:0;right:0}

for pro and cons of this method just visit following article :

http://coding.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/

1
  • Thanks, I used the above css, but when i resize the browser, the second image position is moving, not fixed at the center of the first image
    – lalith458
    Commented Dec 7, 2013 at 9:49
0
box-sizing:contant-box;

use this code. I hope help you.

3
  • can u explain more on that
    – lalith458
    Commented Dec 7, 2013 at 8:34
  • background-position:50% 50%; use Commented Dec 7, 2013 at 8:41
  • box-sizing:content-box. Fix the spelling.
    – Christina
    Commented Dec 7, 2013 at 20:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.