Thursday, March 27, 2014

How to position image with css


If you want your image permanently positioned on your page, you can use css property called "position" with its value as fixed


//HTML
<img alt="Displaying image at corner using css property 
position" class="topLeft" src="http://imagizer.imageshack.us/v2/100x75q90/844/ybfp.jpg" />


<img alt="Displaying image at corner using css property 
position" class="topRight" src="http://imagizer.imageshack.us/v2/100x75q90/844/ybfp.jpg" />

<img alt="Displaying image at corner using css property 
position" class="bottomLeft" src="http://imagizer.imageshack.us/v2/100x75q90/844/ybfp.jpg" />

<img alt="Displaying image at corner using css property 
position" class="bottomRight" src="http://imagizer.imageshack.us/v2/100x75q90/844/ybfp.jpg" />


//CSS 

img {
position:fixed;
}

.topLeft {
top:0;
left:0;

}

.topRight {
top:0;
right:0;

}

.bottomLeft {
bottom:0;
left:0;

}

.bottomRight {
bottom:0;
right:0;

}

Here is the fiddle for positioning images with css http://jsfiddle.net/hSq3b/1/


No comments:

Post a Comment