我正在整理一张表格,比较不同类型的AED及其公司网站的费用。我关注this tutorial以使其适合移动设备。原则是它使得单元格像div一样堆叠在一起,同时使用:before之前插入与该数据相关联的相应标题。
我所看到的问题是,对于采用多行的标题,这并不是很好。他们突破了牢房,遇到了一个人: example image of the titles breaking out
右边的破折号是原始的td数据,左边的标题是插入的:在{content:"&#34 ;;}
之前有关如何让细胞扩展的任何建议?我意识到这可能涉及采取一种全新的方法来使表格响应,所以我可以改变。
完整代码:
<style>
table {
width: 100%;
border-collapse: collapse;
}
/* Zebra Striping */
tr:nth-of-type(even) {
background-color: #f0f0f0;
}
th {
background-color: #333;
color: white;
font-weight: bold;
}
td, th {
padding: 2px !important;
border: 1px solid #ccc;
text-align: center;
}
#aed-comparison img {
height: 60px;
}
thead, tbody, th, td, tr {
vertical-align: middle;
}
#zoll {
background-color: #ccffcc;
}
/* Hover roles */
tr:hover {
background-color: #e9e9e9;
}
#aed-images:hover {
background-color: white;
}
@media only screen and (max-width: 1048px) {
/* Alter the zebra striping */
tr:nth-of-type(even) {
background-color: inherit;
}
td:nth-of-type(even) {
background-color: #f0f0f0;
}
/* Alter hover roles */
tr:hover {
background-color: inherit;
}
td:hover {
background-color: #e6e6e6;
}
/* Force table to not behave like a table */
table, thead, tbody, th, td, tr {
display: block;
vertical-align: -50%;
}
/* Hide table headers (but not display: none;, for accessibility) */
thead tr {
position: absolute;
top: -9999px;
left: -9999px;
}
tr { border: 1px solid #ccc;}
td {
/* behave like a "row" */
border: none;
border-bottom: 1px solid #eee;
position: relative;
padding-left: 50% !important;
}
td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 2px;
left: 2px;
width: 45%;
padding-right: 10px;
}
table {
table-layout: fixed;
}
table td {
word-wrap:break-word;
}
/* Labeling the data */
td:nth-of-type(1):before {content: "ZOLL AED Plus";}
td:nth-of-type(2):before {content: "Cardiac Science Powerheart G5";}
td:nth-of-type(3):before {content: "Cardiac Science Powerheart G3";}
td:nth-of-type(4):before {content: "Philips HeartStart OnSite & Home";}
td:nth-of-type(5):before {content: "Defibtech View";}
td:nth-of-type(6):before {content: "Philips HeartStart FRx";}
td:nth-of-type(7):before {content: "Physio-Control LIFEPAK CR Plus & EXPRESS";}
td:nth-of-type(8):before {content: "HeartSine Samaritan PAD 350 & 450";}
td:nth-of-type(9):before {content: "Defibtech LIFELINE";}
}
</style>
<h2>The AED Plus Total Cost of ownership (TCO) Advantage for FIVE Years</h2>
<table id="aed-comparison">
<thead>
<tr> <!-- Titles -->
<th>Year*</th>
<th>ZOLL AED Plus</th>
<th>Cardiac Science Powerheart G5</th>
<th>Cardiac Science Powerheart G3</th>
<th>Philips HeartStart OnSite & Home</th>
<th>Defibtech View</th>
<th>Philips HeartStart FRx</th>
<th>Physio-Control LIFEPAK CR Plus & EXPRESS</th>
<th>HeartSine Samaritan PAD 350 & 450</th>
<th>Defibtech LIFELINE</th>
</tr>
</thead>
<tr id="aed-images"> <!-- Images -->
<th></th>
<td><img src="https://www.cpr-savers.com/assets/images/zollimage-crop.jpg" href="https://www.cpr-savers.com/ZOLL-AED-Plus_p_6646.html" /></td>
<td><img src="https://www.cpr-savers.com/assets/images/g5.jpg" href="https://www.cpr-savers.com/Cardiac-Science-Powerheart-G5-AED_p_10636.html" /></td>
<td><img src="https://www.cpr-savers.com/assets/images/g3-pro1-crop.jpg" href="https://www.cpr-savers.com/Cardiac-Science-Powerheart-G3-Plus-AED_p_6913.html" /></td>
<td><img src="https://www.cpr-savers.com/assets/images/prodimages/M5066A.jpg" href="https://www.cpr-savers.com/Philips-HeartStart-OnSite-AED_p_7687.html" /></td>
<td><img src="https://www.cpr-savers.com/assets/images/DCF-A2310EN-crop.jpg" href="https://www.cpr-savers.com/Defibtech-Lifeline-VIEW-AED_p_3893.html" /></td>
<td><img src="https://www.cpr-savers.com/assets/images/prodimages/861304_t.jpg" href="https://www.cpr-savers.com/Philips-HeartStart-FRx-AED--Re-Certified_p_10461.html" /></td>
<td><img src="https://www.cpr-savers.com/assets/images/80403-000149.jpg" href="https://www.cpr-savers.com/Physio-Control-LIFEPAK-CR-Plus-AED_p_4644.html" /></td>
<td><img src="https://www.cpr-savers.com/assets/images/350-bac-us-10_thumbnail.jpg" href="https://www.cpr-savers.com/HeartSine-Samaritan-PAD-450P-AED_p_10593.html" /></td>
<td><img src="https://www.cpr-savers.com/assets/images/prodimages/DCF-A100-EN_t.jpg" href="https://www.cpr-savers.com/Defibtech-Lifeline-AED_p_3890.html" /></td>
</tr>
<tr> <!-- YEAR 1 -->
<th>Year 1</th>
<td id="zoll">--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
</tr>
<tr> <!-- YEAR 2 -->
<th>Year 2</th>
<td id="zoll">--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>9V Battery: $7</td>
</tr>
<tr>
<th>Year 3</th>
<td id="zoll">--</td>
<td>Pads: $69</td>
<td>Pads: $46</td>
<td>Pads: $67</td>
<td>Pads: $59</td>
<td>Pads: $56</td>
<td>Pads & Charge Pack: $100</td>
<td>--</td>
<td>9V Battery: $7<br/>Pads: $38</td>
</tr>
<tr> <!-- YEAR 4 -->
<th>Year 4</th>
<td id="zoll">--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>--</td>
<td>Padpak (battery & pads): $175</td>
<td>9V Battery: $7</td>
</tr>
<tr> <!-- YEAR 5 -->
<th>Year 5</th>
<td id="zoll">--</td>
<td>Pads: $69<br />Battery: $395</td>
<td>Pads: $46<br />Battery: $395</td>
<td>Pads: $67<br />Battery: $169</td>
<td>Pads: $59<br />Battery: $169</td>
<td>Pads: $56<br />Battery: $167</td>
<td>Pads & Charge Pack: $100</td>
<td>--</td>
<td>9V Battery: $7<br />Pads: $38</td>
</tr>
<tr style="font-weight: bold;"> <!-- TOTAL COST -->
<th>Total Cost</th>
<td id="zoll">$0</td>
<td>$533</td>
<td>$487</td>
<td>$303</td>
<td>$287</td>
<td>$279</td>
<td>$200</td>
<td>$175</td>
<td>$104</td>
</tr>
<tr style="font-weight: bold;"> <!-- CHANGES REQUIRED -->
<th>Changes Required</th>
<td id="zoll">0</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
<td>4</td>
<td>1</td>
<td>6</td>
</tr>
</table>
答案 0 :(得分:0)
尝试替换以下css:
table td {
word-wrap:break-word;
}
使用:
table td {
word-wrap:break-word;
min-height: 60px;
}
这应该适合你。