Search code examples
htmlcenter

Stuff is not centering in Div


I'm a newbie at this and I'm trying to figure out what I'm doing wrong. I want to centre everything within a div, but it won't budge no matter what I do.

Could you guys advise?

<div id="main1">
<h1>blah</h1>
    <div id="intro">
        <p>Bettina is a designer who is learning to code. She is very cluey and a bit fustrated because she doesn't know what she is doing.</p>
    </div><!--intro-->

#main1 {
width:100%;
height:700px;
margin:0;
position:relative;
background-color:#CCC;}

#title {
position:absolute;
top:500px;
right:auto;
margin:auto;
}

#intro {
bottom:0px;
width:50%;
margin:0 auto;
position:absolute;
text-align:center;
}

Solution

  • Thank you for all your suggestions! This is what I've ended up doing:

    #main1 {
    width:100%;
    height:700px;
    margin:0;
    background-color:#CCC;
    position:relative;
    }
    #title {
    display: block;
    margin-left: auto;
    margin-right: auto;
    position:absolute;
    top:300px;
    margin-left: auto;
    margin-right: auto;
    left: 0;
    right: 0;
    }
    #intro {
    width:50%;
    text-align:center;
    position:absolute;
    bottom:0px;
    margin-left: auto;
    margin-right: auto;
    left: 0;
    right: 0;
    }