css - 如何将6个div放在同一行?

标签 css html css-float

我遇到了这个问题,我试图将 6 个 div 排成一行,并且每个 div 都被用作一个 sprite。发生的事情是 2 个位于包含 div 内的顶部,另外 4 个位于包含 div 之外的下方。我已经研究过让每个 div 都 float ,其中包含宽度与 6 div 的宽度总大小相匹配的 div。我还发现另一个问题在这里使用 <br style="clear: left;" />在第六个 div 之后,但仍在包含的 div 内,但这似乎无法解决我的问题。 这个包含的 div 也在页脚 div 的内部。

CSS:

#footer {
    width: 100%;
    height: 135px;
    background-color:#444;}

#sprite {
    margin: 0 auto;
    width: 602px;
    height: 35px;
    /*background-image: url(images/sprite.png);
    background-repeat: no-repeat;
    background-position: left top;*/
}


#ash {
    width: 113px;
    height: 35px;
    float: left;
    background: url(images/images/sprite1_01.png) no-repeat 0 0;
}

#ash:hover {
    background-position:0 -35px;

}

#gateway {
    margin: 0 auto;
    width: 113px;
    height: 35px;
    background: url(images/images/sprite1_02.png) no-repeat 0 0;
}

#gateway:hover {
    background-position:0 -35px;

}

#conect {
    width: 113px;
    height: 35px;
    float: left;
    background: url(images/images/sprite1_03.png) no-repeat 0 0;
}

#conect:hover {
    background-position:0 -35px;

}

#peninsula {
    width: 113px;
    height: 35px;
    float: left;
    background: url(images/images/sprite1_04.png) no-repeat 0 0;
}

#peninsula:hover {
    background-position:0 -35px;

}

#aza {
    width: 75px;
    height: 35px;
    float: left;
    background: url(images/images/sprite1_05.png) no-repeat 0 0;
}

#aza:hover {
    background-position:0 -35px;

}

#greenscape {
    width: 75px;
    height: 35px;
    float: left;
    background: url(images/images/sprite1_06.png) no-repeat 0 0;
}

#greenscape:hover {
    background-position:0 -35px;

}

html:

<div id="sprite">


            <div id="ash">

            </div> <!-- end of ash div-->

            <div id="gateway">

            </div> <!--end of gateway -->

            <div id="conect">

            </div> <!-- end of conect -->

            <div id="peninsula">

            </div> <!-- end of peninsula -->

            <div id="aza">

            </div> <!-- end of aza -->

            <div id="greenscape">

            </div> <!-- end of greenscape -->


        <br style="clear: left;" />


</div> <!-- end of sprite -->

下图是它在浏览器中的样子。

enter image description here

最佳答案

你错过了这个。

#gateway {
    float: left;
}

关于css - 如何将6个div放在同一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22977569/

相关文章:

css - 在 float div 和底部 div 之间放置一个空格

html - 如果分区 :target change css of another div

html - css 布局、div 定位、对齐和 z-index 的问题

javascript - 对齐彼此相邻的绝对定位元素

JavaScript - onmouseover 修改前一个元素的 css 高度

javascript - 分割 D3 图形 Y 轴垂直色线

css - 在最后一页的底部添加内容

javascript - 使用两个单选按钮和一个表单合并两个表单

css - IE7 在同一个元素上 float 和清除

javascript - 在 d3.js 元素中添加 slider