html - 围绕几个 float div 的 div 上的奇怪中心格式

标签 html css

我遇到了一个问题,我试图拥有一个包含三个 div 的 div,其中有一个左浮动列、右浮动列和中间的主要内容。我已经尽我所能做到这一点,我想到了这个:

An Error!

由于某种原因,中间的 div 在第一列的末尾和右列的末尾之间居中,而不是在右列的开头。

<div id="main">
            <div id="left">
                <img src="/pic1.jpg" alt="Example work" height="250px" width="250px" />
                <br />
                <img src="/pic2.jpg" alt="Example work" height="250px" width="250px" />
            </div>
            <div id="content">
                words
            </div>
            <div id="right">
                <img src="/pic3.jpg" alt="Example work" height="250px" width="250px" />
                <br />
                <img src="/pic4.jpg" alt="Example work" height="250px" width="250px" />
            </div>
</div>

CSS:

#main {
        margin: 0 auto;
        width: 80%;
}

#left {
        float: left;
        padding: 5px;
        border: 2px ridge;
}

#right {
        float: right;
        padding: 5px;       
        border: 2px ridge;
}

#content {
        text-align: center;
}

对这里发生的事情有什么想法吗?

最佳答案

右浮动元素需要在标记中排在第一位。

http://jsfiddle.net/Vv4yA/

<div id="main">
    <div id="right">
        <img src="http://placehold.it/150x150" />
        <br />
        <img src="http://placehold.it/150x150" />
    </div>
    <div id="left">
        <img src="http://placehold.it/150x150" />
        <br />
        <img src="http://placehold.it/150x150" />
    </div>
    <div id="content">words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words words </div>
</div>

关于html - 围绕几个 float div 的 div 上的奇怪中心格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14763345/

相关文章:

javascript - 使用沙盒帐户时出现 API 错误

javascript - 单击按钮时更改值

javascript - 并排对齐部分

JavaScript Tic Tac Toe - 查找数组中所有可能的数字组合

php - 在每个 div 中回显消息或在 php 中单独的 css div

jQuery 没有根据 ID 选择器获取元素

javascript - 我想创建一个循序渐进的订单,这就是我目前所拥有的

css - 在aptana中是否有任何插件自动添加浏览器前缀css3?

asp.net - 在 asp.net 控件的样式属性中使用 DataBinder.Eval()

javascript - 将鼠标悬停在链接上时显示图像