2014-11-23 36 views
0

与列表项3栏布局

.clearself:before,.clearself:after{content: " ";display: block;height: 0;overflow: hidden;} 
 
.clearself:after{clear: both;} 
 
.clearself{zoom: 1;} /* IE < 8 */ 
 

 
ul.three-col-row li{width: 25%;margin-right: 5%;float: left;text-align: center;} 
 
ul.three-col-row li:nth-child(4n+4){margin-right:5%;float: left;} \t 
 
ul.three-col-row li:nth-child(3n+3){margin-right: 5%;float: right;} \t 
 

 
.intro{margin:60px 0 0 0;} 
 
.intro h2{margin-bottom: 15px;} 
 
.intro p{margin-bottom: 30px;} 
 
.intro ul.three-col-row li {min-height:310px;}
<section class="intro clearself"> 
 
     <ul class="three-col-row"> 
 
     <li> 
 
      <h2>Wat?..</h2> 
 
      <p>Praktische en juiste informatie is een belangrijke deelsleutel tot de oplossing van rugproblemen.</p> 
 
      <a class="button" href="advice.html">Meer info!</a> 
 
     </li><!-- 
 
     --><li> 
 
      <h2>Hoe...</h2> 
 
      <p>Ga zo ver mogelijk in de beweging en herhaal dit regelmatig gedurende U capaciteit.</p> 
 
      <a class="button" href="work-out.html">Kies je sport!</a> 
 
     </li><!-- 
 
     --><li class="last-row1"> 
 
      <h2>Doel...</h2> 
 
      <p>Het belangrijkste aspect is echter dat U ontdekt dat U ZELF veel kan doen om uiteindelijk uw rugklacht te vermijden,meer dan U welicht denkt.</p> 
 
      <a class="button" href="about.html">Meer info!</a> 
 
     </li> 
 
     </ul> 
 
    </section>

我这个问题是,第二列是不正确居中。第二和第三列之间的空间太大...我的主要内容宽度是90%,我的部分最小高度是310px。 当我在Firefox上测试页面时,我的3列的宽度为275x310px,但它们看起来不相同。当我在Chrome上进行测试时,我的2列的宽度为275x310px,中间的宽度为274x310px。 如何让空间平等?

回答

0

的原因是,你有float: right第三li。使它float: left和你的利润/差距将是统一的。

ul.three-col-row li:nth-child(3n+3) { margin-right: 5%; float: left; } 

演示:http://jsfiddle.net/abhitalks/477gg73o/


您也可以利用CSS3 columns,使其更容易一些。

段:

ul { 
 
    list-style: none; 
 
    -webkit-columns: 3; 
 
    columns: 3; 
 
    -webkit-column-gap: 8px; 
 
    column-gap: 8px; 
 
} 
 

 
h2 { 
 
    margin-top: 0; 
 
} 
 

 
li { 
 
    -webkit-column-break-inside: avoid; 
 
    column-break-inside: avoid; 
 
}
<section class="intro clearself"> 
 
     <ul class="three-col-row"> 
 
     <li> 
 
      <h2>Wat?..</h2> 
 
      <p>Praktische en juiste informatie is een belangrijke deelsleutel tot de oplossing van rugproblemen.</p> 
 
      <a class="button" href="advice.html">Meer info!</a> 
 
     </li> 
 
     <li> 
 
      <h2>Hoe...</h2> 
 
      <p>Ga zo ver mogelijk in de beweging en herhaal dit regelmatig gedurende U capaciteit.</p> 
 
      <a class="button" href="work-out.html">Kies je sport!</a> 
 
     </li> 
 
     <li class="last-row1"> 
 
      <h2>Doel...</h2> 
 
      <p>Het belangrijkste aspect is echter dat U ontdekt dat U ZELF veel kan doen om uiteindelijk uw rugklacht te vermijden,meer dan U welicht denkt.</p> 
 
      <a class="button" href="about.html">Meer info!</a> 
 
     </li> 
 
     </ul> 
 
    </section>

0

一种解决方案是使用display: table-cell结合了padding: 0 5% 0 5%和删除floats

.clearself:before, 
 
.clearself:after { 
 
    content: " "; 
 
    display: block; 
 
    height: 0; 
 
    overflow: hidden; 
 
} 
 
.clearself:after { 
 
    clear: both; 
 
} 
 
