【问题标题】:Dynamic pricing table/feature matrix with HTML/CSS带有 HTML/CSS 的动态定价表/功能矩阵
【发布时间】:2016-05-28 06:10:59
【问题描述】:

我正在构建定价表/功能矩阵(下面是我正在尝试构建的图片)

我已经建立了基础,但我在底部的价格汇总方面遇到了麻烦,特别是对于“企业家”和“商业专业人士”列。

我希望能够在其上添加新行(新功能)并相应地调整(向下移动)底部价格。现在我正在使用相对定位,这不起作用,因为每次添加新功能/行时我都需要调整它。

Codepen 链接:http://codepen.io/er40/pen/NxeZpq

.box {
  width: 1100px;
  margin: 50px auto;
}
/* Services Col */

.services-table {
  float: left;
  margin-top: 114px;
  z-index: 0;
  margin-right: 5px;
}
.services-table tr {
  height: 40px;
  background: #fff;
  border-bottom: 1px solid #f4f4f4;
}
.services-table tr:last-child {
  border-bottom: none;
}
.services-table th.services {
  color: #707478;
  font-weight: 100;
  min-width: 375px;
  background: #fff;
}
/* Entrepreneur and Business Pro Col */

table.price-matrix {
  -webkit-box-shadow: 0 0 16px 0 rgba(0, 0, 0, .07);
  box-shadow: 0 0 16px 0 rgba(0, 0, 0, .07);
  float: left;
}
table.price-matrix tr {
  height: 40px;
  background: #fff;
}
/* Headers */

table.price-matrix th.header-white {
  color: #707478;
  font-weight: 100;
  font-size: 30px;
  min-width: 230px;
  text-align: center;
  padding: 15px 0;
  background: #fff;
}
table.price-matrix th.header-white:first-child {
  border-right: 1px solid #e3e3e3;
}
th.header-white hr,
th.header-green hr {
  width: 70%;
  border-bottom: 1px solid;
}
/* Rows */

tr:nth-child(even) td {
  background: #f7fafb;
}
tr:nth-child(even) td.td-green {
  background: #489a5a;
}
tr:nth-child(odd) td.td-green {
  background: #54aa66;
}
td.border {
  border-right: 1px solid #e3e3e3;
}
/* Enterprise */

.enterprise {
  float: left;
  -webkit-box-shadow: 0 0 16px 0 rgba(0, 0, 0, .21);
  box-shadow: 0 0 16px 0 rgba(0, 0, 0, .21);
  margin-top: -20px;
}
.enterprise tr {
  height: 40px;
}
th.header-green {
  color: #fff;
  font-weight: 100;
  font-size: 30px;
  min-width: 230px;
  text-align: center;
  padding: 35px 0 15px;
  background: #54aa66;
}
.enterprise tr.price {
  height: 100px;
}
.enterprise tr.price-border {
  height: 10px;
}
span {
  display: inline-block;
  text-align: center;
  width: 230px;
  position: relative;
  left: 380px;
  bottom: 110px;
  font-size: 60px;
}
<section id="pakete">
  <div class="box">
    <!-- The surrounding box -->

    <!-- The front container -->
    <div class="front">
      <table class="services-table">
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
      </table>
      <table class="price-matrix" border="0">
        <tr>
          <th class="header-white">Entrepreneur
            <hr />
          </th>
          <th class="header-white">Business Pro
            <hr />
          </th>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>

        <tr>
          <td class="border"></td>
          <td class="entypo-cancel"></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
      </table>
      <table class="enterprise">
        <th class="header-green">Enterprise
          <hr />
        </th>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr class="price">
          <td class="td-green"></td>
        </tr>
        <tr class="price-border">
          <td class="td-green"></td>
        </tr>
      </table>
      <span>19</span>
    </div>
</section>

