2012-08-03 11 views
5

Mam 3 skrzynki z tytułami, ramką i krótkim opisem.Wyrównaj listę i wypchnij tekst na dół.

W tej chwili wygląda to tak:

enter image description here

Chciałbym przy użyciu tylko CSS, aby wyrównać zielone granice i popchnąć wszystkie tytuły jeden wiersz do dołu.

Treści i tytuły są dynamiczne, więc może się zdarzyć, że w tytule znajdą się 1, 2, 3 wiersze, ale zawsze chcę, aby tytuły z mniejszymi wierszami zaczynały się od dołu, tak jak w poniższym przykładzie.

enter image description here

Nie mogę korzystać z JavaScript!

Każda sugestia zostanie doceniona.


Obecnie struktura kodu jest taka:

HTML:

<section id="" class="boxes"> 
       <ul class="inline"> 
        <li> 
         <article> 
          <h2>Mae hyn yn enghraifft prif llawer hwy</h2> 
          <p> 
           Mae llawer o bethau gwych cymaint yn mynd ymlaen yr haf hwn a, beth bynnag yw eich cynlluniau, nawr yw'r amser i fynd i'r afael a eich gwariant. 
          </p> 
          <a class="read-more" href="">Read more &gt;</a> 
         </article> 
        </li> 

CSS:

ul.inline { 
    display: inline-block; 
    list-style-type: none; 
    margin: 0 0 20px; 
    padding: 0; 
    width: 978px; 
} 

    ul.inline li { 
     float: left; 
     margin: 0 18px 0 0; 
     padding: 0; 
     width: 308px; 
    } 

     ul.inline li h2 { 
      border-bottom: 5px solid #34750E; 
      color: #34750E; 
      font-size: 21px; 
      margin: 0 0 10px; 
      padding: 0 0 10px; 
      position: relative; 
     } 

     ul.inline li a.read-more { 
       color: #34750E !important; 
     } 

EDIT:

FIDDLE UP HERE

+0

Co próbowałeś? stworzyć przykład na [jsfiddle.net] (http://jsfiddle.net) –

+0

czy masz przykładowy kod? Kiedy już to robisz, możesz opublikować to jako demo na http://jsfiddle.net lub http://jsbin.com –

+0

Nie chcesz używać

? Można to łatwo wykonać za pomocą tabeli. – rahool

Odpowiedz

3

UPDATE

Sprawdź to zaktualizowane skrzypce że używa znaczników jak w pytaniu: http://jsfiddle.net/techfoobar/hmCuj/

Logika rozwiązania jest w zasadzie taka sama.


Sprawdź to skrzypce: http://jsfiddle.net/techfoobar/5hhdE/1/

HTML

<ul class="headings"> 
    <li>Heading #1. Heading #1. Heading #1. Heading #1. Heading #1. </li> 
    <li>Heading #2</li> 
    <li>Heading #3. Heading #3. Heading #3. Heading #3. Heading #3. Heading #3. Heading #3.</li> 
</ul> 
<ul class="matter"> 
    <li>Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. </li> 
    <li>Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. </li> 
    <li>Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. Matter. </li> 
</ul> 

CSS

ul.headings, ul.matter { 
    list-style-type: none; 
    vertical-align: bottom; 
    white-space: nowrap; 
} 
ul.headings li { 
    font-size:15px; 
    font-weight: bold; 
    border-bottom: 2px solid #888888; 
    display: inline-block; 
    padding: 5px 0; 
    white-space: normal; 
    width: 33.3%; 
} 
ul.matter li { 
    width: 33.3%; 
    display: inline-block; 
    white-space: normal; 
} 

wpadł na pomysł z tym po: How can I positioning LI elements to the bottom of UL list

+1

** + 1 ** doskonała odpowiedź !;) –

+0

Istnieje "foreach .Net", które powtarzają się listę i wepchnij do tytułu i treści. Jak napisałem w moim poście, jest dynamiczny .. Jeśli mam 2 listy, jak mogę to zrobić? –

+0

Czy masz na myśli, że będziesz mieć wiele 'UL'ów w' sekcji' z pudełkami klas? Jeśli tak, będziesz potrzebować innego rozwiązania! – techfoobar

2

