0

I was looking the way to create image view as have Facebook or Google Plus but i can't put the image at middle of div.

This is my code:

.overflow {
    background-color: rgba(0,0,0,.9);
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    width: 100%;
}

.overflow .left-img-box,.overflow .right-content-box {
    display: inline;
    height: 100%;
}

.overflow .left-img-box {
    display: block;
    left: 0;
    margin: auto;
    position: absolute;
    text-align: center;
    top: 0;
    vertical-align: middle;
    width: 70%;
}

.overflow .right-content-box {
    background: #fff;
    position: absolute;
    right: 0;
    top: 0;
    width: 30%;
}

.overflow .left-img-box img {
    margin: auto;
    max-height: 100%;
}

You can see the example: http://fiddle.jshell.net/N6md8/5/

dorukce
  • 77
  • 10
manout
  • 41
  • 1
  • 10

1 Answers1

3

You can do something css like:

img {
margin:auto;
position:absolute;
top:0;
left:0;
bottom:0;
right:0;
max-height:100%;
max-width:100%;}

reference: http://codepen.io/shshaw/full/gEiDt

I beleive you can go with position:fixed as well :)

Medda86
  • 1,413
  • 1
  • 11
  • 17
  • it wok just if the image have width smaller than height look at example http://fiddle.jshell.net/N6md8/9/ – manout May 04 '14 at 19:32
  • for info, younger browser can do it through flexbox method : http://fiddle.jshell.net/N6md8/8/ and it can clip image via overflow: http://fiddle.jshell.net/N6md8/12/ and display:table http://fiddle.jshell.net/N6md8/13/ – G-Cyrillus May 04 '14 at 19:33
  • @Medda86 thanks again it works fine now i hade just to do max-width:100%. – manout May 04 '14 at 19:36