2014-04-30 5 views
0

Je dois placer l'image au centre verticalement à l'intérieur de la div. Pourriez-vous m'aider à ce sujet? Voici mon extrait essayé.Centrer verticalement une image à l'intérieur de div

<html> 
<body> 
<div style="width:190px;height:100%;"> 
<img src="sample.jpg" width="190px" height="190px"/> 
</div> 
</body> 
</httml> 

sample image

+1

(http://jsfiddle.net/v6R5J/) – potashin

Répondre

0
<html> 
<body> 
<div style="width:190px;height:100%;position:relative;"> 
<img src="sample.jpg" style="height:190px; width:190px; position:absolute; margin:-95px 0 0 -95px; left:50%; top:50%;" /> 
</div> 
</body> 
</html> 

jsFiddle: http://jsfiddle.net/v6R5J/2/

+0

merci, bon travail – Anandh

3

HTML

<div> 
    <img src="http://i.stack.imgur.com/PbkUt.jpg" width="190px" height="190px"/> 
</div> 

CSS

div{ 
    height:400px; 
    width:190px; 
    background-color:grey; 
    display:table-cell; 
    vertical-align:middle; 
} 

Vérifiez ce violon http://jsfiddle.net/x5TK4/

0

FIDDLE - Une autre façon: [? Quel est le problème]

<style> 
    #Image{ 
    width: 190px; 
    height: 100%; 
    background-image: url(sample.jpg); 
    background-position: center; 
    background-repeat: no-repeat; 
    } 
</style> 
<body> 
    <div id="Image"/> 
</body> 
0

http://jsfiddle.net/9kn5N/

<div style="width:500px;height:500px;border:1px solid #000; text-align: center;"> 
<img src="http://i.stack.imgur.com/PbkUt.jpg" width="190px" height="190px" style="margin-top: calc(50% - 95px);"/> 
</div> 
Questions connexes