css - 如何在页脚 Div(固定位置)中并排对齐 3 个 div

标签 css html alignment

这是一个简单的问题,但我正在努力获得准确的输出。我需要在页脚的一个 div 内对齐 3 个 div。我在谷歌尝试了很多,之前也工作过。但在页脚固定位置它不能正常工作。 enter image description here

在该图像中,白色容器 div 用于页脚、红色左侧、绿色右侧和中心。

这是我的 CSS:

div .footer-container
{
    height:53px;
    width:100%;
    position:fixed;
}

div .footer-container div .footer-left
{
    background-color:#f00;
    float:left;
    width:33%;
    height:31px;
}

div .footer-container div .footer-right
{
    background-color:#0f0;
    float:right;
    width:33%;
    height:31px;
}

div .footer-container div .footer-center
{
    background-color:#f0f;
    margin:0 auto;
    height:31px;
    width:33%;
}

这是 HTML:

<div data-role = "footer" class="footer-container">
                <div>
                <div class="footer-left"></div>
                <div class="footer-right"></div>
                <div class="footer-center"></div>
                </div>
            </div>

哪里做错了?请解释。

最佳答案

摆脱所有的花车。向三个内部 div 中的每一个添加 Display: inline-block 并调整它们的宽度(至 32%)以便它们并排放置。

    div .footer-container {    
        height:53px;     
        width:100%;     
        position:fixed; 
        background:#ccc 
    } 
    div .footer-container div .footer-left {     
        background-color:#f00;     
        display: inline-block;     
        width:32%;     
        height:31px; 
    } 
    div .footer-container div .footer-right {     
        background-color:#0f0;     
        display: inline-block;     
        width:32%;     
        height:31px; 
    } 
    div .footer-container div .footer-center {    
        background-color:#f0f;   
        display: inline-block;  
        margin:0 auto;     
        height:31px;     
        width:32%; 
    }​

这是一个FIDDLE

关于css - 如何在页脚 Div(固定位置)中并排对齐 3 个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13764105/

相关文章:

html - 仅使用 HTML 将图像居中左对齐

javascript - 不压缩javascript和CSS对客户端处理有什么影响

javascript - 如何使用 jquery 更改文本区域中的特定字符颜色?

html - 我可以将 Google 图片搜索嵌入到我的 html5 网页中吗

javascript - 使所有div.obstacles具有相同的功能

c++ - std::aligned_storage 的 static_cast 和 reinterpret_cast

css - 一半页面 + CSS 对齐

html - 在div之间添加一个空白

CSS - 在 css 中并排居中两个图像

html - 在图像下方显示下拉值