2014-02-10 22 views
2

我遇到了这个问题的麻烦。集中在水平元素浮动,如果可能,响应

我试着让div的所有形状保持居中,当我减少窗口的宽度,但他们是跟随彼此,总是,真的离开(认为浮动:左)。

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

Tks支持。

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; 
} 

回答

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:显示:表和宽度:100 %

Fiddler

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

+0

Adilapapaya,tks的支持。但我需要这些元素最初保持并排。 – user2752929

0

一个解决方案,可能为你工作是不float:left.left-right-padding框,而是使用margin: 0 auto方法。

Working Demo

CSS:

.general-box .left-right-padding { 
    //float: left; 
    //padding: 0 20px 0 20px; 

    margin: 0 auto; 
    width: 300px; 
} 
+0

男人,tks的支持,但我需要的是元素保持并排到最初,我不能修复一个宽度。 – user2752929