【问题讨论】:

  • 我不知道这个问题是否足够通用,适合 Stack Overflow 论坛。我建议您尝试使问题更笼统。
  • @Gewthen - 为什么问题必须是“通用的”?
  • 您必须考虑这个问题对其他人有何用处。你的问题的症结是什么?定价矩阵方面与问题的技术方面无关,但您将其呈现为这样。因此,我会清理问题以反映您遇到的技术问题。看起来您在将多个表对齐在一起以使它们看起来像一个时遇到了麻烦。你有没有想过做一整张桌子?
  • @Gewthen - 是的,我一开始就把它做成一张桌子。挑战在于处理阴影。如果您查看我在上面发布的图像,您会看到前 2 个计划的列有一个投影,然后最右侧计划的列是一个不同的投影,延伸到其他列。此外,最右边的列需要比其他列高,因此将它们作为单独的表是有意义的。

标签: html css html-table css-tables


【解决方案1】:

这个 UI 有更多的解决方案,但在我看来,这是实现这一目标的最快/标准化方式。这种布局也是响应式的。

注意:我使用了很多:not Selectors 来避免inheritance

function priceTable() {
  var whiteLeft = $('.white-left').innerWidth(),
    greenWidth = $('.green-width').innerWidth(),
    whiteHeight = $('.price').innerHeight();

  $('.bg-white').css({
    'left': whiteLeft,
    'bottom': whiteHeight
  });

  $('.bg-green').css({
    'width': greenWidth
  });
};

