Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Center text in DIV

Posted on 2008-11-05
5
Medium Priority
?
997 Views
Last Modified: 2012-06-21
How can I center the text in the middle of a DIV,

When I look at the code in dreamweaver it looks good, but on IE, FF the text is in the center but at the top of the DIV, and I want in the middle.

here is my css for the DIV
.thrColFixHdr #search {
	background-image:url(../images/search_background_round.jpg);
	background-repeat:no-repeat;
	background-color:#b5d6b7;
	height:70px;
	width:652px;
	margin-left:auto;
	margin-right:auto;
	margin-top:15px;
	text-align:center;
	vertical-align:middle;
}

Open in new window

0
Comment
Question by:Ennio
  • 2
  • 2
5 Comments
 

Expert Comment

by:Midani
ID: 22892319
instantiate the class in your html and then center it in your html.

is there a problem with centering the class in the html?

Midani
0
 

Expert Comment

by:Midani
ID: 22892338
Hey I thought of something:

<div class="thrColFixHdr" align="center">
</div>
or
<div class="thrColFixHdr ">
   <div align="center"></div>
</div>

0
 

Expert Comment

by:WMS52
ID: 22892345
As Midani said...what's wrong with...
<div><center>Hello</center></div>

Open in new window

0
 
LVL 6

Accepted Solution

by:
lpxtech earned 2000 total points
ID: 22892347
Hi,

playing with some css properties, I found this to work.
<div id="wrapper" style="display: table; height: 500px; width: 500px; #position: relative; overflow: hidden; text-align: center;">
	<div id="myDiv" style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle;">
		<div class="innerDiv" style="#position: relative; #top: -50%;">
			<p>This text is centered</p>
		</div>
	</div>
</div>

Open in new window

0
 
LVL 6

Expert Comment

by:lpxtech
ID: 22892352
You can view an example here.

http://www.lpxtech.com/test.php
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question