集中在水平元素浮动,如果可能的话,响应

时间:2014-02-10 14:47:51

标签: javascript jquery html css html5

我遇到了这个问题。

当我减小窗口的宽度时,我试图使div的所有形状都保持居中,但是它们总是相互跟随,并且真的离开了(想想浮动:左边)。

图像,如果可能的话,我们会保持响应有趣的我,但我试图控制宽度百分比,但没有工作。

请求支持。

Fiddler

<div class="general-box">
    <div class="left-right-padding">
        <ul>
            <li class="general-box-title">TITLE 1</li>
            <li> <a id="" href="" title=""><img src="" width="156" height="75" alt="" /></a>
 <a class="left-margin-photo" href="" title=""><img src="" width="101" height="75" alt="" /></a>

            </li>
        </ul>
    </div>
    <div class="left-right-padding">
        <ul>
            <li class="general-box-title">TITLE 2
                <li> <a href="" title=""><img src="" width="92" height="75" alt="" /></a>
 <a class="left-margin-photo" href="" title=""><img src="" width="160" height="75" alt="" /></a>

                </li>
        </ul>
    </div>
    <div class="left-right-padding">
        <ul>
            <li class="general-box-title">TITLE 3
                <li> <a href="" title=""><img src="" width="170" height="75" alt="" /></a>
 <a class="left-margin-photo" href="" title=""><img src="" width="88" height="75" alt="" /></a>

                </li>
        </ul>
    </div>
    <div class="clear"></div>
</div>

CSS:

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font: inherit;
    font-size: 100%;
    vertical-align: baseline;
    outline: none;
    text-decoration: none;
    zoom: 1;
}
/* HTML5 display-role reset for older browsers */
 article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after, q:before, q:after {
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}
.clear {
    clear: both
}
.general-box {
    padding: 0 40px 30px 40px;
    font-weight: bold;
    border: 1px solid #000;
}
.general-box .left-right-padding {
    float: left;
    padding: 0 20px 0 20px;
}
.general-box .general-box-title {
    margin: 30px 0 30px 0;
}
.general-box .left-margin-photo {
    margin-left: 16px;
}

3 个答案:

答案 0 :(得分:0)

我认为问题在于你的CSS。你在类定义中得到float:left,这使得所有的div都对齐。

.general-box {
    padding: 0 40px 30px 40px;
    font-weight: bold;
    border: 1px solid #000;
    text-align:center /** <-- Add a text-align:center here */
}
.general-box .left-right-padding {
    /** float: left;  <--Remove this */
    padding: 0 20px 0 20px;
}

fiddle

答案 1 :(得分:0)

可能适用于您的一个解决方案是float:left .left-right-padding margin: 0 auto框,而不是.general-box .left-right-padding { //float: left; //padding: 0 20px 0 20px; margin: 0 auto; width: 300px; } 方法。

<强> Working Demo

CSS:

{{1}}

答案 2 :(得分:0)

删除浮动,并放入

.general-box {
    padding: 0 40px 30px 40px;
    font-weight: bold;
    display: table-row;
    border: 1px solid #000;
}
.general-box .left-right-padding {
    display: table-cell; 
    padding: 0 20px 0 20px;
}

使用此css在内容周围添加div:display:table和width:100%

Fiddler