.clearself { 
 
    zoom: 1; 
 
} 
 
/* IE < 8 */ 
 

 
ul.three-col-row li { 
 
    width: 25%; 
 
    text-align: center; 
 
} 
 
.intro { 
 
    margin: 60px 0 0 0; 
 
} 
 
.intro h2 { 
 
    margin-bottom: 15px; 
 
} 
 
.intro p { 
 
    margin-bottom: 30px; 
 
    max-height: 75px; 
 
    height: 75px; 
 
} 
 
.intro ul.three-col-row li { 
 
    min-height: 310px; 
 
} 
 
ul.three-col-row { 
 
    display: table; 
 
    padding: 0; 
 
    /*remove padding from ul*/ 
 
} 
 
ul.three-col-row li { 
 
    display: table-cell; 
 
    /*set display to table-cell*/ 
 
    padding: 0px 5% 0 5%; 
 
    /*add padding*/ 
 
}
<section class="intro clearself"> 
 
    <ul class="three-col-row"> 
 
    <li> 
 
     <h2>Wat?..</h2> 
 

 
     <p>Praktische en juiste informatie is een belangrijke deelsleutel tot de oplossing van rugproblemen.</p> <a class="button" href="advice.html">Meer info!</a> 
 

 
    </li> 
 
    <!-- --> 
 
    <li> 
 
     <h2>Hoe...</h2> 
 

 
     <p>Ga zo ver mogelijk in de beweging en herhaal dit regelmatig gedurende U capaciteit.</p> <a class="button" href="work-out.html">Kies je sport!</a> 
 

 
    </li> 
 
    <!-- --> 
 
    <li class="last-row1"> 
 
     <h2>Doel...</h2> 
 

 
     <p>Het belangrijkste aspect is echter dat U ontdekt dat U ZELF veel kan doen om uiteindelijk uw rugklacht te vermijden,meer dan U welicht denkt.</p> <a class="button" href="about.html">Meer info!</a> 
 

 
    </li> 
 
    </ul> 
 
</section>

+0

它的工作就是这样,而不是响应式布局。 – 2014-11-23 14:55:42

+0

嗯,没有看到你描述的问题。 – 2014-11-23 15:04:40

+0

我不能放图片来显示问题出在哪里。问题在于列应该是响应式的。在一个小屏幕上,应该有colums在彼此之下。如果我使用display:table比在大屏幕上完美,但是在移动网站上并不显示在其他下方。 – 2014-11-23 15:20:41

0

我添加了一个主内容的div和编辑/删除了一些CSS代码。希望这可以帮助。

.clearself:before,.clearself:after{content: " ";display: block;height: 0;overflow: hidden;} 
 
.clearself:after{clear: both;} 
 
.clearself{zoom: 1;} /* IE < 8 */ 
 

 
ul.three-col-row li{width: 29%;float: left;text-align: center;margin: 0 2% 0 2%;} 
 

 
.intro{margin:60px 0 0 0;} 
 
.intro h2{margin-bottom: 15px;} 
 
.intro p{margin-bottom: 30px;} 
 
.intro ul.three-col-row li {min-height:310px;} 
 
.main-content-box {width: 90%;margin-left:auto;margin-right:auto;position:relative;}
<section class="intro clearself"> 
 
    <div class="main-content-box"> 
 
     <ul class="three-col-row"> 
 
     <li> 
 
      <h2>Wat?..</h2> 
 
      <p>Praktische en juiste informatie is een belangrijke deelsleutel tot de oplossing van rugproblemen.</p> 
 
      <a class="button" href="advice.html">Meer info!</a> 
 
     </li><!-- 
 
     --><li> 
 
      <h2>Hoe...</h2> 
 
      <p>Ga zo ver mogelijk in de beweging en herhaal dit regelmatig gedurende U capaciteit.</p> 
 
      <a class="button" href="work-out.html">Kies je sport!</a> 
 
     </li><!-- 
 
     --><li class="last-row1"> 
 
      <h2>Doel...</h2> 
 
      <p>Het belangrijkste aspect is echter dat U ontdekt dat U ZELF veel kan doen om uiteindelijk uw rugklacht te vermijden,meer dan U welicht denkt.</p> 
 
      <a class="button" href="about.html">Meer info!</a> 
 
     </li> 
 
     </ul> 
 
    </div> 
 
    </section>