CSS Эквивалент таблицы Rowspan с высотой жидкости

Я пытаюсь выполнить следующее с помощью CSS:

<table border="1" width="300px">
<tr>
    <td rowspan="2">This row should equal the height (no fixed-height allowed) of the 2 rows sitting to the right.</td>
    <td>Here is some sample text.  And some additional sample text.</td>
</tr>
<tr>
    <td>Here is some sample text.  And some additional sample text.</td>
</tr>
</table>

alt text

В примерах, которые я видел для этого, используются фиксированные высоты или разрешено обтекание содержимого вокруг левого столбца. Есть ли элегантный способ сделать это с помощью CSS?

Ответы

Ответ 1

Прежде всего, то, что вы делаете, выглядит как таблица для меня, поэтому вы можете подумать об этом. Однако делать это с помощью CSS немного сложнее (если только вы не выполняете стиль таблицы в CSS). Следующий код работает, но не центрирует вертикально текст в поле:

<html><head><title>Test2</title></head><body>
<div style="width:300px; padding: 2px; border: 1px solid black;">
  <div style="float:right; width: 100px;">
    <div style="border: 1px solid black; margin-bottom: 2px;">
      Here is some sample text. And some additional sample text.
    </div>
    <div style="border: 1px solid black;">
      Here is some sample text. And some additional sample text.
    </div>
  </div>
  <div style="border: 1px solid black; margin-right: 102px;">
    <div>
      This column should equal the height (no fixed-height allowed) of the 2 rows sitting to the right.
    </div>
    <div style="clear: right; margin-bottom: -1px;"></div>
  </div>
</div></body></html>

Ячейки таблицы в CSS проще:

<!DOCTYPE html>
<html><head><title>Test2</title></head><body>
<div style="display: table; width:300px; border: 1px solid black; border-spacing: 2px;">
  <div style="display: table-cell; border: 1px solid black; vertical-align: middle;">
    This column should equal the height (no fixed-height allowed) of the 2 rows sitting to the right.
  </div>
  <div style="display: table-cell; width: 100px;">
    <div style="border: 1px solid black; margin-bottom: 2px;">
      Here is some sample text. And some additional sample text.
    </div>
    <div style="border: 1px solid black;">
      Here is some sample text. And some additional sample text.
    </div>
  </div>
</div>
</body>
</html>

Ответ 2

Мне нужно что-то очень похожее. К сожалению, все эти решения довольно сложны, я пришел с чем-то очень простым (может быть, слишком простым) - использовал display: inline-block

HTML

<div>
    <span id="v">
        text in the left
    </span>
    <div id="x">
        <div>upper row</div>
        <div>lower row</div>
    </div>
</div>

CSS

#x {
    display: inline-block;
    vertical-align: middle;
}

fiddle

Ответ 3

Это то, что я использую: http://www.ejeliot.com/samples/equal-height-columns/example-7.html

Я бы использовал второй столбец как оболочку для двух других элементов (менее семантических). Это должен быть самый простой способ.