Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
i want to center image and text. but dont no not work.

What I have tried:

<style>
    .centerimage {
        top:0;
        right:0;
        left:0;
        bottom:0;
    }
</style>



<div class="centerimage">
    <img src="~/Content/LeaveGrp.jpg" style="margin:0px 0px 0px 0px" />
    <p>you left the group</p>
</div>
Posted
Updated 21-Sep-17 1:38am

1 solution

Take a look below. I added position absolute with left and top. This should get you close to what you want; though you'll probably need to tweak it a bit. Below is an updated test of your sample.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <title> New Document </title>
    <style>
    .centerimage {text-align: center;
    position:absolute;
    left:50%;
    top:50%;
    }
</style>
 </head>
 <body>
<div class="centerimage" style="border: 1px solid #000;">
    <img src="https://codeproject.global.ssl.fastly.net/App_Themes/CodeProject/Img/logo250x135.gif" />
    <p>you left the group</p>
</div>
 </body>
</html>
 
Share this answer
 
v2
Comments
Jaydeep Shah 21-Sep-17 7:56am    
hey thanx but i required exactly center of screen
vertically and horizontally also.
jgakenhe 21-Sep-17 8:09am    
I updated it to center it horizontal and vertically. This should be close to what you need.
Jaydeep Shah 21-Sep-17 8:18am    
Thank you ! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900