Search code examples
htmlcsspositionalignment

Margin: 0 auto; not centering because there are divs to the left and right


I am trying to centre the middle circle but I am unable even when set to margin: 0 auto; and display: inline-block; or display table. Any suggestions?

JSFiddle

HTML

<div id="intro">
    <p class="body">As part of Science World’s Cycle Safe Initiative we have installed sensors at each of our gates. In the past year we have had over <b>300,000</b> people ride along. Some information we gathered for June included;</p>
    <span class="blue circle">
        <h3>2 - 3PM</h3>
        <p>is the busiest hour</p>
    </span>
    <span class="green circle">
        <h3>117,295</h3>
        <p>riders this month</p>
    </span>
    <span class="navy circle">
        <h3>10%</h3>
        <p>of Vancouverites*</p>
    </span>
</div>

CSS

#intro {
    max-width: 1080px;
    margin: 0 auto;
}
#intro .circle {
    min-width: 230px;
    min-height: 230px;
    display: inline-block;
    text-align: center;
    border-radius: 1000px;
    color: white;
    margin: 60px 0;
}
#intro .circle h3 {
    margin-top: 80px;
    margin-bottom: 0;
    font-size: 2.2em;
}
#intro .circle p {
    margin-top: 0;
}
#intro .circle.blue {
    background: #0079c8;
}
#intro .circle.green {
    background: #2ecc71;
}
#intro .circle.navy {
    background: #34495e;
    float: right;
}

Solution

  • Add text-align:center to the #intro (as your inner content acts like inline) and add float:left to your #intro .circle.blue.

    Example