我如何修改我的四个象限以允许它们之间有一些 "breathing room" (HTML/CSS)?

How can I modify my four quadrants to allow some "breathing room" between them (HTML/CSS)?

我已经能够根据已接受的答案在我的页面上创建四个 equi-sized/shaped 象限

所以页面现在看起来像这样:

我现在想给象限一些 "elbow room" - 在它们的边缘周围一些空白 space。我尝试为他们使用的 类 添加边距:

.topleft {
  background-color: blue;
  margin: 4;
}
.topright {
  background-color: red;
  margin: 4;
}
.bottomleft {
  background-color: green;
  margin: 4;
}
.bottomright {
  background-color: yellow;
  margin: 4;
}

那什么也没做;我尝试然后添加填充:

.topleft {
  background-color: blue;
  padding: 4;
}
.topright {
  background-color: red;
  padding: 4;
}
.bottomleft {
  background-color: green;
  padding: 4;
}
.bottomright {
  background-color: yellow;
  padding: 4;
}

...那也什么也没做。

我需要做些什么才能使所有人保持相同的 1/4 space,但通过在它们之间添加边距或在它们周围填充来有效地 "squish" 它们成为 scosh?

这里是完整的 html/css:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>eServices Customer Dashboard</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>    <!--[if IE]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

<!-- Inline CSS (don't tell the CSS-Whisperers I did this!) -->
<style>
body {
    background-color: azure;
}
.body-content {
    -webkit-box-shadow: -1px 0 5px 0 #000000;
    -webkit-box-shadow: -1px 0 5px 0 rgba(0, 0, 0, .25);
    box-shadow: -1px 0 5px 0 #000000;
    box-shadow: -1px 0 5px 0 rgba(0, 0, 0, .5);
   padding-left: 1px;
   padding-right: 1px;
   padding-bottom: 15px;
}
.jumbotronjr {
  padding: 12px;
  margin-bottom: -16px;
  font-size: 21px;
  font-weight: 200;
  color: inherit;
  background-color: white;
}
.addltopmargin {
    margin-top: 8px;
}
.sectiontext {
    font-size: 1.5em;
    font-weight: bold;
    font-family: Candara, Calibri, Cambria, serif;
}
.bottommarginbreathingroom {
    margin-bottom: 2px;
}
.marginaboveandbelow {
    margin-top: 15px;
    margin-bottom: 15px;
}
.rightjustifytext {
  text-align: right;
}
table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}
.contents{
  height:50%;
  width:100%;
}
redfont {
    color: red;
}
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.container {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-wrap: wrap;
}
.container div {
  display: inline-block;
  width: 50vw;
  height: 50vh;
  overflow-y: scroll;
}
.topleft {
  background-color: blue;
  padding: 4;
}
.topright {
  background-color: red;
  padding: 4;
}
.bottomleft {
  background-color: green;
  padding: 4;
}
.bottomright {
  background-color: yellow;
  padding: 4;
}
</style>
</head>

<body>

<div class="contents">
<div class="row">
<div class="col-md-6 topleft">
<h2>Top 10 Items Purchased</h2>
        <div>
            <input type="date" class="bottommarginbreathingroom" id="daterangefrom2" name="daterangefrom2">
            </input>
            <label> to </label>
            <input type="date" class="bottommarginbreathingroom" id="daterangeto2" name="daterangeto2">
            </input>
        </div>

        <table>
            <tr>
                <th>Item Code</th>
                <th>Description</th>
                <th>Qty</th>
            </tr>

            <tr>
                <td>Item Code 1</td>
                <td>Description 1</td>
                <td>Qty 1</td>
            </tr>
            <tr>
                <td>Item Code 2</td>
                <td>Description 2</td>
                <td>Qty 2</td>
            </tr>
            <tr>
                <td>Item Code 3</td>
                <td>Description 3</td>
                <td>Qty 3</td>
            </tr>
            <tr>
                <td>Item Code 4</td>
                <td>Description 4</td>
                <td>Qty 4</td>
            </tr>
            <tr>
                <td>Item Code 5</td>
                <td>Description 5</td>
                <td>Qty 5</td>
            </tr>
            <tr>
                <td>Item Code 6</td>
                <td>Description 6</td>
                <td>Qty 6</td>
            </tr>
            <tr>
                <td>Item Code 7</td>
                <td>Description 7</td>
                <td>Qty 7</td>
            </tr>
            <tr>
                <td>Item Code 8</td>
                <td>Description 8</td>
                <td>Qty 8</td>
            </tr>
            <tr>
                <td>Item Code 9</td>
                <td>Description 9</td>
                <td>Qty 9</td>
            </tr>
            <tr>
                <td>Item Code 10</td>
                <td>Description 10</td>
                <td>Qty 10</td>
            </tr>
        </table>
</div>

