Kakarotto57
Kakarotto57

Reputation: 59

How to center text within a div

This is my HTML:

<div class="fourcol" align="center" ;="" style="float:;">
<h2 class="center" style="text-align: center;">More Mentors Announced Soon</h2>

The text itself is center justified, but I want it to be horizontally centered within the page. How can I do this?

This is the CSS I've been using with it

.fourcol, {
    position: relative;
    float: left;
    margin-right: 2.762430939%;
    margin-bottom: 20px;
    margin-top: 20px; 
}


h2.center {
    width: 50%;
    margin: 0 auto;

Upvotes: 0

Views: 102

Answers (2)

radha
radha

Reputation: 782

try this one.change class fourcol to more

.more {
    float: left;
    width: 100%;
}
<div align="center" class="more">
<h2 style="text-align: center;" class="center">More Mentors Announced Soon</h2>
</div>

Upvotes: 2

CRABOLO
CRABOLO

Reputation: 8793

http://jsfiddle.net/aDdge/

Just remove the width 50% line

h2.center {
    width: 50%; //remove this line
    margin: 0 auto;
}

EDIT

http://jsfiddle.net/aDdge/2/

h2.center {
    margin-top: 34%;
}

Upvotes: 0

Related Questions