Bootstrap 4表行阴影

时间:2019-02-05 08:07:18

标签: twitter-bootstrap bootstrap-4 shadow

是否有一种方法可以使用引导程序4在表行周围显示阴影?

我尝试了以下操作,但是阴影仅出现在桌子的外面:

<table>
<TR class="shadow p-3 mb-3 bg-white rounded">
  <TD>Table Cell</TD>
  <TD>Table Cell</TD>
  <TD>Table Cell</TD>
</TR>
<TR class="shadow p-3 mb-3 bg-white rounded">
  <TD>Table Cell</TD>
  <TD>Table Cell</TD>
  <TD>Table Cell</TD>
</TR>
<TR class="shadow p-3 mb-3 bg-white rounded">
  <TD>Table Cell</TD>
  <TD>Table Cell</TD>
  <TD>Table Cell</TD>
</TR>
</table>

请参见JSFiddle https://jsfiddle.net/na6ohL0j/

4 个答案:

答案 0 :(得分:0)

从您的html中删除shadow类,然后在CSS中添加以下内容:

tr { 
box-shadow: 0px 2px 18px 0px rgba(0,0,0,0.5);
display: block;
}

答案 1 :(得分:0)

这不是精确的,但有点接近您想要的输出。试试这个:

tr {
  box-shadow: 0 8px 16px rgba(0,0,0,.15)!important;
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">

<div class="container">
  <div class="row">
    <table class="table">
      <thead>
        <tr>
          <th scope="col">Table Head</th>
          <th scope="col">Table Head</th>
          <th scope="col">Table Head</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Table Cell</td>
          <td>Table Cell</td>
          <td>Table Cell</td>
        </tr>
        <tr>
          <td>Table Cell</td>
          <td>Table Cell</td>
          <td>Table Cell</td>
        </tr>
        <tr>
          <td>Table Cell</td>
          <td>Table Cell</td>
          <td>Table Cell</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

答案 2 :(得分:0)

最好和最简单的解决方案是使用另一个表。然后为其涂上阴影。

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
    <div class="col">
      <table class="w-100">
        <TR class=" bg-white rounded">
          <td>
            <table class="my-3 shadow w-100">
              <tr>
                <TD class="p-3">Table Cell</TD>
                <TD class="p-3">Table Cell</TD>
                <TD class="p-3">Table Cell</TD>
              </tr>
            </table>
          </td>
        </TR>
        <TR class="bg-white rounded">
          <td>
            <table class="my-3 shadow w-100">
              <tr>
                <TD class="p-3">Table Cell</TD>
                <TD class="p-3">Table Cell</TD>
                <TD class="p-3">Table Cell</TD>
              </tr>
            </table>
          </td>
        </TR>
        <TR class="bg-white rounded">
          <td>
            <table class="my-3 shadow w-100">
              <tr>
                <TD class="p-3">Table Cell</TD>
                <TD class="p-3">Table Cell</TD>
                <TD class="p-3">Table Cell</TD>
              </tr>
            </table>
          </td>
        </TR>
      </table>

    </div>
  </div>
</div>

答案 3 :(得分:-1)

table {
  border-spacing: 0em 1em;
  padding: 0 2em 1em 0;
  border-collapse: separate;
}

td {
  width: 1.5em;
  height: 1.5em;
  text-align: center;
  vertical-align: middle;
}