<div class="col-md-6 topright">
<h2>Pricing Exceptions - Weekly Recap</h2>
<h3 class="redfont">Red denotes Contract Item Overages</h3>
<h3>For Weyand on the pricing week of - 7/31/2016</h3>
        <table>
            <tr>
                <th>Invoice No</th>
                <th>Invoice Date</th>
                <th>Customer</th>
                <th>Cust #</th>
                <th>Item Code</th>
                <th>Description</th>
                <th>Member Item Code</th>
                <th>Member Description</th>
                <th>Bid Price</th>
                <th>Sell Price</th>
                <th>Qty</th>
            </tr>

            <tr>
                <td>Inv No 1</td>
                <td>Inv Date 1</td>
                <td>Customer 1</td>
                <td>Cust # 1</td>
                <td>Item Code 1</td>
                <td>Descrip. 1</td>
                <td>M.I. Code 1</td>
                <td>Memb Desc 1</td>
                <td>Bid Price 1</td>
                <td>Sell Pr. 1</td>
                <td>Qty 1</td>
            </tr>
            <tr>
                <td>Inv No 2</td>
                <td>Inv Date 2</td>
                <td>Customer 2</td>
                <td>Cust # 2</td>
                <td>Item Code 2</td>
                <td>Descrip. 2</td>
                <td>M.I. Code 2</td>
                <td>Memb Desc 2</td>
                <td>Bid Price 2</td>
                <td>Sell Pr. 2</td>
                <td>Qty 2</td>
            </tr>
            <tr>
                <td>Inv No 3</td>
                <td>Inv Date 3</td>
                <td>Customer 3</td>
                <td>Cust # 3</td>
                <td>Item Code 3</td>
                <td>Descrip. 3</td>
                <td>M.I. Code 3</td>
                <td>Memb Desc 3</td>
                <td>Bid Price 3</td>
                <td>Sell Pr. 3</td>
                <td>Qty 3</td>
            </tr>
        </table>
    </div>
</div>

<div class="row">
<div class="col-md-6 bottomleft">
<h2>Forecasted Spend</h2>
        <table>
            <tr>
                <th>Item</th>
                <th>Last Week's Usage</th>
                <th>This Week's Price</th>
                <th>Forecasted Spend</th>
            </tr>

            <tr>
                <td>Item 1</td>
                <td>52</td>
                <td>TWP 1</td>
                <td>68.00</td>
            </tr>
            <tr>
                <td>Item 2</td>
                <td>49</td>
                <td>TWP 2</td>
                <td>65.00</td>
            </tr>
            <tr>
                <td>Item 3</td>
                <td>46</td>
                <td>TWP 3</td>
                <td>63.00</td>
            </tr>
            <tr>
                <td>Item 4</td>
                <td>42</td>
                <td>TWP 4</td>
                <td>60.00</td>
            </tr>
            <tr>
                <td>Item 5</td>
                <td>40</td>
                <td>TWP 5</td>
                <td>58.00</td>
            </tr>
            <tr>
                <td>Item 6</td>
                <td>42</td>
                <td>TWP 6</td>
                <td>60.00</td>
            </tr>
            <tr>
                <td>Item 7</td>
                <td>43</td>
                <td>TWP 7</td>
                <td>61.00</td>
            </tr>
            <tr>
                <td>Item 8</td>
                <td>43</td>
                <td>TWP 8</td>
                <td>61.00</td>
            </tr>
            <tr>
                <td>TOTAL</td>
                <td>314</td>
                <td></td>
                <td>6.00</td>
            </tr>
        </table>
    </div>

<div class="col-md-6 bottomright">
<h2>Fill Rate</h2>
        <table>
            <tr>
                <th>Unit</th>
                <th>Co. Name</th>
                <th>Desc</th>
                <th>Ord</th>
                <th>Ship</th>
                <th>Var</th>
            </tr>

            <tr>
                <td>Unit 1</td>
                <td>Co. Name 1</td>
                <td>Desc 1</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 2</td>
                <td>Co. Name 2</td>
                <td>Desc 2</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 3</td>
                <td>Co. Name 3</td>
                <td>Desc 3</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 4</td>
                <td>Co. Name 4</td>
                <td>Desc 4</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 5</td>
                <td>Co. Name 5</td>
                <td>Desc 5</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 6</td>
                <td>Co. Name 6</td>
                <td>Desc 6</td>
                <td>40</td>
                <td>40</td>
                <td>0</td>
            </tr>
            <tr>
                <td>Unit 7</td>
                <td>Co. Name 7</td>
                <td>Desc 7</td>
                <td>40</td>
                <td>39</td>
                <td>1</td>
            </tr>
            <tr>
                <td>Unit 8</td>
                <td>Co. Name 8</td>
                <td>Desc 8</td>
                <td>0</td>
                <td>0</td>
                <td>0</td>
            </tr>
            <tr>
                <td>TOTAL</td>
                <td></td>
                <td></td>
                <td>280</td>
                <td>279</td>
                <td>1</td>
            </tr>
        </table>
    </div>
</div>


</div>
</body>
</html>

更新

添加填充只会使象限膨胀,不会在它们之间提供任何喘息空间。它看起来或多或少好像 "top" 属性 被分配给了第一个元素,将它进一步向下推。

添加边距 (16px) 会导致象限在页面上垂直排列 - 全部在左侧,右侧没有任何内容。四块垂直堆叠,一层一层。

给出margin & padding 属性 的单位如px, em。尝试给出 margin: 4px;。但是4px好像很小。

marginpadding 都采用 CSS 长度 单位。有很多不同的单位,因为它们按绝对单位(像素或 px 是最常见的)或相对单位(emrem 是最常见的)分类。您也可以使用由百分比给出的维度值 %,即使它不是长度值。

有关完整列表和深入解释,请参阅 here

在您的情况下,可能 padding 会帮助您,并且您可能希望使用比 4px 更大的值。

为边距/边距添加一个单位,例如 px(绝对值)或 em(相对值)。请参考:http://www.w3schools.com/css/css_padding.asp

不要向包含 bootstrap column 类 的 div 添加新的 类。相反,创建一个子 div 并将您的样式应用于内部 div.

例如: 替换

<div class="row">
  <div class="col-md-6 topleft">
    ...
  </div>
</div>

 <div class="row">
   <div class="col-md-6">
     <div class="topleft">
        ...
     </div>
  </div>
</div>

这样您就可以在外部 div 中控制容器的整体边界并在内部 div 中对其进行样式设置(添加边距、填充)。

另外,按照其他人的建议,padding/margin 使用 px/em 单位。

代码笔:http://codepen.io/anon/pen/vKQwyg