Wcześniej skonfigurować przykład za pomocą tabel. Są to dane tabelaryczne, wiersz nagłówka, wiersz opisu i wiele kolumn.

Live Example

<table> 
    <thead> 
    <tr> 
     <th>Event Title 1</th> 
     <th>Event Title 2<br>Mutliline</th> 
     <th>Event Title 3</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr> 
     <td>Event 1 description<br>Multiline!</td> 
     <td>Event 2 description</td> 
     <td>Event 3 description</td> 
    </tr> 
    </tbody> 
</table> 

CSS

th td { 
    margin: 5px; 
} 
th { 
    border-bottom: green 2px solid; 
    vertical-align: bottom; 
} 
td { 
    vertical-align: top; 
} 
0

Spróbuj to Działa:

kod:

<section class="boxes"> 
    <ul class="inline"> 
     <li> 
      <article> 
       <h2>Mae hyn yn enghraifft prif llawer hwy</h2> 
       <p>Mae llawer o bethau gwych cymaint yn mynd ymlaen yr haf hwn a, beth bynnag yw eich cynlluniau, nawr yw'r amser i fynd i'r afael a eich gwariant.</p> 
       <a class="read-more" href="">Read more &gt;</a> 
      </article> 
     </li> 
     <li> 
      <article> 
       <h2>green borders and push</h2> 
       <p>Mae llawer o bethau gwych cymaint yn mynd ymlaen yr haf hwn a, beth bynnag yw eich cynlluniau, nawr yw'r amser i fynd i'r afael a eich gwariant.</p> 
       <a class="read-more" href="">Read more &gt;</a> 
      </article> 
     </li> 
     <li> 
      <article> 
       <h2>with less rows starts from the bottom like in the example</h2> 
       <p>Mae llawer o bethau gwych cymaint yn mynd ymlaen yr haf hwn a, beth bynnag yw eich cynlluniau, nawr yw'r amser i fynd i'r afael a eich gwariant.</p> 
       <a class="read-more" href="">Read more &gt;</a> 
      </article> 
     </li> 
    </ul> 
</section> 

CSS Kod:

ul.inline { 
    display: inline-block; 
    list-style-type: none; 
    margin: 0 0 20px; 
    padding: 0; 
    width: 978px; 
} 
ul.inline li { 
    float: left; 
    margin: 0 18px 0 0; 
    padding: 0; 
    width: 308px; 
} 
ul.inline li p{ 
    border-top: 5px solid #34750E; 
} 
ul.inline li h2 { 
    color: #34750E; 
    font-size: 21px; 
    margin: 0 0 10px; 
    padding: 0 0 10px; 
    position: relative; 
    height: 80px; 
    vertical-align: bottom; 
    display: table-cell; 
} 
ul.inline li a.read-more { 
    color: #34750E !important; 
} 
1

Dlaczego nie można po prostu użyć tabeli CSS?

http://jsfiddle.net/CeMrZ/

nie zostały dołączone wszystkie czcionki kolorowania itp tylko kod układu.

CSS

.table { 
    display: table; 
    width: 100%; 
    table-layout: fixed; 
} 
.table>ul { 
    display: table-row; 
} 
.table>ul>li { 
    display: table-cell; 
} 
.table>ul.thead>li{ 
    vertical-align: bottom; 
} 

HTML

<div class="table"> 
    <ul class="thead"> 
     <li>Mae hyn yn enghraifft prif llawer hwy</li> 
     <li>Mae hyn yn enghraifft prif llawer hwy<br />Mae hyn yn enghraifft prif llawer hwy</li> 
     <li>Mae hyn yn enghraifft prif llawer hwy</li> 
    </ul> 
    <ul> 
     <li>Mae llawer o bethau gwych cymaint yn mynd ymlaen yr haf hwn a, beth bynnag yw eich cynlluniau, nawr yw'r amser i fynd i'r afael a eich gwariant.</li> 
     <li>2</li> 
     <li>3<br />Mae llawer o bethau gwych cymaint yn mynd ymlaen yr haf hwn a, beth bynnag yw eich cynlluniau, nawr yw'r amser i fynd i'r afael a eich gwariant.</li> 
    </ul> 
</div> 
Powiązane problemy