$(document).ready(priceTable);
$(window).on('resize load', priceTable);
body {
  background: #f1f1f1;
  font: 13px/16px sans-serif;
}
.main {
  position: relative;
}
.main .bg-white,
.main .bg-green {
  position: absolute;
  right: 0;
}
.main .bg-white {
  background: #fff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  top: 20px;
}
.main .bg-green {
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
  top: 0;
  bottom: 0;
}
.price-table {
  width: 100%;
  border-collapse: collapse;
  position: relative;
  z-index: 9;
}
.price-table .min {
  height: 10px;
  padding: 5px;
}
.price-table tr:not(:last-child) {
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}
.price-table tr:nth-child(2n) td:not(:first-child,
:last-child,
.price) {
  background: rgba(0, 0, 0, 0.02);
}
.price-table tr:nth-child(2n) td:last-child {
  background: #428c52;
}
.price-table tr td {
  padding: 20px;
}
.price-table tr td:not(:first-child) {
  text-align: center;
}
.price-table tr td:last-child {
  background: #489a5a;
  color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="main">
  <span class="bg-white"></span>
  <span class="bg-green"></span>
  <table class="price-table">
    <thead>
      <tr>
        <td class="min" colspan="3"></td>
        <td class="min"></td>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="white-left">&nbsp;</td>
        <td>Entrepreneur</td>
        <td>Business Pro</td>
        <td class="green-width">Enterprise</td>
      </tr>
      <tr>
        <td>Service 1</td>
        <td>yes</td>
        <td>yes</td>
        <td>yes</td>
      </tr>
      <tr>
        <td>Service 2</td>
        <td>yes</td>
        <td>yes</td>
        <td>yes</td>
      </tr>
      <tr>
        <td>Service 3</td>
        <td>yes</td>
        <td>yes</td>
        <td>yes</td>
      </tr>
      <tr>
        <td>Service 4</td>
        <td>yes</td>
        <td>yes</td>
        <td>yes</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td class="price">$19/month</td>
        <td class="price">$19/month</td>
        <td>$19/month</td>
      </tr>
    </tbody>
  </table>
</div>

【讨论】:

  • 这太棒了!!绝对完美。非常感谢您的帮助!
【解决方案2】:

编辑:好的,这与图像不完全相同。但我认为这对于实际添加数据将是最有效的。如果您不需要添加其他数据(至少根据我的知识和经验),您可以使其看起来与上图完全一样。虽然盒子阴影的工作方式,但我个人无法使其完全发挥作用。

删除&lt;span&gt; 并将span 类更改为.price。也删除Display: inline-block;。我还添加了.td-white,这将使白色定价具有您想要的外观(减去阴影)。我想这就是你要找的:

已更新*参考:http://codepen.io/anon/pen/wMZBqG

HTML:

<section id="pakete">
  <div class="box">
    <!-- The surrounding box -->

    <!-- The front container -->
    <div class="front">
      <table class="services-table">
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
        <tr>
          <th class="services">Service 1</th>
        </tr>
      </table>
      <table class="price-matrix" border="0">
        <tr>
          <th class="header-white">Entrepreneur
            <hr />
          </th>
          <th class="header-white">Business Pro
            <hr />
          </th>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>

        <tr>
          <td class="border"></td>
          <td class="entypo-cancel"></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr>
          <td class="border"></td>
          <td></td>
        </tr>
        <tr class="price">
          <td class="td-white">20</td>
          <td class="td-white">20</td>
        </tr>
      </table>
      <table class="enterprise">
        <th class="header-green">Enterprise
          <hr />
        </th>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr>
          <td class="td-green"></td>
        </tr>
        <tr class="price">
          <td class="td-green">20</td>
        </tr>
        <tr class="price-border">
          <td class="td-green"></td>
        </tr>
      </table>
    </div>
</section>

CSS:

.box {
  width: 1100px;
  margin: 50px auto;
}


/* Services Col */

.services-table {
  float: left;
  margin-top: 114px;
  z-index: 0;
  margin-right: 5px;
}

.services-table tr {
  height: 40px;
  background: #fff;
  border-bottom: 1px solid #f4f4f4;
}

.services-table tr:last-child {
  border-bottom: none;
}

.services-table th.services {
  color: #707478;
  font-weight: 100;
  min-width: 375px;
  background: #fff;
}


/* Entrepreneur and Business Pro Col */

table.price-matrix {
  -webkit-box-shadow: 0 0 16px 0 rgba(0, 0, 0, .07);
  box-shadow: 0 0 16px 0 rgba(0, 0, 0, .07);
  float: left;
}

table.price-matrix tr {
  height: 40px;
  background: #fff;
}


/* Headers */

table.price-matrix th.header-white {
  color: #707478;
  font-weight: 100;
  font-size: 30px;
  min-width: 230px;
  text-align: center;
  padding: 15px 0;
  background: #fff;
}

table.price-matrix th.header-white:first-child {
  border-right: 1px solid #e3e3e3;
}

th.header-white hr,
th.header-green hr {
  width: 70%;
  border-bottom: 1px solid;
}


/* Rows */

tr:nth-child(even) td {
  background: #f7fafb;
}

tr:nth-child(even) td.td-green {
  background: #489a5a;
}

tr:nth-child(odd) td.td-green {
  background: #54aa66;
}

td.border {
  border-right: 1px solid #e3e3e3;
}


/* Enterprise */

.enterprise {
  float: left;
  -webkit-box-shadow: 0 0 16px 0 rgba(0, 0, 0, .21);
  box-shadow: 0 0 16px 0 rgba(0, 0, 0, .21);
  margin-top: -20px;
}

.enterprise tr {
  height: 40px;
}

th.header-green {
  color: #fff;
  font-weight: 100;
  font-size: 30px;
  min-width: 230px;
  text-align: center;
  padding: 35px 0 15px;
  background: #54aa66;
}

.enterprise tr.price {
  height: 100px;
}

.enterprise tr.price-border {
  height: 10px;
}

.price {
  text-align:center;
  width:230px;
  position:relative;
  left:380px;
  bottom:110px;
  font-size:60px;
}

.td-white {
  background-color: #FFFFFF !important;
  border-right: 1px solid #e3e3e3;
  border-top: 1px solid #e3e3e3
}

这应该允许您添加新服务并动态调整最低定价。

【讨论】:

  • 不完全是,看看我附在顶部的图像。我不希望实际表中前两个计划列的价格。它们应该在各自的列下方“浮动”。我最初尝试按照您的方式进行操作,但由于原始设计中的阴影效果不佳。
  • 编辑:刚刚看到您的编辑并且您仍在努力。感谢您的帮助!
  • 立即查看。它尽可能地接近我能得到的尽可能多的功能。至少以我的知识和经验来看,要让它准确地工作,同时保持它在表格中添加和删除的功能是很困难的。
  • 另外,如果您已经对此有所了解,那么您可能已经得出了这个结论。我认为使用阴影并保持您想要的功能是不可能的。
  • 感谢您的尝试,非常感谢。我确实得出了同样的结论,但希望我遗漏了什么或者其他人有更好的主意。
猜你喜欢
  • 1970-01-01
  • 2018-05-17
  • 2021-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-26
  • 2018-10-03
  • 2013-05-08
相关资源
最近更新 更多