【问题标题】:Need helping with column alignment需要帮助进行列对齐
【发布时间】:2014-04-23 14:03:46
【问题描述】:

我需要帮助对齐图像中的文本,这将显示一个“网格”或 3 个表格列,在 <div class="container">...</div> 内居中。

我无法将文本与图像居中。这是设计预览:IMAGE LINK PREVIEW

这里是JSFIDDLE

您还可以“实时”查看它(我正在测试页面)HERE

HTML

<div id="services">
<div class="spacer"></div>
    <div class="conteudo container clearfix">

                <h2>Serviços</h2>
                <h3>Preçários e penteados</h3>

            <div class="holder container clearfix">

                <div class="servico container clearfix">
                    <img src="http://styleeuclides.site50.net/img/top.jpg" class="imgtop"><span class="top">Corte e Afiar + Barba</span>
                    <span class="price">10€</span>
                    <img src="http://styleeuclides.site50.net/img/corte.jpg" alt="corte" class="cut">
                </div>

                <div class="servico container clearfix">
                    <img src="http://styleeuclides.site50.net/img/top.jpg" class="imgtop"><span class="top">Corte e Afiar + Barba</span>
                    <span class="price">10€</span>
                    <img src="http://styleeuclides.site50.net/img/corte.jpg" alt="corte" class="cut">
                </div>

                <div class="servico container clearfix">
                    <img src="http://styleeuclides.site50.net/img/top.jpg" class="imgtop"><span class="top">Corte e Afiar + Barba</span>
                    <span class="price">10€</span>
                    <img src="http://styleeuclides.site50.net/img/corte.jpg" alt="corte" class="cut">
                </div>

                <div class="servico container clearfix">
                    <img src="http://styleeuclides.site50.net/img/top.jpg" class="imgtop"><span class="top">Corte e Afiar + Barba</span>
                    <span class="price">10€</span>
                    <img src="http://styleeuclides.site50.net/img/corte.jpg" alt="corte" class="cut">
                </div>

                <div class="servico container clearfix">
                    <img src="http://styleeuclides.site50.net/img/top.jpg" class="imgtop"><span class="top">Corte e Afiar + Barba</span>
                    <span class="price">10€</span>
                    <img src="http://styleeuclides.site50.net/img/corte.jpg" alt="corte" class="cut">
                </div>

                <div class="servico container clearfix">
                    <img src="http://styleeuclides.site50.net/img/top.jpg" class="imgtop"><span class="top">Corte e Afiar + Barba</span>
                    <span class="price">10€</span>
                    <img src="http://styleeuclides.site50.net/img/corte.jpg" alt="corte" class="cut">
                </div>

            </div>
    </div>

</div>

CSS

#services{
    float: left;
    width: 100%;
    background-color: #131313;
    color: #fff;
    margin: 0;
    padding: 0;
}

#services .spacer{
    width: 100%;
    height: 100px;
}

#services .conteudo h2{
    float: left;
    margin-top: 10px;
    font-size: 1.500em;
    font-weight: bold;
    margin-bottom: 5px;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 0;
    width: 900px;
}

#services .conteudo h3{
    float: left;
    color: #0ebe5b;
    font-size: 0.813em;
    font-style: italic;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 10px;
    letter-spacing: -1px;
    margin-top: -11px;
    width: 900px;
}

#services .holder .servico{
    float: left;
    width:30%;
    margin-left: 1.1%;
    margin-right: 2.2%;
    text-align: center;
}    

#services .holder span{
    position: absolute;
}

#services .holder span.price{
    color: white;
    font-style: italic;
    font-weight: bold;
    font-size: 1.000em;
    z-index: 2;
    line-height: 50px;
}

#services .holder span.top{
    color: white;
    font-style: italic;
    font-weight: bold;
    font-size: 0.875em;
    z-index: 2;
    line-height: 50px;
    width: 290px;
    height: 50px;
}

#services .holder .cut{
    margin-bottom: 10px;
}

提前致谢

【问题讨论】:

    标签: css grid position alignment center


    【解决方案1】:

    请更正您的 html 结构,您需要背景而不是图像这里是 example

    <div class="top-area">
            <span class="title">Corte e Afiar + Barba</span>
            <span class="price">10€</span>
        </div>
    
    span.title{ width:200px; background:#0ebe5b; display:table-cell;}
    span.price{ width:50px; background:#272727; display:table-cell; color:#ffffff;}
    span.price, span.title{ padding:10px; text-align:center;} 
    

    【讨论】:

    • 哇!谢谢,我不得不从 CSS 中删除一些行并添加 urs 并完美适配!
    【解决方案2】:

    这是纠正此问题的简单方法之一。

    #services{
        float: left;
        width: 100%;
        background-color: #131313;
        color: #fff;
        margin: 0;
        padding: 0;
    }
    
    #services .spacer{
        width: 100%;
        height: 100px;
    }
    
    #services .conteudo h2{
        float: left;
        margin-top: 10px;
        font-size: 1.500em;
        font-weight: bold;
        margin-bottom: 5px;
        letter-spacing: 1px;
        text-transform: uppercase;
        padding: 0;
        width: 900px;
    }
    
    #services .conteudo h3{
        float: left;
        color: #0ebe5b;
        font-size: 0.813em;
        font-style: italic;
        font-weight: bold;
        text-transform: uppercase;
        margin-bottom: 10px;
        letter-spacing: -1px;
        margin-top: -11px;
        width: 900px;
    }
    
    #services .holder .servico{
        float: left;
        width:30%;
        margin-left: 1.1%;
        margin-right: 2.2%;
        text-align: center;
    }    
    
    #services .holder span{
        position: absolute;
    }
    
    #services .holder span.price{
        color: white;
        font-style: italic;
        font-weight: bold;
        font-size: 1.000em;
        z-index: 2;
        line-height: 50px;
    }
    
    #services .holder span.top{
        color: white;
    font-style: italic;
    font-weight: bold;
    font-size: 0.875em;
    z-index: 2;
    position: relative;
    top: -40px;
    }
    
    #services .holder .cut{
        margin-bottom: 10px;
    }
    

    这里是jsfiddle

    【讨论】:

    • 看不到你的链接,它坏了
    • @Andy 请查看更新的代码和 jsfiddle 链接。