html - margin : 0 auto; not centering because there are divs to the left and right

标签 html css position alignment

我试图使中间圆居中,但即使设置为 margin: 0 auto 我也无法做到;并显示:内联 block ;或显示表。有什么建议吗?

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;
}

最佳答案

text-align:center 添加到 #intro(因为您的内部内容就像内联一样)并将 float:left 添加到您的#intro .circle.blue

Example

关于html - margin : 0 auto; not centering because there are divs to the left and right,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24174982/

相关文章:

javascript - 如何在某个 ID 选择器上更改导航链接的颜色?更具体地说,使用视差脚本

css - 响应式内联 block 查询

css - 页面最小宽度没有水平滚动条

html - CSS 动画侧边按钮标签

javascript - 为什么 window.scrollY + element.getBoundingClientRect().top 不等于 element.offsetTop?

c# - 如何在 .NET 中获取 xml 元素的流位置

html - CSS - 对齐选项卡

html - 同一文件中的多个 <html><body> </html></body>

javascript - div 变换后 div 容器高度太高

delphi - 如何检测流结束?