我有來自外部源的HTML內容。被打上了div的,有點像這樣:現在缺少單元格的CSS表格佈局
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<link rel="stylesheet" href="mycss.css" type="text/css"/>
</head>
<body>
<div class="book">
<div class="author">Author 1</div>
<div class="title">Title 1</div>
<div class="publisher">Publisher</div>
<div class="year">2012</div>
</div>
<div class="book">
<div class="author">Author 2</div>
<div class="title">Title 2</div>
<div class="year">2013</div>
</div>
<div class="book">
<div class="author">Author 3</div>
<div class="title">Title 3</div>
<div class="publisher">Publisher</div>
</div>
</body>
</html>
,它希望與CSS表格佈局以顯示它與交替的顏色的每一行。有點像這樣:
body {
display: table;
width: 100%;
}
.book {
display: table-row;
}
.book:nth-child(even) {
background: #FFF;
}
.book:nth-child(odd) {
background: #DDD;
}
.author, .title, .publisher, .year {
display: table-cell;
}
然而,這種解決方案的問題在於,你可以看到,一些div缺少的HTML,但我想完成以下任務:
- 有每種信息都是垂直對齊的。換句話說,將上述示例中的每個出版物的年份顯示在與發佈者信息不同的列中。
- 將行着色擴展爲覆蓋每行的頁面寬度。
這是甚至有可能只使用CSS時,我有幾列?
撥弄 - http://jsfiddle.net/sRJhs/
謝謝。解決了它的一部分,但不幸的是沒有對齊數據。 –
更新了我的答案。 – Alex
@Magnus Gustavsson - 改變了我的方法,這個作品最好 – Alex