Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was trying but not success. pls solve my problem.

What I have tried:

<!DOCTYPE html>





  <title>Bootstrap Example

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  
  
  .center{
   height:300px;
   width:300px;
   background:#eee;
   position:absolute;
   margin:-150px 0 0 -150px;
   left:50px;
   top:50px;
   } 
  


<div class="center"></div>
Posted
Updated 18-Jan-17 19:32pm

 
Share this answer
 
I see a lot of problems, including missing closing tags and missing body tag. Additionally, your top margin, being negative, will force the text be above of the screen; so you won't see it.

Peter's comment above will give you the answer, but, my suggestion to you is start from the beginning and read a beginner's tutorial on CSS (CSS Tutorial[^]). It'll take an hour and about 3/4 through, you'll get into layouts (CSS Layout - Horizontal & Vertical Align[^]).

<!DOCTYPE html>
<html>
<head>
<style>
.center{margin: auto; width: 60%; border: 3px solid #000; padding: 10px;}
.center-text{text-align: center;}
</style>
</head>
<body>
<div class="center">
  	<p>The div is centered, but the text is not.</p>
	<h4 class="center-text">This is centered text.</h4>
</div>
</body>
</html>
 
Share this answer
 

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